Esempio n. 1
0
        static void Game(bool newgame)
        {
            Potion PotionHP10   = new Potion("Lesser potion of heal [+10 HP]", 40, 20, 10);
            Potion PotionHP20   = new Potion("Medium potion of heal [+20 HP]", 50, 15, 20);
            Potion PotionHP30   = new Potion("Great potion of heal [+30 HP]", 100, 10, 30);
            Weapon Sword        = new Weapon("Sword [+2 hit] | [+2 damage]", 300, 1, 2, 2);
            Armor  LeatherArmor = new Armor("Leather armor [+4 armor]", 350, 1, 4, 0);

            int    selectedAction;
            Random random = new Random();

            Character PlayerFighter = new Character();

            while (PlayerFighter.CharacterName.Length < 3 || PlayerFighter.CharacterName.Length > 10 || string.IsNullOrWhiteSpace(PlayerFighter.CharacterName))
            {
                Console.Write("Please, enter your Name [3-10 symbols]: ");
                PlayerFighter.CharacterName = Console.ReadLine().Trim();
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                if (string.IsNullOrWhiteSpace(PlayerFighter.CharacterName))
                {
                    Console.WriteLine("String is empty!");
                }
                else if (PlayerFighter.CharacterName.Length > 10)
                {
                    Console.WriteLine("Your name is to long!");
                }
                else if (PlayerFighter.CharacterName.Length < 3)
                {
                    Console.WriteLine("Your name is to short!");
                }
                Console.ResetColor();
            }
ChangeClass:
            Console.WriteLine("Greatings, " + PlayerFighter.CharacterName + "!" + System.Environment.NewLine + System.Environment.NewLine + "Choose your class:");
            selectedAction = MultipleChoice(Console.CursorTop, "Warrior", "Barbarian", "Bard", "Paladin");
            Choose(selectedAction, PlayerFighter, random);

            int fullHp = PlayerFighter.Hp;
            int level  = 0;

            string[] names = { "Wardrich", "Tinedon", "Keken", "Gwinlin", "Ren mini BOSS", "Vupsen` & Pupsen`", "Nagibator2000", "Losdral", "Bornaz", "Dielriel BOSS" };
            for (int round = 1; round <= 10 && again && PlayerFighter.FightResult; round++)
            {
                Character EnemyFighter = new Character();
                EnemyFighter.CharacterName = names[round - 1];
                Console.ForegroundColor    = ConsoleColor.Green;
                Choose(random.Next(0, 4), EnemyFighter, random);

                if (round == 5)
                {
                    level += 2;
                    EnemyFighter.AttackClass += level;
                    EnemyFighter.ArmorClass  += level;
                    EnemyFighter.Gold        *= 3;
                }
                else if (round == 10)
                {
                    level += 5;
                    EnemyFighter.AttackClass += level;
                    EnemyFighter.ArmorClass  += level;
                    EnemyFighter.Gold        *= 10;
                }

                ShowStat(PlayerFighter, ConsoleColor.Green, "You: ");
                ShowStat(EnemyFighter, ConsoleColor.Red, "Enemy: ");

                PlayerFighter.Initiative = random.Next(1, 21);
                EnemyFighter.Initiative  = random.Next(1, 21);

                FightMechanic(PlayerFighter, EnemyFighter, random, round, fullHp, PotionHP10, PotionHP20, PotionHP30);
                OutputResult(PlayerFighter, EnemyFighter, round);
                PlayerFighter.Hp = fullHp;

                if (PlayerFighter.FightResult)
                {
startLoop:
                    Console.WriteLine(System.Environment.NewLine + "Choose:");
                    selectedAction = MultipleChoice(Console.CursorTop, "Next round", "Shop", "Exit");
                    switch (selectedAction)
                    {
                    case 0:
                        continue;

                    case 1:
shop:
                        Console.Clear();
                        Console.WriteLine(
                            "Gold: " + PlayerFighter.Gold +
                            " | Potions[+10]: " + PlayerFighter.PotionHP10 +
                            " | Potions[+20]: " + PlayerFighter.PotionHP20 +
                            " | Potions[+30]: " + PlayerFighter.PotionHP30 + System.Environment.NewLine
                            );
                        Console.WriteLine("Choose a product:");
                        selectedAction = MultipleChoice(
                            Console.CursorTop,
                            "Back",
                            "(" + PlayerFighter.Gold / PotionHP10.Price + ") " + PotionHP10.Name + " - " + PotionHP10.Price,
                            "(" + PlayerFighter.Gold / PotionHP20.Price + ") " + PotionHP20.Name + " - " + PotionHP20.Price,
                            "(" + PlayerFighter.Gold / PotionHP30.Price + ") " + PotionHP30.Name + " - " + PotionHP30.Price,
                            "(" + PlayerFighter.Gold / Sword.Price + ") " + Sword.Name + " - " + Sword.Price,
                            "(" + PlayerFighter.Gold / LeatherArmor.Price + ") " + LeatherArmor.Name + " - " + LeatherArmor.Price
                            );
                        bool smth;
                        switch (selectedAction)
                        {
                        case 0:
                            goto startLoop;

                        case 1:
                            smth = Shop(PlayerFighter, PotionHP10);
                            if (smth)
                            {
                                PlayerFighter.PotionHP10 += 1;
                            }
                            goto shop;

                        case 2:
                            smth = Shop(PlayerFighter, PotionHP20);
                            if (smth)
                            {
                                PlayerFighter.PotionHP20 += 1;
                            }
                            goto shop;

                        case 3:
                            smth = Shop(PlayerFighter, PotionHP30);
                            if (smth)
                            {
                                PlayerFighter.PotionHP30 += 1;
                            }
                            goto shop;

                        case 4:
                            smth = Shop(PlayerFighter, Sword);
                            if (smth)
                            {
                                PlayerFighter.HitClass    += Sword.Hit;
                                PlayerFighter.AttackClass += Sword.Damage;
                            }
                            goto shop;

                        case 5:
                            smth = Shop(PlayerFighter, LeatherArmor);
                            if (smth)
                            {
                                PlayerFighter.ArmorClass += LeatherArmor.ArmorPhysical;
                            }
                            goto shop;
                        }
                        break;

                    case 2:
                        newgame = false;
                        Main();
                        break;
                    }
                    Console.Clear();
                }
                else
                {
                    Console.WriteLine(System.Environment.NewLine + "Choose:");
                    selectedAction = MultipleChoice(Console.CursorTop, "Repeat", "Change class", "Exit");
                    switch (selectedAction)
                    {
                    case 0:
                        round = 0;
                        PlayerFighter.FightResult = true;
                        continue;

                    case 1:
                        PlayerFighter.FightResult = true;
                        goto ChangeClass;

                    case 2:
                        newgame = false;
                        Main();
                        break;
                    }
                    Console.Clear();
                }
                Console.Clear();
            }
        }
Esempio n. 2
0
        static void FightMechanic(Character PlayerFighter, Character EnemyFighter, Random random, int round, int fullHp, Potion PotionHP10, Potion PotionHP20, Potion PotionHP30)
        {
            if (PlayerFighter.Initiative > EnemyFighter.Initiative)
            {
                Console.WriteLine(System.Environment.NewLine + PlayerFighter.CharacterName + " " + PlayerFighter.CharacterClass + " start fight first" + System.Environment.NewLine);
                Console.WriteLine(System.Environment.NewLine + "Press Enter to start");

                ConsoleKey key;
                do
                {
                    key = Console.ReadKey(true).Key;
                } while (key != ConsoleKey.Enter);

                Console.Clear();
                string roundString = "====================ROUND " + (round) + "====================";
                Console.SetCursorPosition((Console.WindowWidth - roundString.Length) / 2, Console.CursorTop);
                Console.WriteLine(roundString + System.Environment.NewLine);
                while (PlayerFighter.Hp > 0)
                {
                    string s        = PlayerFighter.Hp + " HP | " + EnemyFighter.Hp + " HP";
                    string PlayerHP = new string('|', PlayerFighter.Hp);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write(PlayerHP);
                    Console.ResetColor();
                    Console.SetCursorPosition((Console.WindowWidth - s.Length) / 2, Console.CursorTop);
                    Console.Write(s);
                    string EnemyHP = new string('|', EnemyFighter.Hp);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(EnemyHP);
                    Console.ResetColor();

                    Console.WriteLine(System.Environment.NewLine + "Choose your action:");
                    int selectedAction = MultipleChoice(
                        Console.CursorTop, "Attack", "(" + PlayerFighter.PotionHP10 + ")Potion [+10]",
                        "(" + PlayerFighter.PotionHP20 + ") Potion [+20]",
                        "(" + PlayerFighter.PotionHP30 + ") Potion [+30]"
                        );
                    bool potion;
                    switch (selectedAction)
                    {
                    case 0:
                        Damage(PlayerFighter, EnemyFighter, random);
                        if (EnemyFighter.Hp > 0)
                        {
                            Damage(EnemyFighter, PlayerFighter, random);
                        }
                        else
                        {
                            Console.WriteLine(EnemyFighter.CharacterName + " " + EnemyFighter.CharacterClass + " is dead.");
                            EnemyFighter.FightResult = false;
                            return;
                        }
                        break;

                    case 1:
                        potion = CheckPotions(PlayerFighter, PlayerFighter.PotionHP10, fullHp, PotionHP10.HP);
                        if (potion)
                        {
                            PlayerFighter.PotionHP10 -= 1;
                        }
                        else
                        {
                            break;
                        }
                        Damage(EnemyFighter, PlayerFighter, random);
                        break;

                    case 2:
                        potion = CheckPotions(PlayerFighter, PlayerFighter.PotionHP20, fullHp, PotionHP20.HP);
                        if (potion)
                        {
                            PlayerFighter.PotionHP20 -= 1;
                        }
                        else
                        {
                            break;
                        }
                        Damage(EnemyFighter, PlayerFighter, random);
                        break;

                    case 3:
                        potion = CheckPotions(PlayerFighter, PlayerFighter.PotionHP30, fullHp, PotionHP30.HP);
                        if (potion)
                        {
                            PlayerFighter.PotionHP30 -= 1;
                        }
                        else
                        {
                            break;
                        }
                        Damage(EnemyFighter, PlayerFighter, random);
                        break;
                    }
                }
                Console.WriteLine(PlayerFighter.CharacterName + " " + PlayerFighter.CharacterClass + " is dead");
                PlayerFighter.FightResult = false;
            }
            else
            {
                Console.WriteLine(System.Environment.NewLine + EnemyFighter.CharacterName + " " + EnemyFighter.CharacterClass + " start fight first" + System.Environment.NewLine);
                Console.WriteLine(System.Environment.NewLine + "Press Enter to start");
                ConsoleKey key;
                do
                {
                    key = Console.ReadKey(true).Key;
                } while (key != ConsoleKey.Enter);
                Console.Clear();
                string roundString = "====================ROUND " + (round) + "====================";
                Console.SetCursorPosition((Console.WindowWidth - roundString.Length) / 2, Console.CursorTop);
                Console.WriteLine(roundString + System.Environment.NewLine);

                while (EnemyFighter.Hp > 0)
                {
                    Damage(EnemyFighter, PlayerFighter, random);
                    if (PlayerFighter.Hp <= 0)
                    {
                        Console.WriteLine(PlayerFighter.CharacterName + " " + PlayerFighter.CharacterClass + " is dead");
                        PlayerFighter.FightResult = false;
                        return;
                    }

battle:
                    string s = PlayerFighter.Hp + " HP | " + EnemyFighter.Hp + " HP";
                    string PlayerHP = new string('|', PlayerFighter.Hp);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write(PlayerHP);
                    Console.ResetColor();
                    Console.SetCursorPosition((Console.WindowWidth - s.Length) / 2, Console.CursorTop);
                    Console.Write(s);
                    string EnemyHP = new string('|', EnemyFighter.Hp);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(EnemyHP);
                    Console.ResetColor();

                    Console.WriteLine(System.Environment.NewLine + "Choose your action:");
                    int selectedAction = MultipleChoice(
                        Console.CursorTop, "Attack", "(" + PlayerFighter.PotionHP10 + ")Potion [+10]",
                        "(" + PlayerFighter.PotionHP20 + ") Potion [+20]",
                        "(" + PlayerFighter.PotionHP30 + ") Potion [+30]"
                        );
                    bool potion;
                    switch (selectedAction)
                    {
                    case 0:
                        Damage(PlayerFighter, EnemyFighter, random);
                        if (EnemyFighter.Hp <= 0)
                        {
                            Console.WriteLine(EnemyFighter.CharacterName + " " + EnemyFighter.CharacterClass + " is dead.");
                            EnemyFighter.FightResult = false;
                            return;
                        }
                        break;

                    case 1:
                        potion = CheckPotions(PlayerFighter, PlayerFighter.PotionHP10, fullHp, PotionHP10.HP);
                        if (potion)
                        {
                            PlayerFighter.PotionHP10 -= 1;
                        }
                        else
                        {
                            goto battle;
                        }
                        Damage(EnemyFighter, PlayerFighter, random);
                        break;

                    case 2:
                        potion = CheckPotions(PlayerFighter, PlayerFighter.PotionHP20, fullHp, PotionHP20.HP);
                        if (potion)
                        {
                            PlayerFighter.PotionHP20 -= 1;
                        }
                        else
                        {
                            goto battle;
                        }
                        Damage(EnemyFighter, PlayerFighter, random);
                        break;

                    case 3:
                        potion = CheckPotions(PlayerFighter, PlayerFighter.PotionHP30, fullHp, PotionHP30.HP);
                        if (potion)
                        {
                            PlayerFighter.PotionHP30 -= 1;
                        }
                        else
                        {
                            goto battle;
                        }
                        Damage(EnemyFighter, PlayerFighter, random);
                        break;
                    }
                }
                Console.WriteLine(EnemyFighter.CharacterName + " " + EnemyFighter.CharacterClass + " is dead.");
                EnemyFighter.FightResult = false;
            }
        }