如何在java中编译?国际象棋游戏 [英] How to compile in java? Chess game

查看:119
本文介绍了如何在java中编译?国际象棋游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想尝试创建国际象棋游戏,

但是当我运行Main class时没有其他显示器,

如何显示如下:

- - - - - - - -

- - - - - - - -

- - - - - - - -

- - - - - - - -

- - - - - - - -

- - - - - - - -

- - - - - - - -

WP - - - - - - - -





#ChessPiece Class还是空的,



我尝试了什么:



Pawn Class

i want to try create chess game,,
but when i run Main class no other display,,
how to display like :
- - - - - - - -
- - - - - - - -
- - - - - - - -
- - - - - - - -
- - - - - - - -
- - - - - - - -
- - - - - - - -
WP - - - - - - - -


#ChessPiece Class is still empty,

What I have tried:

Pawn Class

package chessPieces;

public class Pawn extends ChessPiece{
	char color;
	public char getPiece()
	{
		return 'P';
	}
	public Pawn(char color)
	{
		this.color = color;
	}
	public char getColor(char color)
	{
		return color;
	}
	
}



Board Board


Board Class

package board;

import chessPieces.ChessPiece;
import chessPieces.EmptySpace;
import chessPieces.Pawn;

public class BoardInterface {
	char white = 'W';
	char empty = '-';
	ChessPiece[][] board;
	
	public BoardInterface()
	{

		this.board = new ChessPiece[8][8];
		for(int i = 0; i < 7; i++)
		{
			for(int j = 0; j < 8; j++)
			{
				board[i][j] = new EmptySpace(empty);
			}
		}
		this.board[7][0] = new Pawn(white);
	}
	public ChessPiece[][] getBoard()
	{
		return this.board;
	}
	
}



空舱


Empty Class

package chessPieces;

public class EmptySpace extends ChessPiece {
	char color;
	public EmptySpace(char color)
	{
		this.color = color;
	}
}



主类


Main Class

package main;


import chessPieces.ChessPiece;
import chessPieces.EmptySpace;
import chessPieces.Pawn;


public class Main {
	public static void main(String[] args) {
		ChessPiece chesspiece = new ChessPiece();
	}
}

推荐答案

引用:

如何在java中编译?国际象棋游戏

How to compile in java? Chess game



与任何其他Java程序完全相同。


Exactly the same way as any other Java program.

Quote:

想尝试创建国际象棋游戏,

但是当我运行Main类没有其他显示时,

want to try create chess game,,
but when i run Main class no other display,,



您应该考虑使用调试器看看你的代码到底在做什么。



你的代码没有你想象的那样,或者你不明白为什么!

-----

有一个几乎通用的解决方案:一步一步地在调试器上运行你的代码,检查变量。

调试器在这里向你展示你的代码正在做,你的任务是与它应该做的事情进行比较。

调试器中没有魔法,它不知道你应该做什么,它没有发现bug,它只是通过向您展示正在发生的事情来帮助您。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。

调试器 - 维基百科,免费的百科全书 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows /jdb.html [ ^ ]

https: //www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]

调试器仅显示您的代码正在执行的操作,您的任务是与什么进行比较应该这样做。


You should think about using a debugger to see what your code is really doing.

Your code do not behave the way you expect, or you don't understand why !
-----
There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.


这篇关于如何在java中编译?国际象棋游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆