/* Mark Hesser Oct 26, 2017 RPSLV Console App Rock Paper Scissors Lizard Spock */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RPSLS_Console { class Program { static void Main(string[] args) { Console.Clear(); Console.Title = "RPSLV"; //Declarations int computerChoice, playerChoice = 0; Random randNumber = new Random(); string computerResult = "", gameResult = "", playerResult = ""; bool Quit = false, isPlayable = false, choiceKeyListener = true, quitKeyListener = true; int playerWins = 0, computerWins = 0, hasPlayed = 0; //Keeps Track of Wins int playerWinCase = 0, playerCase = 0; while (!Quit) //Play the game { Console.Clear(); Console.WriteLine("Welcome to RPSLV!"); Console.WriteLine(""); if (hasPlayed > 0) { Console.WriteLine(computerResult); Console.WriteLine(""); Console.WriteLine("{0}{1}", gameResult, playerResult); Console.WriteLine(""); //Displays current win totals Console.WriteLine("Player {0}, Computer {1}", playerWins, computerWins); Console.WriteLine(""); } Console.WriteLine("Press the Key that Corresponds to your Choice, Press (Q) to Quit"); Console.Write("Rock (R), Paper (P), Scissors (S), Lizard (L), or Spock (V)?: "); isPlayable = false; while (!isPlayable) //Determine if the Choice is Valid, Loop if not { choiceKeyListener = true; while (choiceKeyListener) { ConsoleKeyInfo playerChoiceInput = Console.ReadKey(); //Listens for Key if (playerChoiceInput.Key == ConsoleKey.R) { playerChoice = 1; isPlayable = true; choiceKeyListener = false; } else if (playerChoiceInput.Key == ConsoleKey.P) { playerChoice = 2; isPlayable = true; choiceKeyListener = false; } else if (playerChoiceInput.Key == ConsoleKey.S) { playerChoice = 3; isPlayable = true; choiceKeyListener = false; } else if (playerChoiceInput.Key == ConsoleKey.L) { playerChoice = 4; isPlayable = true; choiceKeyListener = false; } else if (playerChoiceInput.Key == ConsoleKey.V) { playerChoice = 5; isPlayable = true; choiceKeyListener = false; } else if (playerChoiceInput.Key == ConsoleKey.Q) { Console.WriteLine(""); Console.Write("Current Scores will be lost, are you sure you want to Quit? (Y/n): "); quitKeyListener = true; while (quitKeyListener) { hasPlayed--; ConsoleKeyInfo kb2 = Console.ReadKey(); //Listens for Key if (kb2.Key == ConsoleKey.N) // N Quits the Program { Quit = false; /*Keeps the Game Going*/ quitKeyListener = false; /*Must set to False to exit loop*/ choiceKeyListener = false; isPlayable = false; Console.Clear(); Console.WriteLine("Welcome to RPSLV!"); Console.WriteLine(""); if (hasPlayed > 0) { Console.WriteLine(computerResult); Console.WriteLine(""); Console.WriteLine(gameResult, playerResult); Console.WriteLine(""); //Displays current win totals Console.WriteLine("Player {0}, Computer {1}", playerWins, computerWins); Console.WriteLine(""); } Console.WriteLine("Press the Key that Corresponds to your Choice, Press (Q) to Quit"); Console.Write("Rock (R), Paper (P), Scissors (S), Lizard (L), or Spock (V)?: "); //Console.WriteLine("no"); //Debug N Key } else if (kb2.Key == ConsoleKey.Y) { Quit = true; /*Quits the program*/ quitKeyListener = false; /*Must set to False to exit loop*/ choiceKeyListener = false; isPlayable = true; //Console.WriteLine("yes"); //Debug Y Key } else { //Still Quits Console.WriteLine(""); Console.WriteLine("You didn't hit Y or N."); Console.WriteLine("I'm going to assume you said No."); Console.WriteLine("Press Any Key to Quit"); Console.ReadKey(); Quit = true; quitKeyListener = false; choiceKeyListener = false; isPlayable = true; } } } else { //If you are here, you really don't understand how this game works, do you? Console.Clear(); Console.WriteLine("That is not a valid Choice, Please Try Again"); Console.WriteLine(""); Console.WriteLine("Press the Key that Corresponds to your Choice, Press (Q) to Quit"); Console.Write("Rock (R), Paper (P), Scissors (S), Lizard (L), or Spock (V)?: "); } } } Console.WriteLine(""); computerChoice = randNumber.Next(5) + 1; //computer chooses choice after player to avoid cheating! hasPlayed++; //Switch that determines the result of the Game switch (computerChoice) { case 1: computerResult = "The Computer chose Rock"; switch (playerChoice) { case 1: playerCase = 0; playerWinCase = 0; break; case 2: playerCase = 2; playerWinCase = 1; break; case 3: playerCase = 10; playerWinCase = 2; break; case 4: playerCase = 3; playerWinCase = 2; break; case 5: playerCase = 9; playerWinCase = 1; break; default: break; } break; case 2: computerResult = "The Computer chose Paper"; switch (playerChoice) { case 1: playerCase = 2; playerWinCase = 2; break; case 2: playerCase = 0; playerWinCase = 0; break; case 3: playerCase = 1; playerWinCase = 1; break; case 4: playerCase = 7; playerWinCase = 1; break; case 5: playerCase = 8; playerWinCase = 2; break; default: break; } break; case 3: computerResult = "The Computer chose Scissors"; switch (playerChoice) { case 1: playerCase = 10; playerWinCase = 1; break; case 2: playerCase = 1; playerWinCase = 2; break; case 3: playerCase = 0; playerWinCase = 0; break; case 4: playerCase = 6; playerWinCase = 2; break; case 5: playerCase = 5; playerWinCase = 1; break; default: break; } break; case 4: computerResult = "The Computer chose Lizard"; switch (playerChoice) { case 1: playerCase = 3; playerWinCase = 1; break; case 2: playerCase = 7; playerWinCase = 2; break; case 3: playerCase = 6; playerWinCase = 1; break; case 4: playerCase = 0; playerWinCase = 0; break; case 5: playerCase = 4; playerWinCase = 2; break; default: break; } break; case 5: computerResult = "The Computer chose Spock"; switch (playerChoice) { case 1: playerCase = 9; playerWinCase = 2; break; case 2: playerCase = 8; playerWinCase = 1; break; case 3: playerCase = 5; playerWinCase = 2; break; case 4: playerCase = 4; playerWinCase = 1; break; case 5: playerCase = 0; playerWinCase = 0; break; default: break; } break; default: break; } switch (playerCase) { case 1: gameResult = ("Scissors cut Paper, "); break; case 2: gameResult = ("Paper covers Rock, "); break; case 3: gameResult = ("Rock crushes Lizard, "); break; case 4: gameResult = ("Lizard poisons Spock, "); break; case 5: gameResult = ("Spock smashes Scissors, "); break; case 6: gameResult = ("Scissors decapitate Lizard, "); break; case 7: gameResult = ("Lizard eats Paper, "); break; case 8: gameResult = ("Paper disproves Spock, "); break; case 9: gameResult = ("Spock vaporizes Rock, "); break; case 10: gameResult = ("Rock crushes Scissors, "); break; default: gameResult = ("It's a Tie! "); break; } switch (playerWinCase) { case 1: playerResult = ("You Win!"); playerWins++; break; case 2: playerResult = ("You Lose!"); computerWins++; break; default: playerResult = ("Nobody Wins..."); break; } } } } } |