帮助错误创建Java错误 [英] Help error create java eror
本文介绍了帮助错误创建Java错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我想创建国际象棋游戏,
我不知道为什么会出现这种错误,
让我们看看
我要在主运行时显示WP
请帮我怎么写
我尝试过的事情:
典当类
heyy i want to create chess game,,
i dont know why this eror,
lets see
i want when main run,, will display WP
help please how do i write it
What I have tried:
Pawn class
package chessPieces;
public class Pawn extends ChessPiece{
char color;
public Pawn(char color)
{
this.color = color;
}
}
棋子类
Chess Piece class
package chessPieces;
public class ChessPiece {
public ChessPiece()
{
char white = ''W'';
ChessPiece[][] board;
board = new ChessPiece[8][8];
board[7][0] = new Pawn(white);
System.out.print(board[7][0]);
}
}
主班
Main Class
package main;
import chessPieces.ChessPiece;
import chessPieces.Pawn;
public class Main {
public static void main(String[] args) {
ChessPiece chesspiece = new ChessPiece();
}
}
推荐答案
我在 ^ ],但您将其颠倒了.
为什么一个国际象棋班包含棋盘?从对象的角度看一下国际象棋的结构:
1.一块包含8 x 8正方形阵列的木板.
2.可能呈黑色或白色的正方形,可能包含一个棋子.
3.具有颜色并移动类型(计数和方向)的棋子.
4.特定类型的国际象棋,国王,皇后,主教等,具有特定的移动类型.
您已经定义了Pawn的属性(colour0,这对于所有国际象棋都是通用的.Chesspiece类包含一个char变量,其外观保留W或B表示颜色.它还包含Board,这完全没有意义. br/>
停止编写代码,花一些时间勾勒出您的类以及每个类需要哪些属性和方法.
I gave you a suggestion at Help java chess game[^], but you are doing it upside down.
Why would a Chesspiece class contain the chess board? Look at the structure of a chess game from the point of view of the objects:
1. A board which contains an 8 x 8 array of squares.
2. A square which may bw black or whit, and may contain a chess piece.
3. A chess piece which has a colour, and move type (count and direction).
4. Specific types of Chesspieces, King, Queen, Bishop etc., which have spcific move types.
You have defined a property of your Pawn (colour0 which would be common to all chess pieces. Your Chesspiece class contains a char variable the looks to hold W or B denoting colour. It also contains the Board, which makes no sense at all.
Stop writing code, and spend some time sketching out your classes and what properties and methods each one needs.
这篇关于帮助错误创建Java错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文