Mini console program: rock paper scissors

dnq6 Oct 25, 2013

  1. dnq6

    dnq6 Daniel
    0/47

    Joined:
    Sep 24, 2012
    Messages:
    460
    Likes Received:
    91
    Trophy Points:
    0
    Gender:
    Male
    Location:
    Trippa Snippa
    Console:
    Xbox
    sup, so just started to code and made this little console thing ;) If any of you wanna help me learn any of the c languages i shall love marry you, and give you wine and women :p any way heres the code:


    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace RockPaperScissors
    {
    class Program
    {
    static void Main(string[] args)
    {
    Console.Title = "Rock Paper Scissors";
    string userChoice = "**&&**";
    int computerChoice, loseCount = 0, tieCount = 0;
    bool QUIT = false;
    double winPercent = 100.0, gameCount = 0.0, winCount = 0.0;
    Random computer = new Random();
    Console.Clear();
    Console.WriteLine("ROCK PAPER SCISSORS");

    do
    {
    Console.Write("Enter choice, or enter QUIT to quit: ");
    userChoice = Convert.ToString(Console.ReadLine());
    ++gameCount;
    if (userChoice.ToUpper() == "QUIT")
    {
    break;
    }
    computerChoice = computer.Next(1, 4); // 1 is Rock, 2 is Paper, 3 is Scissors

    switch (userChoice.ToUpper())
    {
    case "ROCK":
    if (computerChoice == 1)
    {
    Console.WriteLine("You chose {0} and the computer chose Rock. It was a tie!", userChoice);
    ++tieCount;
    }
    else if (computerChoice == 2)
    {
    Console.WriteLine("You chose {0} and the computer chose Paper. You win!", userChoice);
    ++winCount;
    }
    else if (computerChoice == 3)
    {
    Console.WriteLine("You chose {0} and the computer chose Scissors. You lose!", userChoice);
    ++loseCount;
    }
    break;
    case "PAPER":
    if (computerChoice == 1)
    {
    Console.WriteLine("You chose {0} and the computer chose Rock. You win!", userChoice);
    ++winCount;
    }
    else if (computerChoice == 2)
    {
    Console.WriteLine("You chose {0} and the computer chose Paper. It was a tie!", userChoice);
    ++tieCount;
    }
    else
    {
    Console.WriteLine("You chose {0} and the computer chose Scissors. You lose!", userChoice);
    ++loseCount;
    }
    break;
    case "SCISSORS":
    if (computerChoice == 1)
    {
    Console.WriteLine("You chose {0} and the computer chose Rock. You lose!", userChoice);
    ++loseCount;
    }
    else if (computerChoice == 2)
    {
    Console.WriteLine("You chose {0} and the computer chose Paper. You win!", userChoice);
    ++winCount;
    }
    else
    {
    Console.WriteLine("You chose {0} and the computer chose Scissors. It was a tie!", userChoice);
    ++tieCount;
    }
    break;
    default:
    {
    break;
    }

    }
    } while (QUIT == false);

    if (gameCount > 1)
    {
    Console.Clear();
    Console.WriteLine("Giving up?");
    Console.WriteLine("{0} game(s) played. You won {1} game(s). You lost {2} game(s). {3} game(s) were a tie.", gameCount, winCount, loseCount, tieCount);
    winPercent = (winCount / gameCount) * 100;
    Console.WriteLine("You won {0:f2}% of the games you played.", winPercent);
    Console.WriteLine("Thanks for playing!");
    Console.ReadKey();
    }
    }
    }
    }
     

Share This Page

Close