码迷,mamicode.com
首页 > 其他好文 > 详细

再练一遍猜拳

时间:2015-03-27 22:00:06      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

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

                  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 == 0 && y == 2 || x > y)
                {
                    Console.WriteLine(a+"获胜");
                }
                else if (x == y)
                {
                    Console.WriteLine( "平局");
               
                }
                else if (x == 2 && y == 0 || x < y)
                {

                    Console.WriteLine(b + "获胜");

                }

                else
                {
                    Console.WriteLine("出现错误");
               
                }
               
               
                Console.ReadLine();

             }

         }
    }
}

再练一遍猜拳

标签:

原文地址:http://www.cnblogs.com/lk-kk/p/4372856.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!