public static Player SelectOpponent() { int opponentNum; while (true) { Console.WriteLine("\nWould you like to play against RoRo or Randy? (1 or 2)?"); bool success = int.TryParse(Console.ReadLine().ToUpper(), out opponentNum); if (!success) { Console.WriteLine("Please enter 1 or 2"); } else if (opponentNum > 2 || opponentNum < 1) { Console.WriteLine("1 or 2"); } else { break; } } if (opponentNum == 1) { Player opponent = new RockPlayer("RoRo"); return(opponent); } else { Player opponent2 = new RandPlayer("Randy"); return(opponent2); } }
static void Main(string[] args) { Player randomPlayer = new RandomPlayer("Random Balboa"); //randomPlayer.Name = "Random Balboa"; Player rockPlayer = new RockPlayer("Rocky Balboa"); //rockPlayer.Name = "Rockey Balboa"; UserPlayer userPlayer = new UserPlayer(); Console.Write("Enter your Name"); // user input userPlayer.Name = Console.ReadLine();; Console.WriteLine("Select your rockPlayer!"); Console.WriteLine("1). Rocky Balboa"); Console.WriteLine("2). Random Balboa"); string userInput = Console.ReadLine(); switch (userInput) { case "1": Play(userPlayer, new RockPlayer("Rocky Balboa")); break; case "2": Play(userPlayer, new RandomPlayer("Random Balboa")); break; } }