Exemple #1
0
        static void Main(string[] args)
        {
            List <Hero> heroes = new List <Hero>();
            int         n      = int.Parse(Console.ReadLine());
            int         hpMax  = 100;
            int         mpMax  = 200;

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(" ");

                string heroName = input[0];
                int    hp       = int.Parse(input[1]);
                int    mp       = int.Parse(input[2]);

                Hero hero = new Hero
                {
                    Name = input[0],
                    Hp   = hp > hpMax ? hpMax : hp,
                    Mp   = mp > mpMax ? mpMax : mp
                };

                heroes.Add(hero);
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                string[] cmdArg   = command.Split(" - ");
                string   cmd      = cmdArg[0];
                string   heroName = cmdArg[1];

                Hero hero = heroes.FirstOrDefault(h => h.Name == heroName);

                if (cmd == "CastSpell")
                {
                    int    MpNeeded  = int.Parse(cmdArg[2]);
                    string spellName = cmdArg[3];

                    if (hero.Mp >= MpNeeded)
                    {
                        hero.Mp -= MpNeeded;
                        Console.WriteLine($"{hero.Name} has successfully cast {spellName} and now has {hero.Mp} MP!");
                    }
                    else
                    {
                        Console.WriteLine($"{hero.Name} does not have enough MP to cast {spellName}!");
                    }
                }
                else if (cmd == "TakeDamage")
                {
                    int    damage   = int.Parse(cmdArg[2]);
                    string attacker = cmdArg[3];

                    if (hero.Hp > damage)
                    {
                        hero.Hp -= damage;
                        Console.WriteLine($"{hero.Name} was hit for {damage} HP by {attacker} and now has {hero.Hp} HP left!");
                    }
                    else
                    {
                        Console.WriteLine($"{hero.Name} has been killed by {attacker}!");
                        heroes.Remove(hero);
                    }
                }
                else if (cmd == "Recharge")
                {
                    int amount = int.Parse(cmdArg[2]);

                    if (hero.Mp + amount > mpMax)
                    {
                        amount  = mpMax - hero.Mp;
                        hero.Mp = mpMax;
                    }
                    else
                    {
                        hero.Mp += amount;
                    }

                    Console.WriteLine($"{hero.Name} recharged for {amount} MP!");
                }
                else if (cmd == "Heal")
                {
                    int amount = int.Parse(cmdArg[2]);

                    if (hero.Hp + amount > hpMax)
                    {
                        amount  = hpMax - hero.Hp;
                        hero.Hp = hpMax;
                    }
                    else
                    {
                        hero.Hp += amount;
                    }

                    Console.WriteLine($"{hero.Name} healed for {amount} HP!");
                }

                command = Console.ReadLine();
            }

            foreach (var hero in heroes.OrderByDescending(h => h.Hp).ThenBy(n => n.Name))
            {
                Console.WriteLine(hero);
            }
        }
Exemple #2
0
        static public void ChoiceInTown(Hero hero, Town town)
        {
            Program.code = 0; Program.menuItem = 1; Program.cursorPosition[0] = '>';
            do
            {
                Console.Clear();
                hero.PrintInfo();
                Console.WriteLine("\n  Вы находитесь в городе " + town.GetTownName);
                Console.Write("\n{0} Торговец\n{1} Библиотека\n{2} Выйти на охоту\n{3} Отправиться в другой город", Program.cursorPosition[0], Program.cursorPosition[1], Program.cursorPosition[2], Program.cursorPosition[3]);
                Program.code = Program.Cursor(4);
            } while (Program.code == 0);
            if (Program.code == 1)
            {
                Shop.PrintShop(hero, town);
            }
            else if (Program.code == 2)
            {
                Console.Clear();
                Console.WriteLine("\n  Библиотека");
                Console.WriteLine("\n\n  Тварь DMG [ ] HP [ ] GLD [ ]\n  Можно встретить на болоте и в лесу");
                Console.WriteLine("  Способность: ");
                Console.WriteLine("============================================================");
                Console.WriteLine("\n  Догнивающий DMG [ ] HP [ ] GLD [ ]\n  Втречаются в лесу и на пепелище");
                Console.WriteLine("  Мерзкое существо с горящими глазами, из пасти стекает черная субстанция");
                Console.WriteLine("  Способность: Отравление");
                Console.WriteLine("============================================================");
                Console.WriteLine("\n  Истлевший DMG [ ] HP [ ] GLD [ ]\n  Обитает на пепелище");
                Console.WriteLine("  Способность: Воспламенение");
                Console.WriteLine("============================================================");
                Console.WriteLine("\n  Пожиратель DMG [ ] HP [ ] GLD [ ]\n  Втречаются в лесу и на пепелище");
                Console.WriteLine("  Способности: Плевок, ");
                Console.WriteLine("============================================================");

                Console.ReadLine();
                Town.ChoiceInTown(hero, town);
            }
            else if (Program.code == 3)
            {
                Program.code = 0; Program.menuItem = 1; Program.cursorPosition[0] = '>';
                do
                {
                    Console.Clear();
                    hero.PrintInfo();
                    Console.WriteLine("\n  Выберете локацию:");
                    Console.Write("\n{0} Болото\n{1} Пепелище\n{2} Лес\n{3} Назад", Program.cursorPosition[0], Program.cursorPosition[1], Program.cursorPosition[2], Program.cursorPosition[3]);
                    Program.code = Program.Cursor(4);
                } while (Program.code == 0);
                if (Program.code == 1)
                {
                    Location location = new Location(LocationType.Swamp);
                    location.Battle(hero, town, location);
                }
                else if (Program.code == 2)
                {
                    Location location = new Location(LocationType.Pepel);
                    location.Battle(hero, town, location);
                }
                else if (Program.code == 3)
                {
                    Location location = new Location(LocationType.Forest);
                    location.Battle(hero, town, location);
                }
                else if (Program.code == 4)
                {
                    Town.ChoiceInTown(hero, town);
                }
            }
            else if (Program.code == 4)
            {
                Program.code = 0; Program.menuItem = 1; Program.cursorPosition[0] = '>';
                do
                {
                    Console.Clear();
                    Console.WriteLine("\n  Отправиться в\n");
                    Console.Write("\n{0} Денберг\n{1} Корберг", Program.cursorPosition[0], Program.cursorPosition[1]);
                    Program.code = Program.Cursor(2);
                } while (Program.code == 0);
                if (Program.code == 1)
                {
                    Town town1 = new Town(TownType.Denberg);
                    Town.ChoiceInTown(hero, town1);
                }
                else if (Program.code == 2)
                {
                    Town town1 = new Town(TownType.Qorberg);
                    Town.ChoiceInTown(hero, town1);
                }
            }
        }