再练一遍猜拳

namespace 再练一遍猜拳2
{
    class Program
    {
        static void Main(string[] args)

//首先先随机生成三个数,然后将0,1,2变成剪刀石头布,利用switch case达到,在比较的时候注意当x为0,y为2的时候,出x的获胜。即先判断这一句   x == 0 && y == 2 ,这句成立直接输出,因为后面的是||或者的意思;y获胜也一样,即先判断x == 2 && y == 0这一句,如果不成立再判断下一句。

{
            Console.ForegroundColor = ConsoleColor.Green;            
            while (true)
            {
                int x, y; string a,b;
                Random r = new Random();
                x = r.Next(0, 3);
                y = r.Next(0, 3);
                switch (x)
                {
                    case 0:
                        a = "剪刀";
                        break;
                    case 1:
                        a = "石头";
                        break;
                    case 2:
                        a = "布";
                        break;
                    default:
                        a = "傻叉";
                        break;
                }
                switch (y)
                {
                    case 0:
                        b = "剪刀";
                        break;
                    case 1:
                        b = "石头";
                        break;
                    case 2:
                        b = "布";
                        break;
                    default:
                        b = "傻叉";
                        break;
                }
                Console.WriteLine(a);
                Console.WriteLine(b);
                if (x > y)
                {
                    if (x== 2 && y == 0)
                    {
                        Console.WriteLine("出" + b + "的获胜");
                    }
                    else
                    {
                        Console.WriteLine("出" + a + "的获胜");
                    }
                }
                else if (x < y)
                {
                    if (x == 0 && y == 2)
                    {
                        Console.WriteLine("出" + a + "的获胜");
                    }
                    else
                    {
                        Console.WriteLine("出" + b + "的获胜");
                    }

                }
                else
                {
                    Console.WriteLine("平局");
                }
                Console.ReadLine();
            }
        }
    }
}


             

posted @ 2015-03-27 21:07  XCml  阅读(237)  评论(0编辑  收藏  举报