a. Create a Tic Tac Toe game. In this game, two players alternate placing Xs and Os

Question:

a. Create a Tic Tac Toe game. In this game, two players alternate placing Xs and Os into a grid until one player has three matching symbols in a row, horizontally, vertically, or diagonally. Create a game in which the user is presented with a three-by-three grid containing the digits 1 through 9. When the user chooses a position by typing a number, place an X in the appropriate spot. Generate a random number for the position where the computer will place an O. Do not allow the player or the computer to place a symbol where one has already been placed. Figure 9-29 shows the first four windows in a typical game. When either the player or computer has three symbols in a row, declare a winner; if all positions have been exhausted and no one has three symbols in a row, declare a tie. Save the game as TicTacToe.java.

Input Enter the position where you want to piay Message 123 45 6 х Welcome to Tic Tac Toe. You will have X and the comp

Message Message Your move is recorded; now the computer will play The computer has played 123 123 456 4 56 X 8 9 хо9 ?

b. In the TicTacToe application, the computer€™s selection is chosen randomly. Improve the game so that when the computer has two Os in any row, column, or diagonal, it selects the winning position for its next move rather than selecting a position randomly. Save the improved game as TicTacToe2.java.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Java Programming

ISBN: 978-1337397070

9th edition

Authors: Joyce Farrell

Question Posted: