Example #1
0
        /*
         * ========================================================================================
         * HeroTurn ---> Calculate the damage that will be dealt to the currentMonster
         * ========================================================================================
         */
        private void UseHealthPotion()
        {
            Console.Clear();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("******* Your Health Potions *******");
            Console.ResetColor();

            List <HealthPotion> healthPotions = Hero.HealthPotionBag.ToList();

            if (healthPotions.Any())
            {
                for (int i = 1; i < healthPotions.Count + 1; i++)
                {
                    Console.WriteLine($"{i}. {healthPotions[i - 1].Name} --> (+ {healthPotions[i - 1].HealAmount} HP)");
                }

                bool isNumber = int.TryParse(Console.ReadLine().Trim(), out int userIndex);

                // account for index offset of 1
                userIndex--;

                if (!isNumber || (userIndex < 0 || userIndex >= healthPotions.Count))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Nothing was used because of one of the following errors:");
                    Console.WriteLine("- did not input a number");
                    Console.WriteLine("- inputted number was too small");
                    Console.WriteLine("- inputted number was too big");
                    Console.ResetColor();
                    return;
                }
                else
                {
                    if (Hero.CurrentHP >= Hero.OriginalHP)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Sorry you can't heal past you Original HP\n");
                        Console.ResetColor();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine($"You used your {healthPotions[userIndex].Name}!");
                        Console.ResetColor();

                        Hero.UseHealthPotion(userIndex);
                    }
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("You have nothing to use. . .");
                Console.ResetColor();
            }
        }
Example #2
0
        public static void UseHealthPotion(Hero Hero)
        {
            Console.Clear();
            UI.DefaultBoxes.DrawManageInventory(Hero, UI.Grid.Left, Items.GetListOfItems(Hero.Bag, typeof(Potion)));
            var potionUseInput = "";

            // Check hero HP first, maybe they're already at full health..
            if (Hero.CurrentHP == Hero.OriginalHP)
            {
                Console.Clear();
                UI.DefaultBoxes.DrawManageInventory(Hero, UI.Grid.Left, Items.GetListOfItems(Hero.Bag, typeof(Potion)));
                UI.DefaultBoxes.DrawOptions(new List <string> {
                    "Press any key to return to Inventory."
                }, UI.Grid.Center);
                UI.Draw.PrintToOutput(new List <string>
                {
                    "You're already at full HP! "
                });
                UI.Draw.UpdateInputCursor();
                Console.ReadKey();
            }
            else
            {
                // Check if they have potions in their inventory.
                if (Items.GetListOfItems(Hero.Bag, typeof(Potion)).Any())
                {
                    UI.DefaultBoxes.DrawOptions(new List <string>
                    {
                        "Choose an item to use number to use!",
                        "Press 0 to return to main menu."
                    }, UI.Grid.Center);
                    UI.Draw.UpdateInputCursor();

                    potionUseInput = Console.ReadLine();

                    while (!int.TryParse(potionUseInput, out int _x))
                    {
                        Console.WriteLine("That is not a number, please choose again.");
                        potionUseInput = Console.ReadLine();
                    }

                    // If the input can be parsed as a number
                    Console.Clear();
                    UI.DefaultBoxes.DrawManageInventory(Hero, UI.Grid.Left, Items.GetListOfItems(Hero.Bag, typeof(Potion)));
                    if (int.TryParse(potionUseInput, out int potionIndex) && potionIndex != 0)
                    {
                        // If the number is an index of health potion bag
                        if ((potionIndex -= 1) <= Items.GetListOfItems(Hero.Bag, typeof(Potion)).Count - 1)
                        {
                            // Then use that potion
                            Hero.UseHealthPotion(potionIndex);
                            UI.Draw.PrintToOutput(new List <string>
                            {
                                "Item used!",
                                $"Your HP is now {Hero.CurrentHP}/{Hero.OriginalHP}"
                            });
                        }
                        else
                        {
                            UI.Draw.PrintToOutput(new List <string>
                            {
                                "There's no potion with that number..."
                            });
                        }
                        UI.DefaultBoxes.DrawOptions(new List <string> {
                            "Press any key to return to Inventory."
                        }, UI.Grid.Center);
                        UI.Draw.UpdateInputCursor();
                        Console.ReadKey();
                    }
                }
                else
                {
                    Console.Clear();
                    UI.DefaultBoxes.DrawManageInventory(Hero, UI.Grid.Left, Items.GetListOfItems(Hero.Bag, typeof(Potion)));
                    UI.DefaultBoxes.DrawOptions(new List <string> {
                        "Press any key to return to Inventory."
                    }, UI.Grid.Center);
                    UI.Draw.PrintToOutput(new List <string>
                    {
                        "You don't have any health potions... ",
                        "Go buy some from the store!"
                    });
                    UI.Draw.UpdateInputCursor();
                    Console.ReadKey();
                }
            }
        }
Example #3
0
        public void Start()
        {
            while (Enemy.CurrentHP > 0 && Hero.CurrentHP > 0)
            {
                Console.WriteLine("You've encountered a " + Enemy.Name + "! " + Enemy.Strength + " Strength/" + Enemy.Defense + " Defense/" +
                                  Enemy.CurrentHP + " HP. What will you do?");

                Console.WriteLine("1. Fight");
                Console.WriteLine("2. Heal");
                Console.WriteLine("3. Run!!");

                var input = Console.ReadLine();

                if (input == "1")
                {
                    HeroTurn();
                }
                else if (input == "2")
                {
                    Console.WriteLine("Please choose the potion to heal with by entering a number.");
                    int i;
                    for (i = 0; i < Hero.PotionBag.Count(); i++)
                    {
                        Console.WriteLine($"{i + 1} {Hero.PotionBag[i].Name} of {Hero.PotionBag[i].HealthRestored} Health");
                    }

                    input = Console.ReadLine();
                    var inputNumber = Int32.Parse(input) - 1;
                    Hero.UseHealthPotion(inputNumber);
                }
                else if (input == "3")
                {
                    var chanceToRun = 0;
                    if (Enemy.Dificulty == MonsterDificulty.Easy)
                    {
                        chanceToRun = RandNum.Next(1, 3);
                        if (chanceToRun == 1)
                        {
                            HeroTurn();
                        }
                        else
                        {
                            Console.WriteLine("You get to live another day!!");
                            return;
                        }
                    }
                    else if (Enemy.Dificulty == MonsterDificulty.Medium)
                    {
                        chanceToRun = RandNum.Next(1, 5);
                        if (chanceToRun == 1)
                        {
                            HeroTurn();
                        }
                        else
                        {
                            Console.WriteLine("You get to live another day!!");
                            return;
                        }
                    }
                    else if (Enemy.Dificulty == MonsterDificulty.Hard)
                    {
                        chanceToRun = RandNum.Next(1, 21);
                        if (chanceToRun == 1)
                        {
                            HeroTurn();
                        }
                        else
                        {
                            Console.WriteLine("You get to live another day!!");
                            return;
                        }
                    }
                }
            }
        }