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

猜拳扩展练习,三局两胜

时间:2016-05-03 22:13:51      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

            int count1 = 0, count2 = 0;//设定赢的次数,输的次数

            for (; ; )

            {

                //1、提示用户出拳

                Console.Write("请出拳(石头0,剪子1,布2):");

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

                //2、电脑随机生成

                Random r = new Random();

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

                //3、判断输赢

                //  用户赢:0-1=-1 1-2=-1 2-0=2

                //用户输了:0-2=-2 1-0=1  2-1=1

                //平局     0

                int jg = yh-dn;

                if (yh < 0 || yh > 2)

                {

                    Console.WriteLine("输入有误!");

                }

                else

                {

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

                    {

                        Console.WriteLine("您赢了!");

                        count1++;

                        if (count1 == 2)

                        {

                            Console.WriteLine("您最终赢了!"); break;//赢两次结果,跳出循环

                        }

 

                    }

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

                    {

                        Console.WriteLine("您输了!");

                        count2++;

                        if (count2 == 2)

                        {

                            Console.WriteLine("您最终输了!"); break;

                        }

                    }

 

                    else if (jg == 0)

                    {

                        Console.WriteLine("平局!");

                    }

                }

            }

            Console.ReadLine();

猜拳扩展练习,三局两胜

标签:

原文地址:http://www.cnblogs.com/fengsantianya/p/5456534.html

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