帮助错误创建Java错误 [英] Help error create java eror

查看:163
本文介绍了帮助错误创建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();
	}
	
}

推荐答案

我在
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屋!

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