Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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 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();
	}
}
Posted
Updated 30-Jul-18 8:57am
Comments
Richard MacCutchan 31-Jul-18 5:15am    
Do not use separate package names for each module. Use a single package name, e.g. chessgame, and use it in all source files so they are all part of the chessgame package.

1 solution

Quote:
How to compile in java? Chess game

Exactly the same way as any other Java program.
Quote:
want to try create chess game,,
but when i run Main class no other display,,

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.
 
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