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,...
Tic-Tac-Toe (arrays and multidimensional arrays) C++ Write an interactive program that plays tic-tac-toe. Represent the board as a 3 X 3 character array. Initialize the array to blanks and ask each player in turn to input a position. The first player's position is marked on the board with a O and the second player's position is marked with an X. Continue the process until a player wins or the game is a draw. To win, a player must have 3...
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) ...
How to write a (c++ program) tic tac toe code where its the computer against a human. and the computer always wins. a basic c++ code program using gaming theory arrays <stdio.h> computer plays tic tac toe against a user. computer always when or the game is a draw.
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...
Objective: To write a program to allow a game of Tic Tac Toe to be played, and to determine when the game is over Complete the TicTacToe program below. It will allow for a full game of Tic Tac Toe between two players, and it will tell you who won or if the game is over with no winner. Details: The TicTacToe board is stored in a 3x3 multidimensional list of characters containing spaces at the start of the game...
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...