Create a class TicTacToe that will enable you to write a program to play Tic-Tac
ID: 3658624 • Letter: C
Question
Create a class TicTacToe that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional array. Use an enumeration to represent the value in each cell of the array. The enumeration's constants should be named X, O and EMPTY(for a position that does not contain an X or an O). The constructor should initialize the board elements to EMPTY. Allow two human players. Wherever the first player moves, place an X in the specified square, and place an O wherever the second player moves. Each move must be to an empty square. After each move, determine whether the game has been won and whether it's a draw.Explanation / Answer
import javax.swing.*; public class TicTacToe { private final int BOARDSIZE = 3; private final int WIN = 1, DRAW = 2, CONTINUE = 3; private int board[][]; private boolean firstPlayer, gameOver; public TicTacToe() { board = new int[ BOARDSIZE ][ BOARDSIZE ]; firstPlayer = true; gameOver = false; } // start game public void makeMove() { int row = 0, column = 0; while ( !gameOver ) { // first player’s turn if ( firstPlayer ) { row = Integer.parseInt( JOptionPane.showInputDialog( “Player 1: Enter row ( 0Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.