public Listof_Results Play(Listof_Choices player1, Listof_Choices player2 = Listof_Choices.random) { if (player2 == Listof_Choices.random) { player2 = RandomChoice(); } int choices = Enum.GetValues(typeof(Listof_Choices)).Length; if ((int)player1 >= 0 && (int)player1 < choices && (int)player2 >= 0 && (int)player2 < choices) { if (player1 == player2) { return(Listof_Results.tie); } if (player1 == Listof_Choices.rock && player2 != Listof_Choices.paper) { return(Listof_Results.player1); } if (player1 == Listof_Choices.paper && player2 != Listof_Choices.scissors) { return(Listof_Results.player1); } if (player1 == Listof_Choices.scissors && player2 != Listof_Choices.rock) { return(Listof_Results.player1); } return(Listof_Results.player2); } else { return(Listof_Results.badChoices); } }
public void UIGame() { bool endGame = false; RockPaperScissors myGame = new RockPaperScissors(); while (endGame == false) { Console.WriteLine("Do you want to play 1 or 2 player? Enter 1 or 2"); ConsoleKeyInfo choice = Console.ReadKey(true); if (choice.Key == ConsoleKey.D1) { Console.WriteLine("1 Player🧟♂️ Game!"); Console.WriteLine("Player: Enter 0 for rock, 1 for paper or 2 for scissors"); ConsoleKeyInfo player = Console.ReadKey(true); Listof_Choices playerNumber = (Listof_Choices)Char.GetNumericValue(player.KeyChar); Listof_Results result = myGame.Play(playerNumber); Console.WriteLine("{0} Wins! 🏄🏽♂️", result); break; } if (choice.Key == ConsoleKey.D2) { Console.WriteLine("2 Player🧟♂️ Game!"); Console.WriteLine("Player 1: Enter 0 for rock, 1 for paper or 2 for scissors"); ConsoleKeyInfo player1 = Console.ReadKey(true); Listof_Choices player1Number = (Listof_Choices)Char.GetNumericValue(player1.KeyChar); Console.WriteLine("Player 2: Enter 0 for rock, 1 for paper or 2 for scissors"); ConsoleKeyInfo player2 = Console.ReadKey(true); Listof_Choices player2Number = (Listof_Choices)Char.GetNumericValue(player2.KeyChar); Listof_Results result = myGame.Play(player1Number, player2Number); Console.WriteLine("{0} Wins! 🏄🏽♂️", result); Console.WriteLine("🏄🏽"); break; } Console.WriteLine("Opps i said..."); } }