Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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();
	}
	
}
Posted
Updated 31-Jul-18 21:29pm
v3
Comments
OriginalGriff 1-Aug-18 2:31am    
"It doesn't work" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900