static string[,] gameField = new string[5, 5];
static bool playProgram = false;
static void Main(string[] args)
private static void ControlIfTie()
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
for (int j = 0; j <= gameField.GetUpperBound(1); j++)
if (gameField[i,j].Contains("X") || gameField[i,j].Contains("O"))
Console.WriteLine("Det är oavgjort!");
private static void ControlIfTwoWon()
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
for (int j = 0; j <= gameField.GetUpperBound(1); j++)
if (gameField[i, j].Contains("O"))
for (int i = 0; i <= gameField.GetUpperBound(1); i++)
for (int j = 0; j <= gameField.GetUpperBound(0); j++)
if (gameField[j, i].Contains("O"))
int scoreCountDiagonalOne = 0;
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
if (gameField[i, j].Contains("O"))
if (scoreCountDiagonalOne == 5)
int scoreCountDiagonalTwo = 0;
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
if (gameField[i, j].Contains("O"))
if (scoreCountDiagonalTwo == 5)
Console.WriteLine(playerTwo + " HAR VUNNIT!");
private static void ControlIfWon()
bool gameWonPlayerOne = false;
bool gameWonPlayerTwo = false;
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
int scoreCountPlayerOne = 0;
int scoreCountPlayerTwo = 0;
for (int j = 0; j <= gameField.GetUpperBound(1); j++)
if (gameField[i, j].Contains("X"))
if (gameField[i, j].Contains("O"))
if (scoreCountPlayerOne == 5)
if (scoreCountPlayerTwo == 5)
for (int i = 0; i <= gameField.GetUpperBound(1); i++)
int scoreCountPlayerOne = 0;
int scoreCountPlayerTwo = 0;
for (int j = 0; j <= gameField.GetUpperBound(0); j++)
if (gameField[j, i].Contains("X"))
if (gameField[j, i].Contains("O"))
if (scoreCountPlayerOne == 5)
if (scoreCountPlayerTwo == 5)
int scoreCountDiagonalOnePlayerOne = 0;
int scoreCountDiagonalOnePlayerTwo = 0;
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
if (gameField[i, j].Contains("X"))
scoreCountDiagonalOnePlayerOne++;
if (gameField[i, j].Contains("O"))
scoreCountDiagonalOnePlayerTwo++;
if (scoreCountDiagonalOnePlayerOne == 5)
if (scoreCountDiagonalOnePlayerTwo == 5)
int scoreCountDiagonalTwoPlayerOne = 0;
int scoreCountDiagonalTwoPlayerTwo = 0;
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
if (gameField[i, j].Contains("X"))
scoreCountDiagonalTwoPlayerOne++;
if (gameField[i, j].Contains("O"))
scoreCountDiagonalTwoPlayerTwo++;
if (scoreCountDiagonalTwoPlayerOne == 5)
if (scoreCountDiagonalTwoPlayerTwo == 5)
Console.WriteLine(playerOne + " HAR VUNNIT!");
Console.WriteLine(playerTwo + " HAR VUNNIT!");
private static void PlayerTwoTurn()
Console.WriteLine(playerTwo + "s tur att spela.");
Console.WriteLine("Vart vill du spela din pjäs [O]?");
Console.WriteLine("Välj en siffra: ");
bool validChoice = int.TryParse(Console.ReadLine(), out int playerChoice);
if (playerChoice >= 1 && playerChoice <= 25)
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
for (int j = 0; j <= gameField.GetUpperBound(1); j++)
string strPlayerChoice = Convert.ToString(playerChoice);
if (strPlayerChoice == gameField[i, j])
if (playerChoice >= 1 && playerChoice <= 9)
Console.WriteLine("Felaktigt svar, testa igen.");
private static void PlayerOneTurn()
Console.WriteLine(playerOne + "s tur att spela.");
Console.WriteLine("Vart vill du spela din pjäs [X]?");
Console.WriteLine("Välj en siffra: ");
bool validChoice = int.TryParse(Console.ReadLine(), out int playerChoice);
if (playerChoice >= 1 && playerChoice <= 25)
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
for (int j = 0; j <= gameField.GetUpperBound(1); j++)
string strPlayerChoice = Convert.ToString(playerChoice);
if (strPlayerChoice == gameField[i, j])
if (playerChoice >= 1 && playerChoice <= 9)
Console.WriteLine("Felaktigt svar, testa igen.");
private static void PrintGameboard()
Console.WriteLine(" FEM I RAD ");
for (int i = 0; i <= 1; i++)
for (int j = 0; j <= 4; j++)
Console.Write("[" + gameField[i, j] + " ] ");
Console.Write("[ " + gameField[i, j] + " ] ");
for (int i = 2; i <= gameField.GetUpperBound(0); i++)
for (int j = 0; j <= gameField.GetUpperBound(1); j++)
Console.Write("[" + gameField[i, j] + " ] ");
private static void GameSetup()
Console.WriteLine("FEM I RAD");
Console.WriteLine("Vänligen välj namn.");
Console.WriteLine("Spelare ett: ");
playerOne = Console.ReadLine();
Console.WriteLine("Spelare två: ");
playerTwo = Console.ReadLine();
for (int i = 0; i <= gameField.GetUpperBound(0); i++)
for (int j = 0; j <= gameField.GetUpperBound(1); j++)
gameField[i, j] = Convert.ToString((i * 5) + (j + 1));