colors - getColor() method not found? Chess Game Help Java -
so i'm trying code chess program in java i'm having trouble getcolor() method. i'm relying on of code gridworld. i've created class each piece. want piece work critter gridworld in sense have method creates arraylist of possible locations choose when moving. i've hit problem. i've tried create getcolor() method, reason not working. asked teacher puzzled was. tried debugging don't see wrong it. exact error this:
"cannot find symbol - method getcolor()"
here's code, i'm using bluej record:
import java.util.arraylist; import java.awt.color; public interface piece { public enum piecetype {pawn, rook, knight, bishop, queen, king} }
next chesspiece abstract class. haven't worked on selectmovelocation method yet though:
import java.util.arraylist; import java.awt.color; import info.gridworld.grid.location; import info.gridworld.grid.boundedgrid; public abstract class chesspiece implements piece { color colorofpiece; piecetype typeofpiece; public boundedgrid<object> board; public location location; public arraylist movelocations; public chesspiece( color whiteorblack, piecetype selectedtype) { if (whiteorblack == color.black || whiteorblack == color.white) { if ((selectedtype == piecetype.pawn || selectedtype == piecetype.rook || selectedtype == piecetype.knight || selectedtype == piecetype.bishop ||selectedtype == piecetype.queen || selectedtype == piecetype.king)) { colorofpiece = whiteorblack; typeofpiece = selectedtype; location = null; } } } public color getcolor() { return colorofpiece; } public void makemove(location newlocation) { if (board == null) throw new illegalstateexception("this actor not in board."); if (board.get(location) != this) throw new illegalstateexception( "the board contains different actor @ location " + location + "."); if (!board.isvalid(newlocation)) throw new illegalargumentexception("location " + newlocation + " not valid."); if (newlocation.equals(location)) return; board.remove(location); location = newlocation; board.put(location, this); } public location getlocation() { return location; } public boundedgrid<object> getboard() { return board; } public location selectmovelocation(arraylist<location> movelocations) { location selection; selection = null; //mouse stuff return selection; } }
and finally, code gives me compiler error. code king piece, though gives me error every piece try , implement it:
import java.awt.color; import java.util.arraylist; import info.gridworld.grid.location; import info.gridworld.grid.boundedgrid; //must fix problem getcolor() public class king extends chesspiece { arraylist<location> movelocations; // private color colorofpiece; public king( color whiteorblack ) { super(whiteorblack, piecetype.king); //colorofpiece = whiteorblack; } public void getmovelocations() { movelocations.clear(); (int = 0; < 360; += 45) { if ((getboard().isvalid(getlocation().getadjacentlocation(i))) && (((getboard().get(getlocation().getadjacentlocation(i))) == null) || (((getboard().get(getlocation().getadjacentlocation(i)))).getcolor() == colorofpiece))) { movelocations.add(getlocation().getadjacentlocation(i)); } } } }
getboard().get(..) returns template type e according doc found online, , in case, e type object (since board data member in chesspiece collection of objects.) object has no getcolor() method. you'll want cast (((getboard().get(getlocation().getadjacentlocation(i)))) class has getcolor method. (or maybe change board collection of chesspieces)
Comments
Post a Comment