So I am making a tic tac toe game in java. It works by asking the user what space you want to play on then finds that space in a big line of if statements and then updates the boolean corresponding to the number to true so the computer knows if the space has already been played. The statement looks like this...
if (choiceone.equalsIgnoreCase("1") || choiceone.equalsIgnoreCase("one"))
{//Player 1 Choose "One"
if (bone == false)
{
bone = true;
p1t = false;
p2t = true;
one = "X ";
System.out.println("BOARD--------");
System.out.println(one + two + three);
System.out.println(four + five + six);
System.out.println(seven + eight + nine);
System.out.println("BOARD--------");
}
else if (bone == true)
{
System.out.println("That space has allready been used. Turn Wasted");
p1t = false;
p2t = true;
System.out.println("BOARD--------");
System.out.println(one + two + three);
System.out.println(four + five + six);
System.out.println(seven + eight + nine);
System.out.println("BOARD--------");
}
}//Player 1 Choose "One"
Varibles List:
bone = boolean for the space 1 detecting if it is true of false.
p1t = boolean detecting if it is player 1's turn or not.
p2t = boolean detecting if it is player 2's turn or not
one = space on board (same goes for two, three, four etc. etc.)
choiceone = Player 1's choice of space
Now just imagine 8 more of those for player 1 and 9 more for player two and you basically got my whole code. I would show you all my code but it is over 600 lines of code. Anyways when I run this it runs the first if statment but then it also runs the second else if statment regardless of it being an "Else if" statment. If anyone knows why that is happening I would be pleased to know.
Thanks
Aucun commentaire:
Enregistrer un commentaire