Basic Tic Tac Toe programming help please
835239Jan 29 2011 — edited Jan 30 2011I'm trying to make a seperate java class(there is another main that calls this using SWING interface) that makes mark on the board.
It's supposed to do the following
Method makeMark returns:
a null if the cell indicated by row and column has already been marked
an X if it is X's turn (X gets to go first)
a Y if it is Y's turn
Thus makeMark will have to keep of marks made previously and return the appropriate string
for the requested cell.
and here is what I got so far, but only getting empty clicks as a respond. Any help will be appreciated. thanks.
import javax.swing.JButton;
public class TicTacToeGame {
public String makeMark(int row, int column){
String player = "X";
String [][] Enum = new String [3][3];
for (row=0; row<=2; row++){
for (column=0; column<=2; column++)
{
if (Enum[row][column] == "")
{
if (player == "X"){
Enum[row][column] = "X";
player = "Y";
return "X";
}
if (player == "Y"){
Enum[row][column] = "O";
player = "X";
return "Y";
}
}
else
return null;
}
}
return player;
}
}