Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the game Tic-Tac-Toe, players take turns trying to place symbols on a 3X3 gri

ID: 3638373 • Letter: I

Question

In the game Tic-Tac-Toe, players take turns trying to place symbols on a 3X3 grid with the goal of trying to get three in a row horizontally, vertically, or diagonally (either upper-left to bottom-right or vice-versa). In this particular version of the game, we will allow a user to place either an X or an O on the screen, with X having the first turn.

The game will be played on a board in which the rows and columns are labeled from 0 to 2 as shown below:

  0 1 2
0  | |
  -+-+-
1  | |
  -+-+-
2  | |

(Hint: It might be easy to make 9 global char variables that hold the game board data.)

The game will be player vs. computer, with the user playing as the starting X. Error checking in this program must be strictly enforced; that is, players must not be allowed to enter values for either the row or column lower than 0 or greater than 2. Also, the game should recognize an invalid move because either an X or O is already in the place that the user wishes to play. In such a case, the user should be allowed to try again. The computer will randomly choose location in such a way that it plays in the first legal position in which it attempts. (No need for AI.) Before every turn, the game board must be displayed to the user with complete game information. At the end of each turn, the game board should be checked to see if there is a winning condition. If so, the game terminates and the winner is announced.

In order to write this program, the following methods must be implemented as written:

You are, of course, allowed to implement any other methods you see fit; however, a large percentage of your grade will depend on the implementations of the methods as specified above.

CAWindowsisystem32Mcmd.exe Row: 2 Co luann: 2 o wins any ke

Explanation / Answer

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; public class TicTacToe implements ActionListener { final String VERSION = "1.0"; //Setting up ALL the variables JFrame window = new JFrame("Tic-Tac-Toe " + VERSION); JMenuBar mnuMain = new JMenuBar(); JMenuItem mnuNewGame = new JMenuItem("New Game"), mnuInstruction = new JMenuItem("Instructions"), mnuExit = new JMenuItem("Exit"), mnuAbout = new JMenuItem("About"); JButton btn1v1 = new JButton("Player vs Player"), btn1vCPU = new JButton("Player vs CPU"), btnBack = new JButton("
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote