/// <summary> /// Sets the information of the Opponent. /// </summary> private void SetupOpponent() { string str = string.Empty; // Loop asking if opponont is human or computer do { Display.MenuSelectOpponent(_player1.Name, _player1.PlayerColor); str = Console.ReadLine().Trim().ToUpper(); if (str.Length == 0) { str = "X"; } } while (str[0] != 'H' && str[0] != 'C'); bool isHuman = str[0] == 'H' ? true : false; // If human, loop asking for a valid name (similar to player 1) if (isHuman) { do { Console.WriteLine("Enter Name of Player 2: "); str = Console.ReadLine().Trim(); if (str.ToUpper() == _player1.Name.ToUpper()) { Console.WriteLine("Sorry, but {0} is already taken!", str); } } while (str.Length == 0 || str.ToUpper() == _player1.Name.ToUpper()); _player2 = new PlayerHuman(str); } else { // Computer opponent, ask for difficulty do { Display.MenuSelectDifficulty(); str = Console.ReadLine().Trim(); if (str.Length == 0) { str = "x"; } } while (str[0] != '0' && str[0] != '1' && str[0] != '2' && str[0] != '3'); ComputerDifficulty level = ComputerDifficulty.Random; if (str[0] == '1') { level = ComputerDifficulty.Easy; } else if (str[0] == '2') { level = ComputerDifficulty.Normal; } else if (str[0] == '3') { level = ComputerDifficulty.Advanced; } _player2 = new PlayerComputer("Computer(" + level.ToString() + ")", level); } // Supply the rest of the information for all cases. _player2.PlayerColor = ConsoleColor.Yellow; _player2.Token = -1; }
/// <summary> /// Sets the information of the Opponent. /// </summary> private void SetupOpponent() { string str; // Ask if opponent is human or computer. Check if name is not whitespace. do { Display.MenuSelectOpponent(_player1.Name, _player1.PlayerColor); str = Console.ReadLine().Trim().ToUpper(); if (str.Length == 0) { str = "X"; } }while (str[0] != 'H' && str[0] != 'C'); Console.WriteLine(); bool isHuman = str[0] == 'H' ? true : false; if (isHuman) { // If human, ask opponent name and check if not whitespace. do { Console.Write("Enter name of Player 2: "); str = Console.ReadLine().Trim(); // To avoid confusion, player names must be different. if (str.ToUpper() == _player1.Name.ToUpper()) { Console.WriteLine("Sorry, but {0} is already taken!", str); } }while (str.Length == 0 || str.ToUpper() == _player1.Name.ToUpper()); _player2 = new PlayerHuman(str); } else { // If computer, ask difficulty of opponent. do { Display.MenuSelectDifficulty(); str = Console.ReadLine().Trim().ToUpper(); if (str.Length == 0) { str = "X"; } }while (str[0] != '0' && str[0] != '1' && str[0] != '2' && str[0] != '3'); ComputerDifficulty level = ComputerDifficulty.Random; if (str[0] == '1') { level = ComputerDifficulty.Easy; } else if (str[0] == '2') { level = ComputerDifficulty.Normal; } else if (str[0] == '3') { level = ComputerDifficulty.Advanced; } _player2 = new PlayerComputer("Computer(" + level.ToString() + ")", level); } _player2.PlayerColor = ConsoleColor.Yellow; _player2.Token = -1; }