예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine(@"This is Chinese Drinking Game 5-10-15 
================================================");
            Console.WriteLine(@"
Gmae Rule : Two players. You & Computer.

The aim is to correctly predict the sum total of all the values from the hands displayed by the players.
To begin each round, players extend both hands and reveal either a closed fist (representing a value of 0) or open hand (value of 5) at the same time, much like you would in a game of rock, paper, scissors. 
But at the moment the hands are deployed, the player calls out their prediction of the total value of both hands, which could be 0, 5, or 10.
If the player guesses correctly, he gets to call again, at which point every player has the option of changing their hands.
If the player guesses incorrectly, the call goes to the next in line.
The game ends when one player manages two consecutive correct guesses. The player next in line is forced to drink as punishment.
The next round starts with the winner calling first.

Now you're playing with computer.");
            int      count   = 0;
            Random   random  = new Random();
            whofirst speaker = whofirst.player;

            speaker = (whofirst)random.Next(0, 2);



            while (count != 2)
            {
                while (speaker == whofirst.player && count != 2)
                {
                    Console.WriteLine(@"================================================

Player First 
玩家先開始

Please enter 3 digit for left hand, right hand and the guess of total number. 
For each hand, you can only enter 0 or 5, and total for 0, 5, 10, 15 or 20. 
請輸入三個數字分別代表 左拳 右拳 及 猜測雙方總和");
                    string input;

                    Console.WriteLine("");
                    Console.WriteLine("left hand / right hand / guess total");
                    input = Console.ReadLine();


                    while (!Checkinput(input))
                    {
                        Console.WriteLine("Please input correct range of number");
                        input = Console.ReadLine();
                    }

                    string[] input_array;
                    int[]    player = new int[3]; //要初始化

                    input_array = input.Split('/', ' ', ',');

                    for (int i = 0; i < 3; i++)
                    {
                        player[i] = int.Parse(input_array[i]);
                    }


                    Console.WriteLine("");
                    int[]  com = new int[2];
                    Random ran = new Random();

                    for (int i = 0; i < 2; i++)
                    {
                        int computer = ran.Next(0, 2);
                        computer = computer * 5;
                        com[i]   = computer;
                    }
                    Console.WriteLine($"Computer : {com[0]} , {com[1]}");

                    //判斷誰贏
                    if (com[0] + com[1] + player[0] + player[1] == player[2])
                    {
                        Console.WriteLine("");
                        Console.WriteLine("You scored");
                        count  += 1;
                        speaker = whofirst.player;
                    }
                    else
                    {
                        Console.WriteLine("");
                        Console.WriteLine("You failed. It's turn to computer");
                        count   = 0;
                        speaker = whofirst.computer;
                    }
                }
                //Computer first=============================================================
                while (speaker == whofirst.computer && count != 2)
                {
                    Console.WriteLine("");
                    Console.WriteLine("");
                    Console.WriteLine(@"
================================================

Computer first
現在是電腦先的回合

Please enter 3 digit for left hand, right hand. 
For each hand, you can only enter 0 or 5.
請輸入兩個數字0或5分別代表 左拳 右拳
  ");
                    string input = Console.ReadLine();
                    while (!Checkinput2(input))
                    {
                        Console.WriteLine("Please input correct range of number");
                        input = Console.ReadLine();
                    }

                    string[] input_array;
                    int[]    player = new int[2]; //要初始化

                    input_array = input.Split('/', ' ', ',');

                    for (int i = 0; i < 2; i++)
                    {
                        player[i] = int.Parse(input_array[i]);
                    }



                    int[]  com = new int[3];
                    Random ran = new Random();

                    for (int i = 0; i < 2; i++)
                    {
                        int computer = ran.Next(0, 2);
                        computer = computer * 5;
                        com[i]   = computer;
                    }

                    int computer3 = ran.Next(0, 2);
                    computer3 = (computer3 * 5) + com[0] + com[1];
                    com[2]    = computer3;
                    //Console.WriteLine($"{com[0]}{com[1]}{com[2]}");


                    Console.WriteLine($"computer : {com[0]} , {com[1]} , {com[2]}");
                    if (com[0] + com[1] + player[0] + player[1] == com[2])
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Computer scored. Last chance.");
                        count  += 1;
                        speaker = whofirst.computer;
                    }
                    else
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Computer failed. It's your turn");
                        count   = 0;
                        speaker = whofirst.player;
                    }
                }
            }
            if (speaker == whofirst.player)
            {
                Console.WriteLine(@"
================================================
You win ! ");
            }

            if (speaker == whofirst.computer)
            {
                Console.WriteLine(@"
================================================
You failed ! ");
            }
            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            int      count   = 0;
            Random   random  = new Random();
            whofirst speaker = whofirst.player;

            speaker = (whofirst)random.Next(0, 2);

            while (count != 2)
            {
                while (speaker == whofirst.player && count != 2)
                {
                    //玩家輸入

                    Console.WriteLine(@" 
================================================
現在你喊猜測結果 
請輸入三個數字分別代表 左拳 右拳 及 猜測雙方總和");
                    int[] player = new int[3];

                    for (int i = 0; i < 3; i++)
                    {
                        player[i] = int.Parse(Console.ReadLine());
                    }
                    Console.WriteLine("");
                    int[]  com = new int[2];
                    Random ran = new Random();

                    for (int i = 0; i < 2; i++)
                    {
                        int computer = ran.Next(0, 2);
                        computer = computer * 5;
                        com[i]   = computer;
                    }
                    Console.WriteLine($"{com[0]}\n{com[1]}");

                    if (com[0] + com[1] + player[0] + player[1] == player[2])
                    {
                        Console.WriteLine("You're Win");
                        count  += 1;
                        speaker = whofirst.player;
                    }
                    else
                    {
                        Console.WriteLine("You're Lose");
                        count   = 0;
                        speaker = whofirst.computer;
                    }
                }
                while (speaker == whofirst.computer && count != 2)
                {
                    Console.WriteLine("");
                    int[]  com = new int[3];
                    Random ran = new Random();

                    for (int i = 0; i < 2; i++)
                    {
                        int computer = ran.Next(0, 2);
                        computer = computer * 5;
                        com[i]   = computer;
                    }

                    int computer3 = ran.Next(0, 2);
                    computer3 = (computer3 * 5) + com[0] + com[1];
                    com[2]    = computer3;
                    //Console.WriteLine($"{com[0]}{com[1]}{com[2]}");

                    Console.WriteLine("請輸入兩個個數字分別代表 左拳 右拳");
                    int[] player = new int[2];

                    for (int i = 0; i < 2; i++)
                    {
                        player[i] = int.Parse(Console.ReadLine());
                    }

                    Console.WriteLine($"電腦左拳{com[0]}\n電腦右拳{com[1]}\n電腦猜測總和{com[2]}");
                    if (com[0] + com[1] + player[0] + player[1] == com[2])
                    {
                        Console.WriteLine("電腦猜對 You're lose 電腦繼續開始");
                        count  += 1;
                        speaker = whofirst.computer;
                    }
                    else
                    {
                        Console.WriteLine("電腦猜錯 You're Win 你繼續開始");
                        count   = 0;
                        speaker = whofirst.player;
                    }
                }
            }
            if (speaker == whofirst.player)
            {
                Console.WriteLine(@"
================================================
Winner is player 在你的回合你連贏了兩局");
            }

            if (speaker == whofirst.computer)
            {
                Console.WriteLine(@"
================================================
Winner is computer 在電腦的回合你連輸了兩局");
            }
            Console.ReadKey();
        }