Esempio n. 1
0
        /// <summary>
        /// 战斗场景,当玩家选择战斗后进入
        /// </summary>
        public static void Combat()
        {
            //生成随机数
            Random sjs = new Random();
            //计数器,用来统计局数
            int countNum = 1;
            //判断用户选择角色是否为战士
            bool Rolse = (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Warrior);

            //进入战争循环,直到玩家或者所有怪物死亡,退出
            while (true)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\n\t战争开始了");
                Console.ForegroundColor = ConsoleColor.White;
                int ntemp = sjs.Next(1, 4);
                //用来随机生成敌人(1-3个)
                for (int i = 1; i <= ntemp; i++)
                {
                    //生成一个敌人变量
                    ComputerRoles computerRoles = new ComputerRoles();
                    Thread.Sleep(400);
                    //输出敌人变量的名字
                    Console.WriteLine("\n\t遇到敌人:    " + computerRoles.Name);
                    //把敌人加到敌人列表中
                    ComputerRoles.ListComputerRoles.Add(computerRoles);
                    Thread.Sleep(400);
                }
                //判断玩家输入的是否正确,输入正确后退出循环
                while (true)
                {
                    //显示游戏进行了几次
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\n\t第" + countNum + "回合");
                    Console.ForegroundColor = ConsoleColor.White;
                    Thread.Sleep(400);
                    //提示玩家进行输入
                    s : Console.WriteLine("\n\t请按键选择要执行的行为: \n\n\t1.普通攻击  2.技能攻击  3.显示敌方属性  \n\n\t4.显示己方属性  5.逃跑   6.使用补血药品");
                    //判断玩家输入的是否正确
                    ConsoleKeyInfo Downkey1 = Console.ReadKey(true);
                    //玩家输入后进入攻击方法
                    if (Downkey1.Key.Equals(ConsoleKey.D1) || Downkey1.Key.Equals(ConsoleKey.NumPad1))
                    {
                        Thread.Sleep(400);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n\t您选择的是普通攻击,请按键选择攻击目标:");
                        Console.ForegroundColor = ConsoleColor.White;
                        //输出生成的所有敌人,供玩家选择攻击
                        for (int i = 0; i < ComputerRoles.ListComputerRoles.Count; i++)
                        {
                            Console.WriteLine("\n\t" + (i + 1) + ":" + ComputerRoles.ListComputerRoles[i].Name);
                        }
                        //判断输入的是否正确
                        int Ninttemp;
                        while (true)
                        {
                            //接受玩家的输入信息
                            string strTemp = Console.ReadLine();
                            //判断玩家输入的是否为数字,如果是就退出循环
                            if (int.TryParse(strTemp, out Ninttemp))
                            {
                                //判断玩家输入的是否超过了小怪列表的长度
                                if (ComputerRoles.ListComputerRoles.Count >= Ninttemp)
                                {
                                    break;
                                }
                                else
                                {
                                    Thread.Sleep(400);
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine("\n\t很抱歉,您选择的对象不存在,请重新选择");
                                    Console.ForegroundColor = ConsoleColor.White;
                                }
                            }
                            else
                            {
                                Thread.Sleep(400);
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("\n\t很抱歉,您输入的有误,请重新选择");
                                Console.ForegroundColor = ConsoleColor.White;
                            }
                        }
                        //判断玩家选择的角色,在攻击中对怪物进行不同上海
                        if (Rolse)
                        {
                            //给被攻击对象方法传入:战士
                            ComputerRoles.ListComputerRoles[Ninttemp - 1].Bcombat(_RolesWarrior);
                        }
                        else
                        {
                            //给被攻击对象方法传入:法师
                            ComputerRoles.ListComputerRoles[Ninttemp - 1].Bcombat(_RolesWizard);
                        }
                    }
                    else if (Downkey1.Key.Equals(ConsoleKey.D2) || Downkey1.Key.Equals(ConsoleKey.NumPad2))
                    {
                        Thread.Sleep(400);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n\t您选择的是技能攻击,请按键选择攻击目标:");
                        Console.ForegroundColor = ConsoleColor.White;
                        for (int i = 0; i < ComputerRoles.ListComputerRoles.Count; i++)
                        {
                            Console.WriteLine("\n\t" + (i + 1) + ":" + ComputerRoles.ListComputerRoles[i].Name);
                        }
                        //判断输入的是否正确
                        int Ninttemp;
                        while (true)
                        {
                            //接受玩家输入的选择目标,并进行判断
                            string strTemp = Console.ReadLine();
                            if (int.TryParse(strTemp, out Ninttemp))
                            {
                                if (ComputerRoles.ListComputerRoles.Count >= Ninttemp)
                                {
                                    break;
                                }
                                else
                                {
                                    Thread.Sleep(400);
                                    Console.WriteLine("\n\t很抱歉,您输入的有误,请重新选择");
                                }
                            }
                            else
                            {
                                Thread.Sleep(400);
                                Console.WriteLine("\n\t很抱歉,您输入的有误,请重新选择");
                            }
                        }
                        if (Rolse)
                        {
                            //改变参数,传递使用了技能攻击
                            Bskill = true;
                            ComputerRoles.ListComputerRoles[Ninttemp - 1].Bcombat(_RolesWarrior);
                        }
                        else
                        {
                            //改变参数,传递使用了技能攻击
                            Bskill = true;
                            ComputerRoles.ListComputerRoles[Ninttemp - 1].Bcombat(_RolesWizard);
                        }
                    }
                    else if (Downkey1.Key.Equals(ConsoleKey.D3) || Downkey1.Key.Equals(ConsoleKey.NumPad3))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n\t您选择的是显示敌方属性");
                        Console.ForegroundColor = ConsoleColor.White;
                        Load();
                        //加载出所有怪物的属性
                        for (int i = 0; i < ComputerRoles.ListComputerRoles.Count; i++)
                        {
                            GameRolesManager.Information(ComputerRoles.ListComputerRoles[i].Name, ComputerRoles.ListComputerRoles[i].Hp, ComputerRoles.ListComputerRoles[i].Attack, ComputerRoles.ListComputerRoles[i].Defense, 0, 0, 0, false);
                        }
                    }
                    else if (Downkey1.Key.Equals(ConsoleKey.D4) || Downkey1.Key.Equals(ConsoleKey.NumPad4))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n\t您选择的是显示己方属性");
                        Console.ForegroundColor = ConsoleColor.White;
                        Load();
                        if (Rolse)
                        {
                            //战士的角色信息展示
                            GameRolesManager.Information(_PlayerRoles.Name, _RolesWarrior.Hp, _RolesWarrior.Attack, _RolesWarrior.Defense, _RolesWarrior.Experience, _RolesWarrior.Money, _RolesWarrior.Grade, false);
                        }
                        else if (!Rolse)
                        {
                            //法师的角色信息展示
                            GameRolesManager.Information(_PlayerRoles.Name, _RolesWizard.Hp, _RolesWizard.Attack, _RolesWizard.Defense, _RolesWizard.Experience, _RolesWizard.Money, _RolesWizard.Grade, false);
                        }
                    }
                    else if (Downkey1.Key.Equals(ConsoleKey.D5) || Downkey1.Key.Equals(ConsoleKey.NumPad5))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n\t正在为您加速逃跑中");
                        Console.ForegroundColor = ConsoleColor.White;
                        Load();
                        int temp = sjs.Next(1, 3);
                        if (temp == 2)
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("\n\n\t逃跑成功………………");
                            Console.ForegroundColor = ConsoleColor.White;
                            GameChoice();
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("\n\n\t逃跑失败………………");
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                    }
                    else if (Downkey1.Key.Equals(ConsoleKey.D6) || Downkey1.Key.Equals(ConsoleKey.NumPad6))
                    {
                        Console.WriteLine("\n\t您选择的是使用补血药品");
                        Load();
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n\t请选择您要使用的补血药品");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("\n\t1.能量甘饮");
                        Console.WriteLine("\n\t2.止痛药");
                        ConsoleKeyInfo Downkey4 = Console.ReadKey(true);
                        if (Downkey4.Key.Equals(ConsoleKey.D1) || Downkey4.Key.Equals(ConsoleKey.NumPad1))
                        {
                            if (GamePackage.DicPackageGoods1.ContainsKey("能量甘饮"))
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("\n\t您已成功使用能量甘饮,您的血量增加了120");
                                Console.ForegroundColor = ConsoleColor.White;
                                int count = GamePackage.DicPackageGoods1["能量甘饮"];
                                GamePackage.DicPackageGoods1["能量甘饮"] = count - 1;
                                _RolesWarrior.Hp += 120;
                                _RolesWizard.Hp  += 120;
                                //判断加血是否超过了最大血量
                                if (_RolesWarrior.Hp > ntemp)
                                {
                                    _RolesWarrior.Hp = ntemp;
                                }
                                if (_RolesWizard.Hp > HPTempWizard)
                                {
                                    _RolesWizard.Hp = HPTempWizard;
                                }
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("\n\t您的背包中没有此物品,您可以去商店购买");
                                Console.ForegroundColor = ConsoleColor.White;
                            }
                        }
                        else if (Downkey4.Key.Equals(ConsoleKey.D2) || Downkey4.Key.Equals(ConsoleKey.NumPad2))
                        {
                            if (GamePackage.DicPackageGoods1.ContainsKey("止痛药"))
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("\n\t您已成功使用止痛药,您的血量增加了240");
                                Console.ForegroundColor = ConsoleColor.White;
                                int count = GamePackage.DicPackageGoods1["止痛药"];
                                GamePackage.DicPackageGoods1["止痛药"] = count - 1;
                                _RolesWarrior.Hp += 240;
                                _RolesWizard.Hp  += 240;
                                //判断加血是否超过了最大血量
                                if (_RolesWarrior.Hp > ntemp)
                                {
                                    _RolesWarrior.Hp = ntemp;
                                }
                                if (_RolesWizard.Hp > HPTempWizard)
                                {
                                    _RolesWizard.Hp = HPTempWizard;
                                }
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("\n\t您的背包中没有此物品,您可以去商店购买");
                                Console.ForegroundColor = ConsoleColor.White;
                            }
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Thread.Sleep(500);
                            Console.WriteLine("\n\t很抱歉,您输入的有误,请重新选择");
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Thread.Sleep(500);
                        Console.WriteLine("\n\t很抱歉,您输入的有误,请重新选择");
                        Console.ForegroundColor = ConsoleColor.White;
                        goto s;
                    }
                    //判断生成怪物是否被消灭
                    for (int i = 0; i < ComputerRoles.ListComputerRoles.Count; i++)
                    {
                        if (ComputerRoles.ListComputerRoles[i].Hp <= 0)
                        {
                            Thread.Sleep(400);
                            Console.WriteLine("\n\t" + ComputerRoles.ListComputerRoles[i].Name + "被消灭了");
                            //如果消灭了就删掉这个怪物
                            ComputerRoles.ListComputerRoles.RemoveAt(i);
                            i--;
                        }
                    }
                    //如果所有怪物被消灭
                    if (ComputerRoles.ListComputerRoles.Count == 0)
                    {
                        Thread.Sleep(400);
                        Console.BackgroundColor = ConsoleColor.Red;
                        Console.WriteLine("\n\t战斗结束,你获胜了!!!");
                        Console.BackgroundColor = ConsoleColor.White;
                        //随机生成经验和金钱
                        int jie2 = sjs.Next(10, 20);
                        int jie3 = sjs.Next(5, 200);
                        //给不同角色分别增加金钱和经验
                        if (Rolse)
                        {
                            _RolesWarrior.Experience += jie2;
                            Thread.Sleep(400);
                            Console.WriteLine("\n\t本次战争获得经验" + jie2);
                            _RolesWarrior.Money += jie3;
                            Thread.Sleep(400);
                            Console.WriteLine("\n\t本次战争获得金钱" + jie3);
                        }
                        else
                        {
                            _RolesWizard.Experience += jie2;
                            Thread.Sleep(400);
                            Console.WriteLine("\n\t本次战争获得经验" + jie2);
                            _RolesWizard.Money += jie3;
                            Thread.Sleep(400);
                            Console.WriteLine("\n\t本次战争获得金钱" + jie3);
                        }
                        //随机生成物品
                        int jie1 = sjs.Next(1, 10);
                        if (jie1 == 9 || jie1 == 7)
                        {
                            Thread.Sleep(400);
                            Console.BackgroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("\n\t本次战争获得能量甘饮1瓶,已自动为您放入背包");
                            Console.BackgroundColor = ConsoleColor.White;
                            //给玩家背包增加这个物品
                            int count = GamePackage.DicPackageGoods1["能量甘饮"];
                            GamePackage.DicPackageGoods1["能量甘饮"] = count + 1;
                        }
                        if (jie1 == 5)
                        {
                            Thread.Sleep(400);
                            Console.BackgroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("\n\t本次战争获得止痛药1瓶,已自动为您放入背包");
                            Console.BackgroundColor = ConsoleColor.White;
                            int count = GamePackage.DicPackageGoods1["止痛药"];
                            //给玩家背包增加这个物品
                            GamePackage.DicPackageGoods1["止痛药"] = count + 1;
                        }
                        //判断角色是否可以升级
                        GameRolesManager.Up(Rolse);
                        //回到选择页面,等待玩家再次选择
                        GameChoice();
                    }
                    //如果怪物没有被消灭
                    else
                    {
                        //局数增加
                        countNum++;
                        foreach (var guaiwu in ComputerRoles.ListComputerRoles)
                        {
                            //如果怪物的HP大于0,攻击玩家
                            if (guaiwu.Hp > 0)
                            {
                                if (Rolse)
                                {
                                    //传递对玩家伤害的怪物
                                    _RolesWarrior.Bcombat(guaiwu);
                                }
                                else if (!Rolse)
                                {
                                    _RolesWizard.Bcombat(guaiwu);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 提示玩家选择,1.开始战斗 2.进入商城 3.查看当前属性
 /// </summary>
 public static void GameChoice()
 {
     //清除所有生成的怪物
     ComputerRoles.ListComputerRoles.Clear();
     //判断玩家的等级是否等于5级,如果等于5级就解锁新场景
     if (_RolesWarrior.Grade == 5 || _RolesWizard.Grade == 5)
     {
         //判断是否解锁过新场景,如果解锁过,就不再次解锁
         if (PGrade == 1)
         {
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine("\n\t**************解锁场景失落的古城**************");
             Console.ForegroundColor = ConsoleColor.White;
             Console.WriteLine("\n\t解锁新怪物 叛军  BOSS:变异的军人 ");
             //进入场景后,用于判断玩家等级是否升级的计数器进行增加
             PGrade++;
         }
     }
     //判断玩家选择角色,在玩家每次战斗结束后,恢复玩家血量
     if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Warrior)
     {
         //恢复战士的HP
         _RolesWarrior.Hp = HPTemp;
     }
     else if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Wizard)
     {
         //恢复法师的HP
         _RolesWizard.Hp = HPTempWizard;
     }
     //加载延时,模仿真实游戏加载
     Thread.Sleep(500);
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine("\n\n\t\t* * * * * * * * *欢迎回来\t" + _PlayerRoles.Name);
     Console.ForegroundColor = ConsoleColor.White;
     //进入一个死循环,用于判断玩家的选择是否是给出的选择,如果不是则不退出,如果是则执行相对应的函数
     while (true)
     {
         Thread.Sleep(400);
         Console.ForegroundColor = ConsoleColor.White;
         Console.WriteLine("\n\t请选择您要进行的操作  \n\n\t1.进入战斗  2.进入商城  \n\n\t3.查看当前属性  4.查看当前背包物品  \n\n\t5.技能查看   6.技能学习");
         //判断玩家的按键,获得玩家选择
         ConsoleKeyInfo Downkey1 = Console.ReadKey(true);
         if (Downkey1.Key.Equals(ConsoleKey.D1) || Downkey1.Key.Equals(ConsoleKey.NumPad1))
         {
             //判断玩家选择角色,然后进行判断,在战斗前存储玩家Hp,用于在战斗结束后恢复
             if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Warrior)
             {
                 //保存战士的HP
                 HPTemp = _RolesWarrior.Hp;
             }
             else if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Wizard)
             {
                 //保存法师的HP
                 HPTempWizard = _RolesWizard.Hp;
             }
             Thread.Sleep(400);
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine("\n\t**************您选择的是进入战斗");
             Console.ForegroundColor = ConsoleColor.White;
             //加载动画
             Load();
             //进入战斗场景
             Combat();
             break;
         }
         else if (Downkey1.Key.Equals(ConsoleKey.D2) || Downkey1.Key.Equals(ConsoleKey.NumPad2))
         {
             Thread.Sleep(400);
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine("\n\t**************您选择的是进入商城");
             Console.ForegroundColor = ConsoleColor.White;
             //加载动画
             Load();
             _WeaponStore.PanDuan();
             break;
         }
         else if (Downkey1.Key.Equals(ConsoleKey.D3) || Downkey1.Key.Equals(ConsoleKey.NumPad3))
         {
             Thread.Sleep(400);
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine("\n\t**************您选择的是查看当前属性");
             Console.ForegroundColor = ConsoleColor.White;
             //加载动画
             Load();
             //根据玩家选择的是法师还是战士,展示不同的属性
             if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Warrior)
             {
                 //战士的角色信息展示
                 GameRolesManager.Information(_PlayerRoles.Name, _RolesWarrior.Hp, _RolesWarrior.Attack, _RolesWarrior.Defense, _RolesWarrior.Experience, _RolesWarrior.Money, _RolesWarrior.Grade);
             }
             else if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Wizard)
             {
                 //法师的角色信息展示
                 GameRolesManager.Information(_PlayerRoles.Name, _RolesWizard.Hp, _RolesWizard.Attack, _RolesWizard.Defense, _RolesWizard.Experience, _RolesWizard.Money, _RolesWizard.Grade);
             }
             break;
         }
         else if (Downkey1.Key.Equals(ConsoleKey.D4) || Downkey1.Key.Equals(ConsoleKey.NumPad4))
         {
             Thread.Sleep(400);
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine("\n\t**************您选择的是查看背包");
             Console.ForegroundColor = ConsoleColor.White;
             //加载动画
             Load();
             _PlayerPackage.PackageToUp();
             break;
         }
         else if (Downkey1.Key.Equals(ConsoleKey.D5) || Downkey1.Key.Equals(ConsoleKey.NumPad5))
         {
             Thread.Sleep(400);
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine("\n\t**************您选择的是查看技能");
             Console.ForegroundColor = ConsoleColor.White;
             //加载动画
             Load();
             //根据玩家选择的是法师还是战士,展示不同的技能
             if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Warrior)
             {
                 //战士的技能列表
                 WarriorSkill.WarriorSkillShow();
             }
             else if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Wizard)
             {
                 //法师的技能列表
                 WizardSkill.WizardSkillShow();
             }
             break;
         }
         else if (Downkey1.Key.Equals(ConsoleKey.D6) || Downkey1.Key.Equals(ConsoleKey.NumPad6))
         {
             Thread.Sleep(400);
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine("\n\t**************您选择的是学习技能");
             Console.ForegroundColor = ConsoleColor.White;
             //加载动画
             Load();
             //根据玩家选择的是法师还是战士,学习不同的技能
             if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Warrior)
             {
                 WarriorSkill.StartWarriorSkill();
                 //战士的技能学习
             }
             else if (Enum_GamePlayerRoles == Enum_GameRoles.Enum_Wizard)
             {
                 WizardSkill.StartWizardSkill();
                 //法师的技能学习
             }
             break;
         }
         //选择错误就提示错误,并回到开头,重新选择
         else
         {
             Console.ForegroundColor = ConsoleColor.Red;
             Thread.Sleep(500);
             Console.WriteLine("\n\t**************很抱歉,您输入的有误,当前选择不存在");
         }
     }
 }