What did I mess up?
import java.util.Scanner;
public class TicTacToeExe
{
public static void main(String[] args)
{
int userInput;
int player;
boolean game = true;
boolean switchPlayers = true;
char answer = 'n';
Scanner keyboard;
keyboard = new Scanner(System.in);
do
{
// construct the object of the class
Scanner input = new Scanner(System.in);
TicTacToeClass myAssistant = new TicTacToeClass();
System.out.print("Welcome to the Game of Tic Tac Toe\n");
System.out.println("The board is set up using the numbers from 0-8\nUse" +
" the chart below to plan your moves accordingly\n ");
System.out.println(" 0 1 2");
System.out.println(" 3 4 5");
System.out.println(" 6 7 8\n\n");
System.out.println("***************************************************");
myAssistant.displayBoard();
// switches between the active player
while(game)
{
if(switchPlayers)
{
player = 1;
}
else player = 2;
System.out.print("Player " + player + " Please enter your Move (0 - 8)\n");
userInput = input.nextInt();
//validate the input here, after the user inserts an input
while(userInput < 0 || userInput > 8)
{
System.out.println("Sorry, you have to enter a number betweem 0 - 8\n");
System.out.println("Please try Again\n");
userInput = input.nextInt();
}
myAssistant.playerMove(player, userInput);
myAssistant.displayBoard();
myAssistant.determineWinner();
//switching player
switchPlayers =! switchPlayers;
}
System.out.print("\nWould you Like to Play Again? (Y/N)");
answer = keyboard.next().charAt(0);
if (answer =='n')
{
System.out.println("Thanks for Playing!!");
}
else if (answer =='y')
{
System.out.println("Good Luck");
}
} while (answer == 'y');
}
}

New Topic/Question
Reply



MultiQuote







|