(Tic-Tac-Toe) Create class TicTacToe that will enable you to write a complete app to play the game of Tic-Tac-Toe. The class contains a private 3-by-3 rectangular array of integers. The constructor should initialize the empty board to all 0s. Allow two human players. Wherever the first player moves, place a 1 in the specified square, and place a 2 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.
I want this in C#
There are 2 files required for this game to run. 1st file is TicTacToe.cs and 2nd is the driver file. Both the file codes are posted below in their respective tables. You are required to create a Windows Console C# Project in visual studio and then create 2 class files named TicTacToe.cs and another as Program.cs and then copy the below codes and paste into these files one by one.
TicTacToe.cs |
using System; namespace Tic_Tac_Toe public TicTacToe() public bool isFirstPlayerTurn() public void printInstructions() public void printBoard() Console.WriteLine(" " + board[0, 0] + " | " + board[0, 1] + " | " + board[0, 2]); Console.WriteLine("_____|_____|_____"); Console.WriteLine(" | |"); Console.WriteLine(" " + board[1, 0] + " | " + board[1, 1] + " | " + board[1, 2]); Console.WriteLine("_____|_____|_____"); Console.WriteLine(" | |"); Console.WriteLine(" " + board[2, 0] + " | " + board[2, 1] + " | " + board[2, 2]); } public bool selectCell(int row, int col) } } private bool isValidMove(int row, int col) public int checkWinner() else if((board[1, 0] == board[1, 1]) && (board[1, 0] ==
board[1, 2]) && (board[1, 0] != 0)) else if ((board[2, 0] == board[2, 1]) && (board[2, 0] ==
board[2, 2]) && (board[2, 0] != 0)) else if ((board[0, 0] == board[1, 0]) && (board[0, 0] ==
board[2, 0]) && (board[0, 0] != 0)) else if ((board[0, 1] == board[1, 1]) && (board[0, 1] ==
board[2, 1]) && (board[0, 1] != 0)) else if ((board[0, 2] == board[1, 2]) && (board[0, 2] ==
board[2, 2]) && (board[0, 2] != 0)) else if ((board[0, 0] == board[1, 1]) && (board[0, 0] ==
board[2, 2]) && (board[0, 0] != 0)) else if ((board[2, 2] == board[1, 1]) && (board[2, 2] ==
board[2, 0]) && (board[2, 2] != 0)) } |
Program.cs |
using System; namespace Tic_Tac_Toe if(game.isFirstPlayerTurn()) Console.WriteLine(); bool validMove = game.selectCell(row, col); if (winner == 1) } Console.ReadKey(); |
OUTPUT
NOTE: If there is some issue with slash n and slash t (escape sequences) i.e., any output format related issues then please comment in the comment box and I will post the code screenshots.
(Tic-Tac-Toe) Create class TicTacToe that will enable you to write a complete app to play the...
(Tic-Tac-Toe) Create a class Tic-Tac-Toe 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...
Please make this into one class. JAVA Please: Tic Tac Toe class - Write a fifth game program that can play Tic Tac Toe. This game displays the lines of the Tic Tac Toe game and prompts the player to choose a move. The move is recorded on the screen and the computer picks his move from those that are left. The player then picks his next move. The program should allow only legal moves. The program should indicate when...
In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A stalemate occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Write a program...
(Game: play a tic-tac-toe game) In a game of tic-tac-toe, two players take turns marking an available cell in a grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells in the grid have been filled with tokens and neither player has achieved a win. Create...
PYTHON Exercise 2. Tic-Tac-Toe In this exercise we are going to create a Tic-Tac-Toe game. 1. Create the data structure – Nine slots that can each contain an X, an O, or a blank. – To represent the board with a dictionary, you can assign each slot a string-value key. – String values in the key-value pair to represent what’s in each slot on the board: ■ 'X' ■ 'O' ■ ‘ ‘ 2. Create a function to print the...
Write a c program that will allow two users to play a tic-tac-toe game. You should write the program such that two people can play the game without any special instructions. (assue they know how to play the game). Prompt first player(X) to enter their first move. .Then draw the gameboard showing the move. .Prompt the second player(O) to enter their first move. . Then draw the gameboard showing both moves. And so on...through 9 moves. You will need to:...
Write a program to Simulate a game of tic tac toe. A game of tic tac toe has two players. A Player class is required to store /represent information about each player. The UML diagram is given below.Player-name: string-symbol :charPlayer (name:string,symbol:char)getName():stringgetSymbol():chargetInfo():string The tic tac toe board will be represented by a two dimensional array of size 3 by 3 characters. At the start of the game each cell is empty (must be set to the underscore character ‘_’). Program flow:1) ...
18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Write . Displays the contents of the board array. . Allows player 1 to select a location on the board for an X. The program should ask the...
In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A stalemate occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Write a program...
I need help developing this app using java in android studio Assignment: Tic-Tac-Toe app User interface Operation The app allows the user to play a game of Tic-Tac-Toe. The user can click the New Game button at any time to start a new game. The app displays other messages to the user as the game progresses such as (1) whose turn it is, (2) if a player wins, and (3) if the game ends in a tie. Specifications The app...