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

    效果图:

    开始:

    结束:

  • 相关阅读:
    python3安装 MAC
    MacOS三个比较接地气实用的终端命令
    maya界面字体怎么设置大小?
    Mac 下 Android Studio 连 夜神模拟器 调试以及真机调试方法
    [macOS] Mojave10.14 夜神安卓模拟器启动问题
    解决MAC电脑系统设置的安全性与隐私下通用没有任何来源选项
    一个分析“文件夹”选择框实现方法的过程
    windows下nginx+php简单配置
    使用windbg抓取崩溃文件和分析的过程
    解决工作中遇到的一个"打开,保存"文件框的bug的过程
  • 原文地址:https://www.cnblogs.com/tzq9308/p/4204767.html
Copyright © 2020-2023  润新知