static void PvC() { bool player = false; Board board = new Board(); int gameState = 0; do { Console.Clear(); Console.WriteLine("Player:X and Computer:O"); Console.WriteLine("\n"); if (player) { board.AImove(); } else { Console.WriteLine("Your turn"); Console.WriteLine("\n"); board.displayBoard(); int choice = getMove(board); board.makeMove(choice, 'X'); } player = !player; gameState = board.CheckWin(); } while (gameState == 0); Console.Clear(); Console.WriteLine("\n"); board.displayBoard(); if (gameState == 1) { if (player) Console.WriteLine("Player has won"); else Console.WriteLine("Computer has won"); } else { Console.WriteLine("Draw"); } }
static void PvP() { bool player = false; Board board = new Board(); int gameState = 0; do { Console.Clear(); Console.WriteLine("Player1:X and Player2:O"); Console.WriteLine("\n"); if (player) { Console.WriteLine("Player 2 move"); } else { Console.WriteLine("Player 1 move"); } Console.WriteLine("\n"); board.displayBoard(); int choice = getMove(board); if (player) { board.makeMove(choice, 'O'); } else { board.makeMove(choice, 'X'); } player = !player; gameState = board.CheckWin(); } while (gameState == 0); Console.Clear(); Console.WriteLine("\n"); board.displayBoard(); if (gameState == 1) { Console.WriteLine("Player {0} has won", (player) ? "2" : "1"); } else { Console.WriteLine("Draw"); } }