码迷,mamicode.com
首页 > Windows程序 > 详细

C#处理猜拳问题(非窗体)

时间:2016-07-03 23:26:46      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:

//猜拳,5局3胜,要求使用公用变量。

namespace 结构体复习_公用变量

{

    class Program

    {public int rz=0;

        public int dz = 0;

 

        public string bj(int a , int b)

        {

            int d = a - b;

            if (d==-2||d==1)

            {

                return "人";

            }

            else if (d==2||d==-1)

            {

                return "电脑";

            }

            else

            {

                return "和";

            }

        }

        static void Main(string[] args)

        {Random sj = new Random();

            Program zdy=new Program();

            while (zdy.rz < 3 && zdy.dz < 3)

            {

                Console.WriteLine("请输入剪刀石头布的数字编码(1为剪刀,2为石头,3为布):");

                int a = int.Parse(Console.ReadLine());

                int b = sj.Next(1,4);

                string jg = zdy.bj(a, b);

                switch (jg)

                {

                    case "人":

                        zdy.rz++;

                        Console.WriteLine("本局你获胜");

                        break;

                    case "电脑":

                        zdy.dz++;

                        Console.WriteLine("本局电脑获胜");

                        break;

                    case "和":

                        Console.WriteLine("本局平局");

                        break;

                }

               

            }

            if (zdy.rz > zdy.dz)

            {

                Console.WriteLine("你赢了");

            }

            else

            {

                Console.WriteLine("你输了");

 

            }

            Console.ReadLine();

       }

    }

}

 

C#处理猜拳问题(非窗体)

标签:

原文地址:http://www.cnblogs.com/H2921306656/p/5638994.html

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