Author | Message |
---|---|
venny
Posts: 61
|
Posted 17:55 Oct 20, 2014 |
Hello, I thought I was on the right track but nothing is showing up on the GUI when I try to test it.
public Move getPlayerMove(int row, int col) { Move m= new MoveImpl(mainPlayer,row,col); //mainPlayer = either player is X or O allMoves.add(m); //allMoves = stack array with all the moves if(whatTurn==Player.O){ theBoard[m.getRow()][m.getCol()] = 'O'; //theBoard = 2d array of the board whatTurn=Player.X; } else { theBoard[m.getRow()][m.getCol()] = 'X'; whatTurn=Player.O; } return m; }
My autoTurn is similar to this. Am I doing something wrong? |
kscasado
Posts: 19
|
Posted 18:08 Oct 20, 2014 |
From what i can tell you should consider how you deal with whose turn it is, maybe this needs to be switched through a seperate method to avoid confusion Also if you know who the User is (mainPlayer) maybe you shouldnt need to test it with whatTurn. Hope that helps |
venny
Posts: 61
|
Posted 18:18 Oct 20, 2014 |
Would you say it was wrong to make a separate variable to keep track of the turns? I changed the code a bit, but still no dice.
public Move getPlayerMove(int row, int col) { Move m= new MoveImpl(mainPlayer,row,col); allMoves.add(m); if(mainPlayer==Player.O){ theBoard[m.getRow()][m.getCol()] = 'O';
} else { theBoard[m.getRow()][m.getCol()] = 'X';
} switchTurn(whatTurn); return m;
} private void switchTurn(Player t) { if(t==Player.O) { whatTurn=Player.X; } else { whatTurn=Player.X; } } |
kscasado
Posts: 19
|
Posted 18:33 Oct 20, 2014 |
That looks fine, have you tried checking what your board looks like? Does neither letter show up? it could be your constructor of GameImpl() hard to tell but that looks fine. |
ringworld
Posts: 11
|
Posted 20:22 Oct 20, 2014 |
You should store Move's inside a stack and loop through each element in your stack inside the getBoard() method. Doing this also makes implementing the undo and redo buttons significantly easier as well as guarantee your moves actually display on the GUI. private Stack<Move> nameofyourstackhere = new Stack<>(); public Character[][] getBoard() { for (Move m : this.nameofyourstackhere) { } }
Last edited by ringworld at
20:37 Oct 20, 2014.
|