コード例 #1
0
ファイル: Program.cs プロジェクト: tkbcode/RockPaperScissors
        static void Main(string[] args)
        {
            Fist           MyFist   = new Fist();
            Fist           YourFist = new Fist();
            ConsoleKeyInfo Keypress;
            int            GameCount = 1, WinCount = 0, LossCount = 0, TieCount = 0;

            Console.WriteLine("ROCK, PAPER, SCISSORS");
            Console.WriteLine("=====================");
            do
            {
                Console.WriteLine("Press R to throw Rock, P for Paper, S for Scissors, ");
                Console.WriteLine("and any other key to throw randomly.  ");
                Console.WriteLine("Press Escape to exit the program.");

                Keypress = Console.ReadKey(true);
                MyFist.Throw();

                switch (Keypress.Key)
                {
                case ConsoleKey.R:
                    YourFist.SetState(FistType.rock);
                    break;

                case ConsoleKey.P:
                    YourFist.SetState(FistType.paper);
                    break;

                case ConsoleKey.S:
                    YourFist.SetState(FistType.scissors);
                    break;

                default:
                    YourFist.Throw();
                    break;
                }

                Console.WriteLine();
                Console.WriteLine("Game " + GameCount++);
                Console.WriteLine("Your fist threw " + YourFist.ToString());
                Console.WriteLine("My fist threw " + MyFist.ToString());

                if (MyFist > YourFist)
                {
                    Console.WriteLine("I win!");
                    WinCount++;
                }
                else if (MyFist < YourFist)
                {
                    Console.WriteLine("You win!");
                    LossCount++;
                }
                else
                {
                    Console.WriteLine("It's a tie!");
                    TieCount++;
                }
                Console.WriteLine("Wins: {0}, Losses:  {1}, Ties:  {2}", LossCount, WinCount, TieCount);
                Console.WriteLine();
            } while (Keypress.Key != ConsoleKey.Escape);
        }