public static Player GetOpponent() //Gets opponent and creates the object based off of name chosen { Console.Write("Who would you like to play against? (Phil or Adom): "); string userChoice = Console.ReadLine().ToLower(); while (userChoice != "phil" && userChoice != "adom") //Makes sure input is valid { Console.Write("Please enter a valid opponent (Phil or Adom): "); userChoice = Console.ReadLine().ToLower(); } if (userChoice == "phil") { Player Phil = new RockMan(); ////Make a Phil! Phil.Name = "Phil"; Console.WriteLine(); return(Phil); } else { Player Adom = new RandomMan(); //Make an Adom! Adom.Name = "Adom"; Console.WriteLine(); return(Adom); } }
static void Main(string[] args) { Player dopey = new Dopey(); Player random = new RandomMan(); Player chosen = null; int userNum = Validator.CheckRange(Validator.GetUserInput("Play against\n1. Dopey\n2. Random Man"), 1, 2); if (userNum == 1) { chosen = dopey; } if (userNum == 2) { chosen = random; } Console.WriteLine(RoshamboApp.Play(chosen, "Ryan")); Console.WriteLine($"{chosen.Name} throws {chosen.RPS}"); }