Пример #1
0
        //method to make enemy move logic
        private void EnemyMove(Wizard enemy)
        {
            //dead enemy can't make a move
            if (enemy.CharacterState == State.Dead)
            {
                return;
            }

            //enemy that need revival, heal or unparalyze
            Wizard inDangerTarget = enemy;
            //enemy that need mana regeneration
            Wizard lowerManaTarget = enemy;

            //if enemy quantity more than 1 we want to choose the most weakened character in list of enemies
            if (_enemy.Count > 1)
            {
                foreach (var wizard in _enemy)
                {
                    if (wizard.CurrentHealthPoints < inDangerTarget.CurrentHealthPoints ||
                        wizard.CharacterState is State.Dead or State.Paralyzed)
                    {
                        if (wizard.CharacterState == State.Paralyzed &&
                            inDangerTarget.CharacterState == State.Paralyzed)
                        {
                            //if both characters are paralyzed it chooses one with least hp
                            switch (wizard.CurrentHealthPoints < inDangerTarget.CurrentHealthPoints)
                            {
                            case true:
                            {
                                inDangerTarget = wizard;
                                break;
                            }

                            case false:
                            {
                                break;
                            }
                            }
                        }
                        else
                        {
                            inDangerTarget = wizard;
                        }
                    }
                    //find character with the least mana
                    if (wizard.CurrentMana < lowerManaTarget.CurrentMana)
                    {
                        lowerManaTarget = wizard;
                    }
                }
            }
            //switch to revive or unparalyze character or his teammate
            switch (inDangerTarget.CharacterState)
            {
            case State.Dead:
            {
                if (TryCastSpell(new SpellRevival(), enemy, inDangerTarget))
                {
                    return;
                }

                break;
            }

            case State.Paralyzed:
            {
                if (TryCastSpell(new SpellUnparalyze(), enemy, inDangerTarget))
                {
                    return;
                }

                break;
            }
            }

            //cast heal spell when character is lowHP and mana is not low
            if (inDangerTarget.CurrentHealthPoints < inDangerTarget.MaxHealthPoints / 2 && enemy.CurrentMana >= enemy.MaxMana / 2)
            {
                if (TryCastSpell(new SpellHeal(), enemy, inDangerTarget))
                {
                    return;
                }
            }

            Artefact outFromFunc;

            //use living water when it is in inventory and inDangerTarget needs hp regeneration
            if (inDangerTarget.CurrentHealthPoints < inDangerTarget.MaxHealthPoints / 2 &&
                enemy.HasWaterBottle(true, out outFromFunc))
            {
                enemy.UseArtefact(outFromFunc, inDangerTarget);
                return;
            }

            //use dead water when it is in inventory and lowerManaTarget needs mana regeneration
            if (lowerManaTarget.CurrentMana < lowerManaTarget.MaxMana / 4 &&
                enemy.HasWaterBottle(false, out outFromFunc))
            {
                enemy.UseArtefact(outFromFunc, lowerManaTarget);
                return;
            }

            //use armor spell when mana is almost full(it is quite expensive)
            if (enemy.CurrentMana > enemy.MaxMana * 8 / 10)
            {
                if (TryCastSpell(new SpellArmor(), enemy, enemy))
                {
                    return;
                }
            }

            //switch to undo the negative state
            switch (enemy.CharacterState)
            {
            case State.Poisoned:
            {
                if (TryUseArtefact(new FrogLegsDecoct(), enemy, enemy))
                {
                    return;
                }

                break;
            }

            case State.Sick:
            {
                if (TryCastSpell(new SpellAntidote(), enemy, enemy))
                {
                    return;
                }

                break;
            }
            }

            //use artefact with negative status on main player
            if (_mainPlayer.CharacterState != State.Dead &&
                (_mainPlayer.CharacterState is State.Healthy or State.Weakened) &&
                enemy.HasStatusArtefact(out outFromFunc))
            {
                enemy.UseArtefact(outFromFunc, _mainPlayer);
                return;
            }

            //use spell FireBall on main player when there is enough mana and spell is learned
            if (enemy._learnedSpells.FindIndex(spell => spell.ToString() == new SpellFireball().ToString()) != -1 &&
                enemy.CurrentMana > enemy.MaxMana / 4)
            {
                enemy.CastSpell(new SpellFireball(), _mainPlayer, enemy.CurrentMana / 4);
            }

            enemy.UseArtefact(enemy._inventory[0], _mainPlayer);
        }
Пример #2
0
        //works as a constructor, it creates character and returns it
        public Wizard CreateCharacter(Wizard wizard)
        {
            Console.WriteLine("Now is the time to create the character and choose the subclass");
            string name;

            while (true)
            {
                Console.WriteLine("Enter the name of your character(name couldn't be empty):");
                name = Console.ReadLine();
                //regexp to process and check the input data
                Regex reg = new Regex(@"^\s*$");
                if (!reg.IsMatch(name))
                {
                    while (name[0] == ' ')
                    {
                        name = name.Remove(0, 1);
                    }
                    while (name[name.Lenght - 1] == ' ')
                    {
                        name = name.Remove(name.Length - 1, 1);
                    }
                    break;
                }

                Console.WriteLine("Wrong format");
            }

            int age;

            while (true)
            {
                Console.WriteLine("Enter the age of your character:");
                //here we try to parse string with age, and if it is not possible, ask for input one more time
                if (int.TryParse(Console.ReadLine(), out age))
                {
                    if (age < 12)
                    {
                        Console.WriteLine("Age must be at least 12. Try again");
                        continue;
                    }

                    break;
                }

                Console.WriteLine(
                    "It is probably a miss click or you don't even know, that age contains only numbers");
            }

            var race = Race.Elf;

            while (true)
            {
                Console.WriteLine("Which race would you choose:\nHuman(1)\nGnome(2)\nElf(3)\nOrc(4)\nGoblin(5)");
                //here we try to parse string with choice number, and if it is not possible or number is wrong, ask for input one more time
                int choice;
                if (int.TryParse(Console.ReadLine(), out choice) && choice is >= 1 and <= 5)
                {
                    switch (choice)
                    {
                    case 1:
                    {
                        race = Race.Human;
                        break;
                    }

                    case 2:
                    {
                        race = Race.Gnome;
                        break;
                    }

                    case 3:
                    {
                        race = Race.Elf;
                        break;
                    }

                    case 4:
                    {
                        race = Race.Orc;
                        break;
                    }

                    case 5:
                    {
                        race = Race.Goblin;
                        break;
                    }
                    }

                    break;
                }

                Console.WriteLine("You need numbers from 1 to 5");
            }

            var gender = Gender.Undefined;

            while (true)
            {
                Console.WriteLine("Which gender would you choose:\nMale(1)\nFemale(2)\nUndefined(3)");
                //here we try to parse string with choice number, and if it is not possible or number is wrong, ask for input one more time
                int choice;
                if (int.TryParse(Console.ReadLine(), out choice) && choice is >= 1 and <= 3)
                {
                    switch (choice)
                    {
                    case 1:
                    {
                        gender = Gender.Male;
                        break;
                    }

                    case 2:
                    {
                        gender = Gender.Female;
                        break;
                    }

                    case 3:
                    {
                        gender = Gender.Undefined;
                        break;
                    }
                    }

                    break;
                }

                Console.WriteLine("You need numbers from 1 to 3");
            }

            Console.WriteLine(
                "And now is the time to choose a subclass of you character:\nWizard(1)\nWarrior(2)\nBandit(3)");
            Console.ReadLine();
            Console.WriteLine(
                "Ooops... There is a problem. Whatever you choose, your subclass will be a wizard. The rest are not finalized yet, the game is on the prerelease beta gamma alpha test 0.0.0.0.1a.");
            Thread.Sleep(2000);
            wizard      = new Wizard(name, race, gender, age);
            _mainPlayer = wizard;
            return(_mainPlayer);
        }