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

剪刀石头布编辑

时间:2015-03-01 22:10:40      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

Random r = new Random();    

         string x, y;     

        int a = r.Next(0,3);        

         int b = r.Next(0, 3);            

         switch(a)            

{  

            case 0: 

                    x="剪刀";       

              break;              

             case 1:               

                    x="石头";            

              break;           

              case 2:    

                    x="布";           

               break;        

            default:           

          x="OY";            

         break;

                   }  

           switch (b)  

           {            

              case 0:         

            y = "剪刀";         

            break;         

            case 1:          

           y = "石头";            

         break;         

        case 2:           

          y = "布";            

         break;                 

       default:          

          y="OY";            

         break;

            }          

   Console.WriteLine("x出的是"+x);      

    Console.WriteLine("y出的是"+y);       

      if (a==b)      

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

     else if (a > b)       

     {                 if (a == 2 && b == 0)          

      {                     Console.WriteLine("y胜利");                 }

   else          

       {                     Console.WriteLine("x胜利");                 }        

     }      

       else if (b > a)      

       {        

         if (a == 0 && b == 2)          

       {                     Console.WriteLine("x胜利");                 }          

       else            

     {                 Console.WriteLine("y胜利");                 }             }

剪刀石头布编辑

标签:

原文地址:http://www.cnblogs.com/shitouge/p/4307556.html

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