private static void GameResult() { // TODO Input object for log construction if (tied == true) { Game.ClearScreen(); WriteLine("-------------------------------------------------------------------"); WriteLine(" Game Over "); WriteLine("-------------------------------------------------------------------"); WriteLine("\n\n\n\nResult:"); WriteLine("Game Tied!"); } if (gameWon == true) { Game.ClearScreen(); WriteLine("-------------------------------------------------------------------"); WriteLine(" Game Over "); WriteLine("-------------------------------------------------------------------"); WriteLine("\n\n\n\nResult:"); WriteLine("Player " + winningPlayer.GetPlayerNum() + " won the game!"); WriteLine("\nPress Enter to continue..."); ReadKey(); ResetGame(); } }
private static void CheckDiagnalWinUp(Player player) { int fourInRow = 0; // cycles through each space for (int row = 0; row < Game.board.Length; row++) { for (int column = 0; column < Game.board[row].Length; column++) { // found a space with player token if (Game.board[row][column] == player.GetPlayerNum()) { // prevents going off Game.board if (row - 3 >= 0 && column + 3 < Game.board[row].Length) { // look for four in a row for (int s = 0; s < 4; s++) { // plug because Game.board looks inverted from index int r = row - s; int c = column + s; if (Game.board[r][c] == player.GetPlayerNum()) { fourInRow++; // game won if (fourInRow >= 4) { Manager.GameWon(player); return; } } else { fourInRow = 0; break; } } } } } } }
public static void Turn(Player player) { Game.ClearScreen(); WriteLine("-------------------------------------------------------------------"); WriteLine("Player Turn: " + player.GetPlayerNum()); WriteLine("-------------------------------------------------------------------"); Game.PrintBoard(); PlayerPickColumn(player); WinChecker.CheckForWin(player); }
public static bool ValidatePlayerChoice(int userInput, Player player) { for (int r = board.Length - 1; r >= 0; --r) { if (board[r][userInput] == 0) { // assign space to user board[r][userInput] = player.GetPlayerNum(); return(true); } } // row is full return(false); }
private static void CheckVerticalWin(Player player) { int fourInRow = 0; // cycles through each space for (int row = 0; row < Game.board.Length - 3; row++) { for (int column = 0; column < Game.board[row].Length; column++) { // found a space with player token if (Game.board[row][column] == player.GetPlayerNum()) { // checks for four in a row for (int r = row; r < row + 4; r++) { if (Game.board[r][column] == player.GetPlayerNum()) { fourInRow++; // game won if (fourInRow >= 4) { Manager.GameWon(player); return; } } else { fourInRow = 0; break; } } } } } }
public static void LogToFile(Player winner, Player loser) { try { StreamWriter write = new StreamWriter(log, true); write.WriteLine("Winnter: " + winner.GetPlayerNum()); write.WriteLine("Loser: " + loser.GetPlayerNum()); write.WriteLine("-----------"); write.Close(); } catch (Exception e) { Console.WriteLine("Error: \n" + e); } }