Skip to content

Instantly share code, notes, and snippets.

@internalbuffer
Last active July 23, 2018 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save internalbuffer/eee725b6f0676974946720196db08d57 to your computer and use it in GitHub Desktop.
Save internalbuffer/eee725b6f0676974946720196db08d57 to your computer and use it in GitHub Desktop.
using System;
namespace TicTacKitty
{
class Program
{
static bool Player;
static string Position;
static string[] Board;
static string[] PlayerSets = new string[]
{
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
};
static void GetInput()
{
Position = Console.ReadLine();
if (Position.Length == 1)
SetPlayerInput(Position);
else
GetInput();
}
static void SetPlayerInput(string Position)
{
Player = !Player;
try
{
if (PlayerSets[Convert.ToInt32(Position)] == Position)
PlayerSets[Convert.ToInt32(Position)] = Player ? "X" : "O";
else
Player = !Player;
}
catch (Exception)
{
Player = !Player;
}
Draw();
}
static void RenderBoard()
{
Board = new string[] {
PlayerSets[0] + " | " + PlayerSets[1] + " | " + PlayerSets[2]+ "\n",
"---------\n",
PlayerSets[3] + " | " + PlayerSets[4] + " | " + PlayerSets[5]+ "\n",
"---------\n",
PlayerSets[6] + " | " + PlayerSets[7] + " | " + PlayerSets[8]+ "\n"
};
}
static bool Compare(string Variable1, string Variable2, string Variable3)
{
bool tmpbool;
if (Variable1 == Variable2 && Variable2 == Variable3)
tmpbool = true;
else
tmpbool = false;
return tmpbool;
}
static void Check()
{
//Yes i do realize how messy this looks, i don't give a fuck!
if (Compare(PlayerSets[0], PlayerSets[1], PlayerSets[2]) ||
Compare(PlayerSets[0], PlayerSets[3], PlayerSets[6]) ||
Compare(PlayerSets[0], PlayerSets[4], PlayerSets[8]) ||
Compare(PlayerSets[1], PlayerSets[4], PlayerSets[7]) ||
Compare(PlayerSets[2], PlayerSets[5], PlayerSets[8]) ||
Compare(PlayerSets[2], PlayerSets[4], PlayerSets[6]) ||
Compare(PlayerSets[3], PlayerSets[4], PlayerSets[5]) ||
Compare(PlayerSets[6], PlayerSets[7], PlayerSets[8]))
{
Console.Write(PlayerSets[0] == "O" ? "Player O has won the game!" : "Player X has won the game!");
Console.ReadLine();
}
else
GetInput();
}
static void Draw()
{
Console.Clear();
RenderBoard();
for (int i = 0; i < Board.Length; i++)
Console.Write(Board[i]);
Check();
}
static void Main()
{
Draw();
}
}
}
©InternalBusiness every piece of code should be threated with matter, Else im gonna sue you!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment