/// <summary> /// Helper function: Displays the available moves. /// </summary> public void DisplayAvailableMoves() { WriteLine("Available moves:"); foreach (var m in this.AvailableMoves) { WriteLine("{0}. {1}", this.AvailableMoves.IndexOf(m) + 1, m.Label); } RSPGame.printMainMenuOption(); }
/// <summary> /// Displays the available players /// </summary> /// <param name="availablePlayersList">Available players list.</param> static void DisplayAvailablePlayers(List <Player> availablePlayersList) { WriteLine("Play againist:"); foreach (Player p in availablePlayersList) { WriteLine("{0}. {1}", availablePlayersList.IndexOf(p) + 1, p.PlayerName); // indexOf method performs a linear search; therefore, this method is an O(n) operation which I don't like, but's that ok for now } RSPGame.printMainMenuOption(); }
/// <summary> /// Helper function: Displays the match history. /// </summary> public void DisplayMatchHistory() { WriteLine("\nMatch move history:"); ForegroundColor = ConsoleColor.Yellow; WriteLine("Game \tPlayer 1 \tPlayer 2 \tWinner"); ResetColor(); int gameRound = 1; int CompareMovesSum = 0; foreach (var move in this.MovesHistory) { var label1 = this.AvailableMoves[move.Item1].Label; var label2 = this.AvailableMoves[move.Item2].Label; var result = RSPGame.CompareMoves(this.AvailableMoves[move.Item1], this.AvailableMoves[move.Item2]); CompareMovesSum += result; string gameWinner = "Tie"; if (result < 0) { gameWinner = "Player 1"; } else if (result > 0) { gameWinner = "Player 2"; } WriteLine("Game {0} \t{1,-10} \t{2,-10} \t{3}", gameRound++, label1, label2, gameWinner); } string winner; if (CompareMovesSum < 0) { winner = "Player 1"; } else if (CompareMovesSum > 0) { winner = "Player 2"; } else { winner = "Tie"; } ForegroundColor = ConsoleColor.Green; WriteLine("Match winner: \t{0}", winner); ResetColor(); }