public enum Action { Rock, Paper, Scissor };
public enum Result { Tie, PlayerWon, ComputerWon }
public static Random rand;
public static void Main() {
Console.WriteLine("How many rounds would you like to play?");
int rounds = GetDesiredRounds();
for(var round = 1; round <= rounds; round++) {
Console.WriteLine("Round {0} Begins", round);
Console.WriteLine("Which hand do you choose(Rock, Paper, Scissor)? ");
var playerAction = GetPlayerAction();
Console.WriteLine("You picked: {0}", playerAction.ToString());
var computerAction = GetComputerAction();
Console.WriteLine("Your opponent picked: {0}", computerAction.ToString());
switch(CalculateResult(playerAction, computerAction)) {
Console.WriteLine("You won the round! You gained a point.");
Console.WriteLine("Computer won the round! Computer gained a point.");
Console.WriteLine("Round tied. You and the computer gained a point.");
Console.WriteLine("Results - Player {0}, Computer {1}", playerPoints, computerPoints);
if (playerPoints == computerPoints) {
Console.WriteLine("Tie Game");
bool isPlayerWinner = playerPoints > computerPoints;
Console.WriteLine("{0} won the game!", isPlayerWinner ? "Player" : "Computer");
public static int GetDesiredRounds() {
var input = Console.ReadLine();
if(Int32.TryParse(input, out result)) {
Console.WriteLine("Invalid input. Please input a number.");
public static Action GetPlayerAction() {
var input = Console.ReadLine();
if(Action.TryParse(input, true, out result)) {
Console.WriteLine("Invalid action {0}. Please input 'Rock', 'Paper' or 'Scissors'.", input);
public static Action GetComputerAction() {
return (Action)rand.Next((int)Action.Rock, (int)Action.Scissor + 1);
public static Result CalculateResult(Action p, Action c) {
case Action.Rock: return Result.Tie;
case Action.Paper: return Result.ComputerWon;
case Action.Scissor: return Result.PlayerWon;
case Action.Rock: return Result.PlayerWon;
case Action.Paper: return Result.Tie;
case Action.Scissor: return Result.ComputerWon;
case Action.Rock: return Result.ComputerWon;
case Action.Paper: return Result.PlayerWon;
case Action.Scissor: return Result.Tie;
throw new Exception(string.Format("Unhandled action pair occured: {0}, {1}", p, c));