c#对战游戏

2021-04-30 18:28

阅读:481

标签:amp   else   shang   alt   ret   sleep   bsp   分享   color   

namespace 对战游戏
{
       class Program
    {
        public struct ZhanShi
        {
            public string MingZi;
            public int GongJi;
            public int XueLiang;
        }


        static void Main(string[] args)
        {
         创建战士给战士赋予属性
            ZhanShi zs1 = new ZhanShi();
            zs1.MingZi = "张无忌";
            zs1.GongJi = 100;
            zs1.XueLiang = 1000;

            ZhanShi zs2 = new ZhanShi();
            zs2.MingZi = "洪七公";
            zs2.GongJi = 150;
            zs2.XueLiang = 700;
       
            //对打
            while (true)
            {
                int ShangHai = Program.PuTongGongJi(zs1.GongJi);
                zs2.XueLiang = zs2.XueLiang - ShangHai;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(zs1.MingZi + " 对 " + zs2.MingZi + " 发动了普通攻击,造成了" + ShangHai + "点伤害, " + zs2.MingZi + " 剩余" + zs2.XueLiang + "点血量!");
                Console.WriteLine();
                System.Threading.Thread.Sleep(1000);

                ShangHai = Program.PuTongGongJi(zs2.GongJi);
                zs1.XueLiang = zs1.XueLiang - ShangHai;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(zs2.MingZi + " 对 " + zs1.MingZi + " 发动了普通攻击,造成了" + ShangHai + "点伤害, " + zs1.MingZi + " 剩余" + zs1.XueLiang + "点血量!");
                Console.WriteLine();

                System.Threading.Thread.Sleep(1000);

                if (zs1.XueLiang                 {
                    if (zs1.XueLiang                     {
                        Console.WriteLine("二位同归于尽了!!!");
                    }
                    else
                    {
                        if (zs1.XueLiang                         {
                            Console.WriteLine(zs2.MingZi + "获得了最终胜利!!!");
                        }
                        else
                        {
                            Console.WriteLine(zs1.MingZi + "获得了最终胜利!!!");
                        }
                    }
                    break;
                }
            }

            //判断输赢


            Console.ReadKey();
        }
                      生成浮动攻击力
        ///


        /// 生成普通攻击的浮动攻击值
        ///

        /// 普通攻击的基础攻击力
        ///
        public static int PuTongGongJi(int a)
        {
            int cc = 0;
            Random r = new Random();
            int aa = r.Next(0, 141);
            int bb = r.Next(0, 2);
            if (bb == 0)
            {
                cc = a + aa;
            }
            else
            {
                cc = a - aa;
            }
            return cc;
        }
    }
}

效果图:技术分享

c#对战游戏

标签:amp   else   shang   alt   ret   sleep   bsp   分享   color   

原文地址:http://www.cnblogs.com/gbbwzz/p/7799415.html

上一篇:win7 host文件绑定

下一篇:c#基础试题


评论


亲,登录后才可以留言!