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

c#对战游戏

时间:2017-11-07 18:07:00      阅读:254      评论:0      收藏:0      [点我收藏+]

标签: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 <= 0 || zs2.XueLiang <= 0)
                {
                    if (zs1.XueLiang <= 0 && zs2.XueLiang <= 0)
                    {
                        Console.WriteLine("二位同归于尽了!!!");
                    }
                    else
                    {
                        if (zs1.XueLiang <= 0)
                        {
                            Console.WriteLine(zs2.MingZi + "获得了最终胜利!!!");
                        }
                        else
                        {
                            Console.WriteLine(zs1.MingZi + "获得了最终胜利!!!");
                        }
                    }
                    break;
                }
            }

            //判断输赢


            Console.ReadKey();
        }
                      生成浮动攻击力
        /// <summary>
        /// 生成普通攻击的浮动攻击值
        /// </summary>
        /// <param name="a">普通攻击的基础攻击力</param>
        /// <returns></returns>
        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

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