• 猜拳扩展练习,三局两胜


                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();

  • 相关阅读:
    reflow和repaint
    移动端事件
    不支持冒泡的事件
    Gulp
    JAVAWEB项目Tomcat与内网穿透实现外网访问,可连接mysql数据库
    Echarts连接Mysql使用心得
    layui的date组件在弹窗里闪退的解决办法
    Layui的table标签使用记录
    Layui后台实现页面内部的iframe跳转
    第16周作业
  • 原文地址:https://www.cnblogs.com/fengsantianya/p/5456534.html
Copyright © 2020-2023  润新知