Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Main
- {
- class Program
- {
- static void Main()
- {
- string[,] possition_array = { { ".", ".", "." }, { ".", ".", "." }, { ".", ".", "." } };
- Console.WriteLine("Hello Players!");
- Console.WriteLine("Following is the board, you will enter numbers 1-9 to put down your mark.");
- Draw_board(possition_array);
- Console.WriteLine("Please enter wether you are playing as X or O; ");
- string Player1 = Console.ReadLine();
- switch (Player1)
- {
- case "X":
- int x = 0;
- Play(x, possition_array);
- break;
- case "O":
- int i = 1;
- Play(i, possition_array);
- break;
- default:
- Console.WriteLine("Please enter either X or O, as represented, to start the game");
- Main();
- break;
- }
- }
- static void Play(int x, string[,] possition_array)
- {
- Victory_check(possition_array);
- Draw_board(possition_array);
- string[] player_array = new string[] { "X", "O" };
- Console.WriteLine("Please enter where you wish to put your mark, ", player_array[x], ".");
- string Player_entry = Console.ReadLine();
- switch (Player_entry)
- {
- case "1":
- if (possition_array[0, 0] == ".")
- {
- possition_array[0, 0] = player_array[x];
- Player_change(x, possition_array);
- }
- else
- {
- Console.WriteLine("There's already a mark here, please try another number.");
- Play(x, possition_array);
- }
- break;
- case "2":
- if (possition_array[0, 1] == ".")
- {
- possition_array[0, 1] = player_array[x];
- Player_change(x, possition_array);
- }
- else
- {
- Console.WriteLine("There's already a mark here, please try another number.");
- Play(x, possition_array);
- }
- break;
- case "3":
- if (possition_array[0, 2] == ".")
- {
- possition_array[0, 2] = player_array[x];
- Player_change(x, possition_array);
- }
- else
- {
- Console.WriteLine("There's already a mark here, please try another number.");
- Play(x, possition_array);
- }
- break;
- case "4":
- if (possition_array[1, 0] == ".")
- {
- possition_array[1, 0] = player_array[x];
- Player_change(x, possition_array);
- }
- else
- {
- Console.WriteLine("There's already a mark here, please try another number.");
- Play(x, possition_array);
- }
- break;
- case "5":
- if (possition_array[1, 1] == ".")
- {
- possition_array[1, 1] = player_array[x];
- Player_change(x, possition_array);
- }
- else
- {
- Console.WriteLine("There's already a mark here, please try another number.");
- Play(x, possition_array);
- }
- break;
- case "6":
- if (possition_array[1, 2] == ".")
- {
- possition_array[1, 2] = player_array[x];
- Player_change(x, possition_array);
- }
- else
- {
- Console.WriteLine("There's already a mark here, please try another number.");
- Play(x, possition_array);
- }
- break;
- case "7":
- if (possition_array[2, 0] == ".")
- {
- possition_array[2, 0] = player_array[x];
- Player_change(x, possition_array);
- }
- else
- {
- Console.WriteLine("There's already a mark here, please try another number.");
- Play(x, possition_array);
- }
- break;
- case "8":
- if (possition_array[2, 1] == ".")
- {
- possition_array[2, 1] = player_array[x];
- Player_change(x, possition_array);
- }
- else
- {
- Console.WriteLine("There's already a mark here, please try another number.");
- Play(x, possition_array);
- }
- break;
- case "9":
- if (possition_array[2, 2] == ".")
- {
- possition_array[2, 2] = player_array[x];
- Player_change(x, possition_array);
- }
- else
- {
- Console.WriteLine("There's already a mark here, please try another number.");
- Play(x, possition_array);
- }
- break;
- default:
- Console.WriteLine("Please enter a number 1-9.");
- Play(x, possition_array);
- break;
- }
- }
- static void Victory_check(string[,] possition_array)
- {
- for (int i = 0; i < 3; i++)
- {
- if ((possition_array[i, 0] == "X") & (possition_array[i, 1] == "X") & (possition_array[i, 2] == "X"))
- {
- End("X", possition_array);
- }
- else if ((possition_array[i, 0] == "O") & (possition_array[i, 1] == "O") & (possition_array[i, 2] == "O"))
- {
- End("O", possition_array);
- }
- else if ((possition_array[0, i] == "X") & (possition_array[1, i] == "X") & (possition_array[2, i] == "X"))
- {
- End("X", possition_array);
- }
- else if ((possition_array[0, i] == "O") & (possition_array[1, i] == "O") & (possition_array[2, i] == "O"))
- {
- End("O", possition_array);
- }
- else if ((possition_array[0, 0] == "X") & (possition_array[1, 1] == "X") & (possition_array[2, 2] == "X"))
- {
- End("X", possition_array);
- }
- else if ((possition_array[0, 0] == "O") & (possition_array[1, 1] == "O") & (possition_array[2, 2] == "O"))
- {
- End("O", possition_array);
- }
- else
- {
- continue;
- }
- }
- }
- static void Player_change(int x, string[,] possition_array)
- {
- if(x == 1)
- {
- Play(0, possition_array);
- }
- else
- {
- Play(1, possition_array);
- }
- }
- static void Draw_board(string[,] possition_array)
- {
- for (int i = 0; i < 3; i++)
- {
- Console.WriteLine($"{possition_array[i, 0]} {possition_array[i, 1]} {possition_array[i, 2]}");
- }
- }
- static void End(string Victor, string[,] possition_array)
- {
- Draw_board(possition_array);
- if (Victor == "X")
- {
- Console.WriteLine("Crosses won!");
- }
- else
- {
- Console.WriteLine("Circles won!");
- }
- Console.WriteLine("Well Played. Please press Enter to quit.");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement