示例#1
0
 public string attack(Creature enemy)           //Желательно переделать в виртуальный метод, и для каждого класса существ переопределять отдельно
 {
     target = enemy;
     if (target != null)
     {
         if (target.isAlive())
         {
             //isInBattle = true;
             float _enemy_hp = target.getHp()[0];                      //нужно для расчёта нанесённого урона
             target.takeDamage(damage);
             if (!target.isAlive())
             {
                 string _enemy_name = target.name;
                 addExp((int)target.maxhp);
                 target.Die();
                 target = null;
                 //isInBattle = false;
                 return(name + " убил " + _enemy_name);
             }
             else
             {
                 return(name + " нанёс " + Convert.ToInt32(_enemy_hp - target.hp) + " урона по " + target.name);
             }
         }
         else
         {
             return(target.name + " уже мёртв");
         }
     }
     else
     {
         return("Цель отсутствует");
     }
 }
示例#2
0
        static void gameHandler(Creature hero)
        {
            ConsoleKeyInfo key;

            while (hero.isAlive())
            {
                right_i = 4;
                updateUI(hero, info);
                key = Console.ReadKey(true);
                switch (key.Key)
                {
                case ConsoleKey.L:
                {
                    resetToDefault(hero);
                    break;
                }

                case ConsoleKey.G:
                {
                    resetToDefault(hero);
                    choiceDirection();
                    info = "ChoiceDirection";
                    updateUI(hero, info);
                    resetToDefault(hero);
                    ConsoleKeyInfo choice = Console.ReadKey(true);
                    switch (choice.Key)
                    {
                    case ConsoleKey.W:                             //Вверх
                        addToLog(hero.goToDirection(0, 1));
                        break;

                    case ConsoleKey.Q:                            //Вверх влево
                        addToLog(hero.goToDirection(-1, 1));
                        break;

                    case ConsoleKey.A:                            //влево
                        addToLog(hero.goToDirection(-1, 0));
                        break;

                    case ConsoleKey.Z:                            //вниз влево
                        addToLog(hero.goToDirection(-1, -1));
                        break;

                    case ConsoleKey.X:                            //вниз
                        addToLog(hero.goToDirection(0, -1));
                        break;

                    case ConsoleKey.C:                            //Вниз вправо
                        addToLog(hero.goToDirection(1, -1));
                        break;

                    case ConsoleKey.D:                            //вправо
                        addToLog(hero.goToDirection(1, 0));
                        break;

                    case ConsoleKey.E:                            //вверх вправо
                        addToLog(hero.goToDirection(1, 1));
                        break;

                    case ConsoleKey.S:
                        break;
                    }
                    resetToDefault(hero);
                    break;
                }                          //end of case

                case ConsoleKey.T:
                {
                    resetToDefault(hero);
                    info = "SelectTarget";
                    updateUI(hero, info);
                    int choice_target = Convert.ToInt32(Console.ReadLine());
                    hero.selectTarget(hero.getLocation().creatures [choice_target]);
                    addToLog(hero.name + " выбрал целью " + hero.getLocation().creatures [choice_target].name);
                    resetToDefault(hero);
                    right_i = 4;
                    updateUI(hero, info);
                    break;
                }

                case ConsoleKey.A:
                {
                    addToLog(hero.attack(hero.getTarget()));
                    if (/* hero.isInBattle && */ hero.getTarget() != null)
                    {
                        info = "FightInfo";
                    }
                    else
                    {
                        resetToDefault(hero);
                    }
                    break;
                }

                case ConsoleKey.P:
                {
                    info = "ChoiceItemToPick";
                    updateUI(hero, info);
                    int item = Convert.ToInt32(Console.ReadLine());
                    addToLog(hero.pickUpItem(hero.getLocation().getItems() [item]));
                    resetToDefault(hero);
                    break;
                }

                case ConsoleKey.I:
                {
                    info = "Inventory";
                    updateUI(hero, info);
                    right_i = 4;
                    break;
                }

                case ConsoleKey.S:
                {
                    info = "drawHeroStats";
                    updateUI(hero, info);
                    break;
                }

                case ConsoleKey.U:
                {
                    switch (Console.ReadKey(true).Key)
                    {
                    case ConsoleKey.S:
                        addToLog("Выберите характеристику для улучшения");
                        updateUI(hero, "drawHeroStats");
                        string choice = Console.ReadLine();
                        addToLog(hero.upgradeStat(Convert.ToInt32(choice)));
                        break;
                    }
                    break;
                }
                }                 //end of switch
                for (int i = 0; i < hero.getLocation().creatures.Count; i++)
                {
                    if (hero.getLocation().creatures [i].isEnemy)
                    {
                        addToLog(((IEnemy)(hero.getLocation().creatures [i])).AI(hero));
                    }
                }
                for (int i = 0; i < hero.buffs.Count; i++)
                {
                    hero.buffs [i].update();
                }
                updateUI(hero, info);
            }
            Console.WriteLine("Лол ты сдох");
        }