public static void ModifyGame(Player player1, Player player2) { Console.Clear(); if (NumberOfPlayers < 2) { Console.WriteLine("Would you like to modify the game board or change the A.I. difficulty?"); Console.WriteLine("Please select from the options below..."); Console.WriteLine("1 - Modify Board and Game Parameters"); Console.WriteLine("2 - Change A.I. Difficulty"); Console.WriteLine("0 - Return without changing anything"); byte answer = CX.GetKey(limit: 2); if (answer == 0) { return; } if (answer == 1) { Gameboard.CustomiseGame(player1, player2); } if (answer == 2) { if (player1.IsRobot && player2.IsRobot) { Console.WriteLine("Who would you like to change the difficulty of?"); Console.Write("1 - "); CX.Print(player1.Name, player1.Colour, null, true); Console.Write("2 - "); CX.Print(player2.Name, player2.Colour, null, true); Console.WriteLine("0 - I changed my mind and don't want to change any difficulties."); byte secondAnswer = CX.GetKey(limit: 2); if (secondAnswer == 0) { return; } if (secondAnswer == 0) { player1.ChangeDifficulty(); } if (secondAnswer == 0) { player2.ChangeDifficulty(); } } else { player2.ChangeDifficulty(); } } } else { Gameboard.CustomiseGame(player1, player2); } }
public static void VictoryMessage(Player winningPlayer, Player losingPlayer, DateTime startingTime) { Gameboard.PrintGameBoard(true); Console.Write("\nCongratulations to "); CX.Print(winningPlayer.Name, winningPlayer.Colour, null, true); Console.Write("Commiseration to "); CX.Print(losingPlayer.Name, losingPlayer.Colour, null, true); CX.Print($"\n{winningPlayer.Name}", winningPlayer.Colour); Console.Write($" made {winningPlayer.Moves} during the game.\n"); CX.Print($"\n{losingPlayer.Name}", losingPlayer.Colour); Console.Write($" made {losingPlayer.Moves} during the game.\n"); Console.WriteLine($"A total of {winningPlayer.Moves + losingPlayer.Moves} where made between both players.\n"); Console.WriteLine($"The game took {DateTime.Now - startingTime}.\n"); Console.WriteLine("Would you like to play again?"); Console.WriteLine("1 - Yes\n2 - No\n0 - Show Game Replay"); }
public bool MakeMove(byte move) { move--; for (short i = 0; i < Gameboard.Rows.Count; i++) { if (Gameboard.Rows[i][move].ClaimedBy == null || (Gameboard.Mode == Gameboard.GameMode.Infinity && i == Gameboard.Rows.Count - 1)) { // In 'Infinity' mode, when a counter is placed on the highest row, a new row is added to the top of the board. // This code checks to see if a counter has been placed on the highest row and if so it adds a new row to the top of the board. if (Gameboard.Mode == Gameboard.GameMode.Infinity && i == Gameboard.Rows.Count - 1 && Gameboard.Rows[i][move].ClaimedBy != null) { Gameboard.RowDropper(); } Gameboard.Rows[i][move].ClaimCounter(this); Gameboard.History.Add((Gameboard.Rows[i][move], this)); Moves++; return(true); } } return(false); }
// * THE GAME * ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- private static int PlayGame(Player player1, Player player2) { // Used to decide who makes the first move. It is only used once in the next statement. Random random = new Random(); Player activePlayer = random.Next(2) == 0 ? player1 : player2; // These are used for declaring a winner and displaying information at the end of the game. Player winningPlayer = null; Player losingPlayer = null; // Setting up the game. Gameboard.Mode = GameEngine.ChooseGameMode(player1, player2); // Get game mode. GameEngine.ChooseNumberOfPlayers(player1, player2); // Declare and name players. Gameboard.SetUpBoard(); // Printing a last message to the user / users playing. Console.Clear(); CX.Print(player1.Name, player1.Colour); Console.Write(" vs "); CX.Print(player2.Name, player2.Colour); Console.WriteLine("!\nPress any key to play..."); Console.ReadKey(); Console.Clear(); // IN-GAME DateTime startingTime = DateTime.Now; // This will be used to show how long a game has been played for. while (true) { // Printing to the terminal who is playing and whose move it is. Console.Clear(); CX.Print(player1.Name, player1.Colour); Console.Write(" vs "); CX.Print(player2.Name, player2.Colour); Console.WriteLine($" | \u001b[4mConnect {Gameboard.VictoryNumber} to win!\u001b[0m"); Console.Write("\nIt is "); CX.Print(activePlayer.Name + "'s", activePlayer.Colour); Console.WriteLine(" turn...\n"); // Printing the game board with player instructions. Gameboard.PrintGameBoard(); // PLAYER INPUT if (!activePlayer.IsRobot) { byte playerChoice = CX.GetKey(limit: Gameboard.BoardWidth); // Access pause menu. if (playerChoice == 0) // Entering '0' accesses the pause menu. { byte pauseMenuValue = PauseMenu(player1, player2); if (pauseMenuValue == 0) { return(0); // Quit the game. } else if (pauseMenuValue == 6) { Gameboard.ResetBoard(true, player1, player2); } continue; } else if (playerChoice == 10 && Gameboard.History.Count > 0) { Gameboard.UndoMove(); // Undo Move... 'CX.GetKey()' Returns 10 when you enter [Z]. if (player2.IsRobot) { continue; } } else if (playerChoice < 10) { if (!activePlayer.MakeMove(playerChoice)) { continue; // Place a counter on the board. If invalid (false) try again. } } } else { activePlayer.ComputerMove(activePlayer == player1 ? player2 : player1); } // It makes no sense to check for victory if the player hasn't made enough moves to win. if (activePlayer.Moves >= Gameboard.VictoryNumber) { winningPlayer = Gameboard.CheckVictory(); losingPlayer = winningPlayer != null ? activePlayer == player1 ? player2 : player1 : null; } // This is the end game screen. This code only runs when a winner has been declared. if (winningPlayer != null) { Console.Clear(); while (true) { GameEngine.VictoryMessage(winningPlayer, losingPlayer, startingTime); byte answer = CX.GetKey(limit: 2); if (answer == 0) { Gameboard.MatchReplay(); } else if (answer == 1 || answer == 2) { Console.Clear(); Gameboard.ResetBoard(true, player1, player2); Gameboard.History.RemoveRange(0, Gameboard.History.Count); Console.WriteLine(answer == 1 ? "Press any key to continue..." : "Thank you for playing\nPress any key to continue..."); Console.ReadKey(); Console.Clear(); winningPlayer = null; losingPlayer = null; if (answer == 1) { break; } if (answer == 2) { return(0); } } Console.Clear(); } } activePlayer = activePlayer == player1 ? player2 : player1; if (player1.IsRobot && player2.IsRobot) { Thread.Sleep(500); } } }