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

对战游戏 不完全

时间:2017-11-07 23:54:55      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:攻击   ons   输入   amp   等于   输出   while   设定   console   

 #region 创建角色   
            JueSe JS1 = new JueSe();  //创建一个角色1.
            Console.Write("请输入第一个角色的姓名:");//在前端让用户输入字符.
            JS1.XingMing = Console.ReadLine();//输入的内容赋值给角色1的姓名.
            JS1.GongJi = 100;//设定角色1攻击是100
            JS1.ShengMing = 1000;//设定角色1生命时1000
            JueSe JS2 = new JueSe();//同上
            Console.Write("请输入第二个角色的姓名:");
            JS2.XingMing = Console.ReadLine();
            JS2.GongJi = 100;
            JS2.ShengMing = 1000;
            #endregion
        

         #region 对战部分
        
            while (true)//死循环
            {
                JS2.ShengMing = JS2.ShengMing - JS1.GongJi;
                Console.WriteLine(JS1.XingMing + "攻击" + JS2.XingMing + ",造成了" + JS1.GongJi + "点伤害," + JS2.XingMing + "还剩余" + JS2.ShengMing + "点生命.");
                System.Threading.Thread.Sleep(1000);
                //输出过程尽量不要再输出过程中使用运算符号

                JS1.ShengMing = JS1.ShengMing - JS2.GongJi;
                Console.WriteLine(JS2.XingMing + "攻击" + JS1.XingMing + ",造成了" + JS2.GongJi + "点伤害," + JS1.XingMing + "还剩余" + JS1.ShengMing + "点生命.");
                System.Threading.Thread.Sleep(1000);
                if (JS1.ShengMing<=0||JS2.ShengMing<=0)//判断角色1或者角色2生命等于0时发生什么
                {
                    if (JS1.ShengMing <= 0 && JS2.ShengMing <= 0)//判断角色1,2生命都等于0时
                    {
                        Console.WriteLine("同归于尽");//输出结果
                        break;//终止循环
                    }
                    else
                    {
                        if (JS1.ShengMing <= 0)//同上
                        {
                            Console.WriteLine(JS2.XingMing+"恭喜胜利");
                            break;
                        }
                        if (JS2.ShengMing <= 0)
                        {
                            Console.WriteLine(JS1.XingMing + "恭喜胜利");
                            break;
                        }
                    }
                }
                
            }

对战游戏 不完全

标签:攻击   ons   输入   amp   等于   输出   while   设定   console   

原文地址:http://www.cnblogs.com/buzhiheyan/p/7801547.html

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