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

(Game: displaying a TicTacToe board) Display a frame that contains nine labels.

ID: 3634467 • Letter: #

Question

(Game: displaying a TicTacToe board) Display a frame that contains nine
labels. A label may display an image icon for X, an image icon for O, or nothing,
as shown in Figure 12.15(c). What to display is randomly decided. Use the
Math.random() method to generate an integer 0, 1, or 2, which corresponds to
displaying a cross image icon, a not image icon, or nothing. The cross and not
images are in the files x.gif and o.gif, which are under the image directory
in www.cs.armstrong.edu/liang/intro8e/book.zip).

Explanation / Answer

question is a bit long and difficult too //tictactoe2.h #include #include #include class TicTacToe { private: enum Status { WIN, DRAW, CONTINUE }; int board [3][3]; public: TicTacToe (); void makeMove (); void printBoard (); bool validMove (int r, int c); bool xoMove (int input); Status gameStatus (); void holdscreen (); }; TicTacToe::TicTacToe () { for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col ++) board[row][col] = " "; } } bool TicTacToe::validMove (int r, int c) { if (r >= 0 && r < 3 && c >= 0 && c < 3 && board[r][c] == " ") { return true; } else return false; } TicTacToe::Status TicTacToe::gameStatus(void) { int a; if ((board[0][0]!= " ") && (board[0][0] == board[1][1]) && (board[0][0] == [2][2])) { return WIN; } else if ((board[2][0]!= " ") && (board[2][0] == board[1][1]) && (board[2][0] == [0][2])) { return WIN; } else if ((board[0][0]!= " ") && (board[0][0] == board[0][1]) && (board[0][0] == [0][2])) { return WIN; } else if ((board[1][0]!= " ") && (board[1][0] == board[1][1]) && (board[1][0] == [1][2])) { return WIN; } else if ((board[2][0]!= " ") && (board[2][0] == board[2][1]) && (board[2][0] == [2][2])) { return WIN; } else if ((board[0][0]!= " ") && (board[0][0] == board[1][0]) && (board[0][0] == [2][0])) { return WIN; } else if ((board[0][1]!= " ") && (board[0][1] == board[1][1]) && (board[0][1] == [2][1])) { return WIN; } else if ((board[0][2]!= " ") && (board[0][2] == board[1][2]) && (board[0][2] == [2][2])) { return WIN; } if (board[row][column] = " ") { return CONTINUE; } else { return DRAW; } } //----------------------------------------------------------------------------------------- //Main Program: //game.cpp #include #include "tictactoe2.h" void main () { TicTacToe game; game.TicTacToe (); game.validMove (); game.gameStatus (); game.printBoard (); game.makeMove (); game.xoMove (); system("pause"); }