zoukankan      html  css  js  c++  java
  • 1月5日 结构体(对战小游戏)

    对战小游戏:

    namespace duzhanxiaoyouxi
    {
        struct RenWu
        {
            public string Name;
            public int Blood;
            public int Attack;
            public int Defence;
            public int Speed;
            public WuGong WG;
        }
        struct WuGong
        {
            public string Name;
            public int Attack;
            public int Defence;
            public int Speed;
        }
        class Program
        {
            static void Main(string[] args)
            {
                //创建
                RenWu r1 = new RenWu();
                RenWu r2 = new RenWu();
    
                Console.Write("请输入第一个战士的姓名:");
                r1.Name = Console.ReadLine();
    
                Console.Write("请输入第二个战士的姓名:");
                r2.Name = Console.ReadLine();
    
                //生成血量
                Random rand = new Random();
                r1.Blood = rand.Next(1000) + 1000;
                r2.Blood = rand.Next(1000) + 1000;
    
                //生成攻防
                r1.Attack = rand.Next(100) + 50;
                r1.Defence = rand.Next(100) + 50;
    
                r2.Attack = rand.Next(100) + 50;
                r2.Defence = rand.Next(100) + 50;
    
                //生成身法
                r1.Speed = rand.Next(100);
                r2.Speed = rand.Next(100);
    
                Console.WriteLine(r1.Name + "的血量为:" + r1.Blood + "滴	攻击力为:" + r1.Attack + "	防御力为:" + r1.Defence);
                Console.WriteLine(r2.Name + "的血量为" + r2.Blood + "滴	攻击力为:" + r2.Attack + "	防御力为:" + r2.Defence);
                Console.WriteLine();
                //对战
                while (true)
                {
                    //跳出循环的条件
                    if (r1.Blood <= 0 && r2.Blood <= 0)
                    {
                        Console.WriteLine(r1.Name + "" + r2.Name + "同归于尽了");
                        break;
                    }
                    if (r1.Blood <= 0)
                    {
                        Console.WriteLine(r2.Name + "" + r1.Name + "KO了");
                        break;
                    }
                    if (r2.Blood <= 0)
                    {
                        Console.WriteLine(r1.Name + "" + r2.Name + "KO了");
                        break;
                    }
    
                    //开始对战
                    int shenfa = rand.Next(50)+50;
     
                    //速度稍慢一些  暂停一秒
                    System.Threading.Thread.Sleep(1000);
    
                    
                    if (r2.Speed > shenfa)
                    {
                        Console.WriteLine(r2.Name + "躲过了" + r1.Name + "的攻击");
                    }
                    else
                    {
                        int shanghai1 = rand.Next(100) + 50;//第一个对第二个的伤害
                        shanghai1 += r1.Attack - r2.Defence; //第二个人实际掉的血
    
                        r2.Blood = (r2.Blood - shanghai1) < 0 ? 0 : (r2.Blood - shanghai1);
    
                        //改变文字颜色
                        Console.ForegroundColor = ConsoleColor.Blue;
    
                        Console.Write(r1.Name + "发起攻击," + r2.Name + "掉了" + (shanghai1 < 0 ? 0 : shanghai1) + "滴血	");
                        Console.WriteLine();
                    }
    
                    if (r1.Speed > shenfa)
                    {
                        Console.WriteLine(r1.Name + "躲过了" + r2.Name + "的攻击");
                    }
                    else
                    {
                        int shanghai2 = rand.Next(100) + 50;
                        shanghai2 += r2.Attack - r1.Defence;
    
                        r1.Blood = (r1.Blood - shanghai2) < 0 ? 0 : (r1.Blood - shanghai2);
    
                        //改变文字颜色
                        Console.ForegroundColor = ConsoleColor.Red;
    
                        Console.WriteLine(r2.Name + "发起攻击," + r1.Name + "掉了" + (shanghai2 < 0 ? 0 : shanghai2) + "滴血");
                    }
                    //改变文字颜色
                    Console.ForegroundColor = ConsoleColor.Green;
    
                    Console.WriteLine(r1.Name + "的剩余血量为" + r1.Blood + "	" + r2.Name + "的剩余血量为" + r2.Blood );
    
                    Console.WriteLine();
                    Console.WriteLine();
    
                }
            }
        }
    }

    效果图:

    开始:

    结束:

  • 相关阅读:
    举例阐述游戏战斗系统设计的基本规则
    角色动作控制接口的设计
    游戏动作感设计初探
    c#扩展方法
    Bundle Adjustment光束平差法概述
    Levenberg-Marquardt
    OpenCV2:Mat属性type,depth,step
    opencv surf特征点匹配拼接源码
    OpenCV仿射变换+投射变换+单应性矩阵
    在OpenCV for Android 2.4.5中使用SURF(nonfree module)
  • 原文地址:https://www.cnblogs.com/tzq9308/p/4204767.html
Copyright © 2011-2022 走看看