Currently i am coding a simple tic tac toe code in java. Everything works fine but i have a problem.
int[] board = new int[9];
for(int i = 0; i < board.length; i++){
board[i] = 7;
}
This is my board.It has 9 fields.
if(zug >= 9 || zug < 0){
System.out.println("Dieses Feld gibt es nicht! Versuche es erneut!");
zug1class(player, playerone1, playertwo2, board2,zug1check2 );
}
else if (zug < 9 || zug > 0){
check = zug;
System.out.println(check);
meinBoard[zug] = 0;
}
And this is my statement for setting a fied. But i want to implement that the code checks with the if statement if the field is taken. I tried it with this:
int[] fieldchecker= new int[9];
for(int i = 0; i < board.length; i++){
board[i] = -1;
}
And then after choosing a field:
fieldchecker[zug] = zug;
And then it checks in the if statement:
if(zug == fieldchecker[zug]{
//Do something
}
But this doesnt work for me. :/ I hope you can help me :D
Marvin
Aucun commentaire:
Enregistrer un commentaire