Question: Create a new class to make the code below work to aid a two player tic tac toe game. _ _ _ _ _ _

Create a new class to make the code below work to aid a two player tic tac toe game.
____________________________________________________________________________________________
private static void playGame(Scanner keyboard){
char p ='X';
TicTacToe ttt = new TicTacToe();
int r, c;
do {
System.out.println(ttt);
do {
System.out.print("'"+ p +"', choose your location (row, column): ");
try {
r = keyboard.nextInt();
c = keyboard.nextInt();
if (!ttt.isValid(r, c))
System.out.println("That is not a valid location. Try again.");
else if (ttt.playerAt(r, c)!='')
System.out.println("That location is already full. Try again.");
else
break;
}
catch (Exception e){
System.out.println("Bad Integer Entered. Try Again.");
keyboard.nextLine();
}
} while (true);
ttt.playMove(p, r, c);
if (p =='X')
p ='O';
else
p ='X';
} while (!ttt.isWinner('X') && !ttt.isWinner('O') && !ttt.isFull());
System.out.println(ttt);
String status;
if (ttt.isWinner('X'))
status ="X is the winner!";
else if (ttt.isWinner('O'))
status ="O is the winner!";
else
status = "The game is a tie.";
status +=" After "+ ttt.getTurns()+" plays.";
System.out.println(status);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!