• 对战游戏


    zhaoshi.cs中:

    namespace 对战游戏
    {
        class zhaoshi
        {
            private string _name;
    
            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }
            private int _gongji;
    
            public int Gongji
            {
                get { return _gongji; }
                set { _gongji = value; }
            }
    
            private zhaoshi _xiaozhao;
    
            internal zhaoshi Xiaozhao
            {
                get { return _xiaozhao; }
                set { _xiaozhao = value; }
            }
    
            private zhaoshi _dazhao;
    
            internal zhaoshi Dazhao
            {
                get { return _dazhao; }
                set { _dazhao = value; }
            }
        }
    }

    soldier.cs中:

    namespace 对战游戏
    {
        public class soldier
        {
        //名字、生命值、攻击力、招式
            private string _name;
    
            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }
            private int _blood;
    
            public int Blood
            {
                get { return _blood; }
                set { _blood = value; }
            }
    
            private int _gongji;
    
            public int Gongji
            {
                get { return _gongji; }
                set { _gongji = value; }
            }
    
            private int _miss;
    
            public int Miss
            {
                get { return _miss; }
                set { _miss = value; }
            }
            private zhaoshi xiaozhao;
    
            internal zhaoshi Xiaozhao
            {
                get { return xiaozhao; }
                set { xiaozhao = value; }
            }
    
            private zhaoshi dazhao;
    
            internal zhaoshi Dazhao
            {
                get { return dazhao; }
                set { dazhao = value; }
            }
    
    
        }
    }

    program.cs中:

    namespace 对战游戏
    {
        class Program
        {
            static void Main(string[] args)
            {
                Random r = new Random();
                soldier s1 = new soldier();
                Console.WriteLine("请输入第一个战士名字:");
                s1.Name = Console.ReadLine();
                s1.Gongji = r.Next(10,101);
                s1.Blood = r.Next(500,1001);
                zhaoshi z1 = new zhaoshi();
                Console.WriteLine("请输入小招名称:");
                z1.Name = Console.ReadLine();
                z1.Gongji = r.Next(100,201);
                s1.Xiaozhao = z1;
                zhaoshi z2 = new zhaoshi();
                Console.WriteLine("请输入大招名称:");
                z2.Name = Console.ReadLine();
                z2.Gongji = r.Next(300,501);
                s1.Dazhao = z2;
    
                s1.Miss = r.Next(0,41);
    
    
                soldier s2 = new soldier();
                Console.WriteLine("请输入第二个战士名字:");
                s2.Name = Console.ReadLine();
                s2.Gongji = r.Next(10,101);
                s2.Blood = r.Next(500,1001);
                zhaoshi z3 = new zhaoshi();
                Console.WriteLine("请输入小招名称:");
                z3.Name = Console.ReadLine();
                z3.Gongji = r.Next(100,201);
                s2.Xiaozhao = z1;
                zhaoshi z4 = new zhaoshi();
                Console.WriteLine("请输入大招名称:");
                z4.Name = Console.ReadLine();
                z4.Gongji = r.Next(300,501);
                s2.Dazhao = z4;
    
                s2.Miss = r.Next(0,41);
    
                Console.WriteLine("======================战士信息展示=======================");
                Console.WriteLine("战士1:" + s1.Name + ",攻击:" + s1.Gongji + ",闪避:" + s1.Miss + ",血量:" + s1.Blood + ",小招:" + s1.Xiaozhao.Name + "" + s1.Xiaozhao.Gongji + ",大招:" + s1.Dazhao.Name + "" + s1.Dazhao.Gongji);
                Console.WriteLine("战士2:" + s2.Name + ",攻击:" + s2.Gongji + ",闪避:" + s2.Miss + ",血量:" + s2.Blood + ",小招:" + s2.Xiaozhao.Name + "" + s2.Xiaozhao.Gongji + ",大招:" + s2.Dazhao.Name + "" + s2.Dazhao.Gongji);
                Console.WriteLine("按下任意键开始战斗!!!");
                Console.ReadKey();
    
                //开始对战
                int count = 1;
                while (true)
                {
                    Console.WriteLine("-------------------第"+count+"回合------------------");
                    //战士1开始攻击
                    System.Threading.Thread.Sleep(1000);
                    if (r.Next(0, 101) < s2.Miss)
                    {
                        Console.WriteLine(s2.Name+"躲避了此次攻击");
                    }
                    else
                    {
                        int ss1 = r.Next(0,101);
                        if (ss1 > 95)//开大招
                        {
                            Console.WriteLine("" + s1.Name + "】对【" + s2.Name + "】释放了☆☆☆☆☆" + s1.Dazhao.Name + "☆☆☆☆☆,造成" + s1.Dazhao.Gongji + "点伤害,【" + s2.Name + "】剩余" + (s2.Blood - s1.Dazhao.Gongji) + "点血量");
                            Console.WriteLine();
                            s2.Blood = s2.Blood - s1.Dazhao.Gongji;
                        }
                        else if (ss1 > 80)//开小招
                        {
                            Console.WriteLine("" + s1.Name + "】对【" + s2.Name + "】释放了☆☆" + s1.Xiaozhao.Name + "☆☆,造成" + s1.Xiaozhao.Gongji + "点伤害,【" + s2.Name + "】剩余" + (s2.Blood - s1.Xiaozhao.Gongji) + "点血量");
                            Console.WriteLine();
                            s2.Blood = s2.Blood - s1.Xiaozhao.Gongji;
                        }
                        else
                        {
                            Console.WriteLine("" + s1.Name + "】攻击了【" + s2.Name + "】,造成" + s1.Gongji + "点伤害,【" + s2.Name + "】剩余" + (s2.Blood - s1.Gongji) + "点血量");
                            Console.WriteLine();
                            s2.Blood = s2.Blood - s1.Gongji;
                        }
                        if (s2.Blood <= 0)
                        {
                            Console.WriteLine(s2.Name+"已阵亡"+s1.Name+"是获胜者");
                            break;
                        }                
                    }
                    //战士2开始攻击
                    System.Threading.Thread.Sleep(1000);
                    if (r.Next(0, 101) < s1.Miss)
                    {
                        Console.WriteLine(s1.Name+"躲避了此次攻击");
                    }
                    else
                    {
                        int ss2 = r.Next(0,101);
                        if (ss2 > 95)
                        {
                            Console.WriteLine("" + s2.Name + "】对【" + s1.Name + "】释放了☆☆☆☆☆" + s2.Dazhao.Name + "☆☆☆☆☆,造成" + s2.Dazhao.Gongji + "点伤害,【" + s1.Name + "】剩余" + (s1.Blood - s2.Dazhao.Gongji) + "点血量");
                            Console.WriteLine();
                            s1.Blood = s1.Blood - s2.Dazhao.Gongji;
                        }
                        else if (ss2 > 80)
                        {
                            Console.WriteLine("" + s2.Name + "】对【" + s1.Name + "】释放了☆☆" + s2.Xiaozhao.Name + "☆☆,造成" + s2.Xiaozhao.Gongji + "点伤害,【" + s1.Name + "】剩余" + (s1.Blood - s2.Xiaozhao.Gongji) + "点血量");
                            Console.WriteLine();
                            s1.Blood = s1.Blood - s2.Xiaozhao.Gongji;
                        }
                        else
                        {
                            Console.WriteLine("" + s2.Name + "】攻击了【" + s1.Name + "】,造成" + s2.Gongji + "点伤害,【" + s1.Name + "】剩余" + (s1.Blood - s2.Gongji) + "点血量");
                            Console.WriteLine();
                            s1.Blood = s1.Blood - s2.Gongji;
                        }
                        if (s1.Blood <= 0)
                        {
                            Console.WriteLine(s1.Name + "已阵亡" + s2.Name + "是获胜者");
                            break;
                        }
                    }
                    count++;                                 
                }
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    springboot接口测试
    谷粒学院_day08_课程管理_添加课程之课程发布(后端开发)
    谷粒学院_day03_vue组件
    谷粒学院_day03_vue固定代码抽取
    vue自定义事件
    vue插槽slot
    vue基本语法
    Vue之axios异步通信
    无归岛[HNOI2009]
    仓库建设[ZJOI2007]
  • 原文地址:https://www.cnblogs.com/wy1992/p/6106724.html
Copyright © 2020-2023  润新知