Results 1 to 3 of 3
  1. #1
    SunDontShine is offline Member
    Join Date
    Jul 2014
    Posts
    22
    Rep Power
    0

    Default Simple Question about Enum?

    Hello Everyone,

    I am trying to write a small program for chess (console based for now).
    Can someone please tell me what is wrong with my code for creating an object of WHITE or BLACK. They are all in the same package

    The first chunk of code is my class for "Chess Board" which for now is just going to have all of the game piece objects created onto the board
    second chunk is the extended GamePiece class
    Third, is the actual Bishop Class.

    As you can see I am attempting to create a Black Bishop One on line 26. But i receive an error. The error underlines line 26 and asks to import the
    enum under GamePiece.Color;
    I do and it doesn't fix the problem. I am still under the same package so I am a little confused. Please let me know if you have questions,
    Java Code:
    
    public class ChessBoard
    {
    //variables
    	private GamePiece boardSpace[][];
    	
    //Black Team Game Pieces(16 total Objects)
    	Bishop BB1, BB2;
    	King BK;
    	Knight BK1, BK2;
    	Pawn BP1, BP2, BP3, BP4, BP5, BP6, BP7, BP8;
    	Queen BQ;
    	Rook BR1, BR2;
    //White Team Game Pieces (16 total objects)
    	Bishop WB1, WB2;
    	King WK;
    	Knight WK1, WK2;
    	Pawn WP1, WP2, WP3, WP4, WP5, WP6, WP7, WP8;
    	Queen WQ;
    	Rook WR1, WR2;
    	
    	GamePiece test;
    //constructor
    	public ChessBoard()
    	{
    		boardSpace = new GamePiece[ChessGame.boardsize][ChessGame.boardsize];
    		BB1 = new Bishop(Color.BLACK);
    	}
    //methodd
    	
    }

    ///////////////////Game Piece Class
    Java Code:
     public abstract class GamePiece
    {
    	 public enum Color
    	 {
    		 BLACK, WHITE
    	 }
    	 
    	private boolean validMove[][];
    	private Color color;
    	GamePiece(Color color)
    	{
    		this.color = color;
    		validMove = new boolean[ChessGame.boardsize][ChessGame.boardsize];
    	}
    /////////////////Bishop
    Java Code:
    
    public class Bishop extends GamePiece
    {
    
    	Bishop(Color color) {
    		super(color);
    	}
    
    	public boolean calcValidMoves(ChessBoard board) {
    		return false;
    	}
    	
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Simple Question about Enum?

    My first guess would be there is a conflict between the JDK Color class and your enum Color. I would change your enum to some other name (even if this is not the problem). Then it will be easier to diagnose.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    SeanK is offline Member
    Join Date
    Nov 2014
    Posts
    1
    Rep Power
    0

    Default Re: Simple Question about Enum?

    You need to reference the Color enum (which exists in GamePiece class) as follows..

    Java Code:
    BB1 = new Bishop(GamePiece.Color.BLACK);
    Sean K.

Similar Threads

  1. Enum question
    By rome99 in forum New To Java
    Replies: 12
    Last Post: 07-30-2014, 03:39 AM
  2. Question on Enum
    By rome99 in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2014, 03:57 AM
  3. public static enum vs enum class
    By Dipke in forum New To Java
    Replies: 3
    Last Post: 08-30-2011, 11:45 AM
  4. Simple Question
    By barusk in forum Networking
    Replies: 13
    Last Post: 03-04-2009, 08:33 PM
  5. Probably a really simple question...
    By ibanez270dx in forum New To Java
    Replies: 0
    Last Post: 11-16-2007, 02:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •