Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how do i write in the Main class to display it ??

so when start the main is output;

-     -     -    -    -    -    -    -
-     -     -    -    -    -    -    -
-     -     -    -    -    -    -    -
-     -     -    -    -    -    -    -
-     -     -    -    -    -    -    -
-     -     -    -    -    -    -    -
-     -     -    -    -    -    -    -
WP    -     -    -    -   -     -    -


What I have tried:

Pawn Class
Java
package chessPieces;

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

Class board
package board;

import java.util.ArrayList;
import chessPieces.ChessPiece;
import chessPieces.EmptySpace;
import chessPieces.Pawn;

public class BoardInterface {
	static char white = 'W';
	static char black = 'B';
	static char empty = '-';
	ChessPiece[][] board;
	int turn;
	ArrayList<int[][]> previousMoves;
	
	public BoardInterface()
	{
		this.turn = 0;
		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);
	}
}

Class empty
package chessPieces;

public class EmptySpace extends ChessPiece {
	char color;
	public EmptySpace(char color)
	{
		this.color = color;
	}
}
Posted
Updated 29-Jul-18 22:23pm
v3
Comments
wseng 30-Jul-18 2:11am    
post ChessPiece class
Member 13906640 30-Jul-18 2:31am    
chessPiece Class and Main Class still empty,
I want to try gradually by displaying the first WP
Richard MacCutchan 30-Jul-18 3:42am    
Your board class should do the display, based on the position of all the pieces.
Member 13906640 30-Jul-18 4:09am    
how to??
Richard MacCutchan 30-Jul-18 4:18am    
By planning, thinking designing and writing code.
What should the board class contain? squares.
How are these squares set out? 8 x 8.
What does each square hold? nothing, or a chess piece.
So each square needs to know its position within the board, and what it contains.
If the square is empty, then it draws a blank coloured area.
If it contains a chess piece then it calls the piece to do the drawing

etc.

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