static void Main(string[] args) { Console.WriteLine("Welcome to the game of Rock Paper Scissors"); Console.WriteLine("Please Enter Your Name: "); string input = Console.ReadLine(); HumanPlayer user = new HumanPlayer(input); Player opponent = SelectOpponent(); bool repeat = true; while (repeat) { Roshambo userPick = user.GenerateRoshambo(); Roshambo oppPick = opponent.GenerateRoshambo(); string result = GetWinner(userPick, oppPick); Console.WriteLine($"{user._Name}: {userPick}\n{opponent._Name}: {oppPick}\n{result}"); Console.WriteLine("Would you like to keep playing? (Y/N):"); repeat = Validator.DoAgain(); } }
public void BeginRoshambo() { UserPlayer user = new UserPlayer(); user.Name = Program.GetUserInput("Please enter your name."); bool goAgain = true; while (goAgain) { Console.Clear(); Player opponent = ChooseOpponent(); user.Roshambo = user.GenerateRoshambo(); opponent.GenerateRoshambo(); Console.WriteLine($"{opponent.ReturnName()} has thrown {opponent.GenerateRoshambo()}"); Console.WriteLine($"{user.Name} has thrown {user.Roshambo}"); if (user.Winner(opponent)) { Console.WriteLine($"{user.ReturnName()} is the winner!"); } else if (opponent.Winner(user)) { Console.WriteLine($"{opponent.ReturnName()} is the winner!"); } else { Console.WriteLine("Tie! Nobody wins!"); } string quitChoice; Console.WriteLine($"You have a total of {user.Wins()} wins, {user.Losses()} losses, and {user.Ties()} ties."); Console.WriteLine("Enter (Q)uit to exit, or any other key to run again"); quitChoice = Console.ReadLine().Trim(); if (quitChoice.ToLower() == "q" || quitChoice.ToLower() == "quit") { goAgain = false; } } }
static void Main(string[] args) { Console.WriteLine("Welcome to Rock Paper Scissors!!!\n"); Player user = new HumanPlayer(); user.Name = Validation.GetName(); Player opponent = Validation.GetOpponent(); bool continueFlag = true; while (continueFlag) { user.RPS = user.GenerateRoshambo(); opponent.RPS = opponent.GenerateRoshambo(); Validation.RPSOutcome(user, opponent, user.Name, opponent.Name); Console.Write("Play again? (y/n): "); Validation.YesOrNo(Console.ReadLine(), ref continueFlag); } Console.WriteLine($"\nOK BYEEEEEEEEEEEEE!!!!!!\n"); }
public static void Play(UserPlayer userPlayer, Player choosenPlayer) { int i = 0; //int rockyWins = 0; //int randomWins = 0; //int ties = 0; while (i < 10)// this means we will run it 10 times. { Console.WriteLine("Pick Rock, Paper, Scissors"); string rocky = choosenPlayer.GenerateRoshambo(); string random = userPlayer.GenerateRoshambo(); if (rocky == "Rock" && random == "Rock") { Console.WriteLine($"{userPlayer.Name} selected {random}"); Console.WriteLine(($"{choosenPlayer.Name} selected {rocky}")); Console.WriteLine("Tie"); } else if (rocky == "Rock" && random == "Paper") { Console.WriteLine($"{userPlayer.Name} selected {random}"); Console.WriteLine(($"{choosenPlayer.Name} selected {rocky}")); Console.WriteLine($"{choosenPlayer.Name} Wins!"); } else if (rocky == "Rock" && random == "Scissors") { Console.WriteLine($"{userPlayer.Name} selected {random}"); Console.WriteLine(($"{choosenPlayer.Name} selected {rocky}")); Console.WriteLine($"{choosenPlayer.Name} Wins!"); } else if (rocky == "Rock" && random == "Paper") { Console.WriteLine($"{userPlayer.Name} selected {random}"); Console.WriteLine(($"{choosenPlayer.Name} selected {rocky}")); Console.WriteLine($"{userPlayer.Name} Wins!"); } i++; // this is to get out of the while loop } }
// Generate RPS values for each player and determine winner. public void FindWinner(Player one, Player two) { Player isWinner = null; // Generate RPS values string player1Throw = one.GenerateRoshambo(); string player2Throw = two.GenerateRoshambo(); if (player1Throw == player2Throw) { PrintResult(isWinner, player1Throw, player2Throw); } else { if (player1Throw == "rock") { if (player2Throw == "scissors") { isWinner = one; Player1Wins += 1; PrintResult(isWinner, player1Throw, player2Throw); } else { isWinner = two; Player2Wins += 1; PrintResult(isWinner, player1Throw, player2Throw); } } else if (player1Throw == "paper") { if (player2Throw == "rock") { isWinner = one; Player1Wins += 1; PrintResult(isWinner, player1Throw, player2Throw); } else { isWinner = two; Player2Wins += 1; PrintResult(isWinner, player1Throw, player2Throw); } } else if (player1Throw == "scissors") { if (player2Throw == "paper") { isWinner = one; Player1Wins += 1; PrintResult(isWinner, player1Throw, player2Throw); } else { isWinner = two; Player2Wins += 1; PrintResult(isWinner, player1Throw, player2Throw); } } } }