Hello
After some advice from a few more experienced members on this board I decided to scrap my poor attempt at a chess engine and start over , this time using OOP.
I am currently having an issue with using enum variables and objects.
Please excuse my ignorance before hand , I come from a background of embedded programming.
Basically I have a class ChessGame for the game itself , a class ChessPiece and a class for each of the types of Pieces (king , queen , bishop etc) which extends ChessPiece.
First of all , why do the individual pieces classes extend ChessPiece? Because I use an enum type for the color and rank of the piece and I doesn't allow me to declare it in each class separately.
Now , when I start the interface , I create a new instance of the ChessGame. In that instance of the ChessGame I want to create an instances of all the pieces on the board meaning 2 kings , 2 queens , 16 pawns etc .
Can someone tell me why this is giving me an error? The line where I make an instance of a king.
I've tried making an instance of the king from the class , constructor , main and anywhere else I could think of but it's giving me an error saying that the enum types ( WHITE , RANK )
- Cannot find symbol : variable WHITE .
Why is it not working? The King class extends the ChessPiece class where the enum types are declared.
public class ChessGame { King kingWhite = new King(WHITE , KING , 0 , 4 ); private int chosenSquareXCoordinate; private int chosenSquareYCoordinate; //...........................................
The constructor in the King class:
public King(Shade color, Rank rank, int piecePositionX , int PiecePositionY) { super(); isAlive = true; // Whether the piece is still on the board this.color = color; // Color of the piece this.rank = rank; // Type of piece this.piecePositionX = piecePositionX; this.piecePositionY = piecePositionY; }
and the Chesspiece Class where the enum is declared:
enum Shade { WHITE , BLACK } enum Rank { PAWN , ROOK , KNIGHT , BISHOP , QUEEN , KING , BLANK } public class ChessPiece { Shade color; // color of the piece Rank rank; // Type of piece public ChessPiece() { } // ....................