Write a two player tic-tac-toe program in C# that has the following requirements: loops, classes, arrays, switch statements, methods and functions. The program must include at least 70 lines of code and does NOT require a GUI.
The current program requirements are represented above but I’m having difficulty starting the program. Any help and example would be greatly appreciated.
using System;
using System.Threading;
namespace TIC_TAC_TOE
{
class Program
{
//making array
static char[] arr = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
static int player = 1;
static int choice;
static int flag = 0;
static void Main(string[] args)
{
do
{
Console.Clear();
Console.WriteLine("Player1:X and Player2:O");
Console.WriteLine("\n");
if (player % 2 == 0)
{
Console.WriteLine("Player 2 Chance");
}
else
{
Console.WriteLine("Player 1 Chance");
}
Console.WriteLine("\n");
Board();
choice = int.Parse(Console.ReadLine());
if (arr[choice] != 'X' && arr[choice] != 'O')
{
if (player % 2 == 0)
{
arr[choice] = 'O';
player++;
}
else
{
arr[choice] = 'X';
player++;
}
}
else
{
Console.WriteLine("Sorry the row {0} is already marked with {1}", choice, arr[choice]);
Console.WriteLine("\n");
Console.WriteLine("Please wait 2 second board is loading again.....");
Thread.Sleep(2000);
}
flag = CheckWin();
} while (flag != 1 && flag != -1);
Console.Clear();
Board();// getting filled board again
if (flag == 1)
{
Console.WriteLine("Player {0} has won", (player % 2) + 1);
}
else
{
Console.WriteLine("Draw");
}
Console.ReadLine();
}
private static void Board()
{
Console.WriteLine(" | | ");
Console.WriteLine(" {0} | {1} | {2}", arr[1], arr[2], arr[3]);
Console.WriteLine("_____|_____|_____ ");
Console.WriteLine(" | | ");
Console.WriteLine(" {0} | {1} | {2}", arr[4], arr[5], arr[6]);
Console.WriteLine("_____|_____|_____ ");
Console.WriteLine(" | | ");
Console.WriteLine(" {0} | {1} | {2}", arr[7], arr[8], arr[9]);
Console.WriteLine(" | | ");
}
private static int CheckWin()
{
#region Horzontal Winning Condtion
if (arr[1] == arr[2] && arr[2] == arr[3])
{
return 1;
}
else if (arr[4] == arr[5] && arr[5] == arr[6])
{
return 1;
}
else if (arr[6] == arr[7] && arr[7] == arr[8])
{
return 1;
}
#endregion
#region vertical Winning Condtion
else if (arr[1] == arr[4] && arr[4] == arr[7])
{
return 1;
}
else if (arr[2] == arr[5] && arr[5] == arr[8])
{
return 1;
}
else if (arr[3] == arr[6] && arr[6] == arr[9])
{
return 1;
}
#endregion
#region Diagonal Winning Condition
else if (arr[1] == arr[5] && arr[5] == arr[9])
{
return 1;
}
else if (arr[3] == arr[5] && arr[5] == arr[7])
{
return 1;
}
#endregion
#region Checking For Draw
else if (arr[1] != '1' && arr[2] != '2' && arr[3] != '3' && arr[4] != '4' && arr[5] != '5' && arr[6] != '6' && arr[7] != '7' && arr[8] != '8' && arr[9] != '9')
{
return -1;
}
#endregion
else
{
return 0;
}
}
}
}
Write a two player tic-tac-toe program in C# that has the following requirements: loops, classes, arrays,...
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) ...
I need a simple Tic Tac Toe program using two dimmesional arrays and functions. (Using Printf anf scanf)
I need to create a Tic Tac Toe program in C++. These are the requirements Write a program that allows the computer to play TicTacToe against a human player or allow two human players to play one another. Implement the following conditions: The player that wins the current game goes first in the next round, and their symbol is X. The other player will be O. Keep track of the number of games played, wins, and draws for each player....
1. Use Turtle Graphics to create a tic tac toe game in Python. Write a Python program that allows for one player vs computer to play tic tac toe game, without using turtle.turtle
So I have to make a tic tac toe game in C++. and the problem is asking me to design, implement and test classea to reperesnt the game board(3x3 sqaure), and the x and o markers. the problem is also asking me to provide suitable observor and mutator methods for modifying the game board and displaying game status. I have to use clases to create a game that prompts for player x and player O to place markers at specified...
Hey guys, I need help writing a Tic-Tac-Toe game programmed in Java. The game has to be a 1D (One-Dimension) array board NOT 2D. It has to be a human plays against the computer type of Tic-Tac-Toe. Here is the requirements for the program. PLEASE NO COPY AND PASTE ANSWER. Thank you in advance! You will develop a program in which a human plays against the computer. 1. Validate user input at every opportunity. a. Do not allow number entries...
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...
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...
Assignment C++: Rock-Scissor-Paper & Tic-Tac-Toe i need you to write two different program for RSP and TTT: R-S-P Requirement: - write one program that mimics the Rock-Scissor-Paper game. This program will ask user to enter an input (out of R-S-P), and the computer will randomly pick one and print out the result (user wins / computer wins). - User's input along with computer's random pick will be encoded in the following format: -- user's rock: 10 -- user's scissor: 20...
Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two-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: 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 user to enter...