Пример #1
0
        public void Use(ref Player player)
        {
            int selection = -1;

            player.health = player.healthmax;
            while (selection != menu.Length)
            {
                selection = -1;
                Console.WriteLine($"\n{player.name}'s Gold: {player.coins}");
                Console.WriteLine($"Store's Gold: {coins}\n");
                Display();
                Console.Write("\t");
                for (int i = 0; i < menu.Length; i++)
                {
                    Console.Write($"{(i + 1)} {menu[i]}   ");
                }
                Console.WriteLine("");
                while (true)
                {
                    Console.Write("\tSelection: ");
                    string buffer = Console.ReadLine();
                    try
                    {
                        selection = Int32.Parse(buffer);
                    }
                    catch
                    {
                        buffer    = string.Empty;
                        selection = -1;
                    }
                    if (selection > 0 && selection <= menu.Length)
                    {
                        break;
                    }
                    Console.WriteLine("\n\tInvalid Selection");
                }

                if (selection == 1)
                {
                    Console.WriteLine("Which of my lovely wares is fitting of your impecable taste?");

                    string buffer = Console.ReadLine().ToLower();
                    if (buffer.Contains("rapier"))
                    {
                        if (player.coins >= rapier.cost)
                        {
                            Buy(rapier);
                            player.Buy(rapier);
                            Console.Clear();
                            Console.WriteLine($"You will be happy with that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("Oh! it seems you don't have enough coin to pay for that.");
                        }
                    }
                    else if (buffer.Contains("axe"))
                    {
                        if (player.coins >= axe.cost)
                        {
                            Buy(axe);
                            player.Buy(axe);
                            Console.Clear();
                            Console.WriteLine($"You will be happy with that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("Oh! it seems you don't have enough coin to pay for that.");
                        }
                    }
                    else if (buffer.Contains("club"))
                    {
                        if (player.coins >= club.cost)
                        {
                            Buy(club);
                            player.Buy(club);
                            Console.Clear();
                            Console.WriteLine($"You will be happy with that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("Oh! it seems you don't have enough coin to pay for that.");
                        }
                    }
                    else if (buffer.Contains("light"))
                    {
                        if (player.coins >= lhpotion.cost)
                        {
                            Buy(lhpotion);
                            player.Buy(lhpotion);
                            Console.Clear();
                            Console.WriteLine($"You will be happy with that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("Oh! it seems you don't have enough coin to pay for that.");
                        }
                    }
                    else if (buffer.Contains("moderate"))
                    {
                        if (player.coins >= mhpotion.cost)
                        {
                            Buy(mhpotion);
                            player.Buy(mhpotion);
                            Console.Clear();
                            Console.WriteLine($"You will be happy with that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("Oh! it seems you don't have enough coin to pay for that.");
                        }
                    }
                    else if (buffer.Contains("severe"))
                    {
                        if (player.coins >= shpotion.cost)
                        {
                            Buy(shpotion);
                            player.Buy(shpotion);
                            Console.Clear();
                            Console.WriteLine($"You will be happy with that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("Oh! it seems you don't have enough coin to pay for that.");
                        }
                    }
                    else if (buffer.Contains("elixir"))
                    {
                        if (player.coins >= hepotion.cost)
                        {
                            Buy(hepotion);
                            player.Buy(hepotion);
                            Console.Clear();
                            Console.WriteLine($"You will be happy with that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("Oh! it seems you don't have enough coin to pay for that.");
                        }
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("Invalid selection");
                    }
                }
                else if (selection == 2)
                {
                    player.DisplayInventory();
                    Console.WriteLine("Which item are you looking to part with?");
                    Console.Write("Selection: ");
                    string buffer = Console.ReadLine().ToLower();
                    if (buffer.Contains("rapier"))
                    {
                        if (coins >= rapier.cost)
                        {
                            player.Sell(rapier);
                            Sell(rapier);
                            Console.Clear();
                            Console.WriteLine($"Thank you for that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("I am sorry, but I cannot afford that item.");
                        }
                    }
                    else if (buffer.Contains("axe"))
                    {
                        if (coins >= axe.cost)
                        {
                            player.Sell(axe);
                            Sell(axe);
                            Console.Clear();
                            Console.WriteLine($"Thank you for that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("I am sorry, but I cannot afford that item.");
                        }
                    }
                    else if (buffer.Contains("club"))
                    {
                        if (coins >= club.cost)
                        {
                            player.Sell(club);
                            Sell(club);
                            Console.Clear();
                            Console.WriteLine($"Thank you for that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("I am sorry, but I cannot afford that item.");
                        }
                    }
                    else if (buffer.Contains("light"))
                    {
                        if (coins >= lhpotion.cost)
                        {
                            player.Sell(lhpotion);
                            Sell(lhpotion);
                            Console.Clear();
                            Console.WriteLine($"Thank you for that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("I am sorry, but I cannot afford that item.");
                        }
                    }
                    else if (buffer.Contains("moderate"))
                    {
                        if (coins >= mhpotion.cost)
                        {
                            player.Sell(mhpotion);
                            Sell(mhpotion);
                            Console.Clear();
                            Console.WriteLine($"Thank you for that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("I am sorry, but I cannot afford that item.");
                        }
                    }
                    else if (buffer.Contains("severe"))
                    {
                        if (coins >= shpotion.cost)
                        {
                            player.Sell(shpotion);
                            Sell(shpotion);
                            Console.Clear();
                            Console.WriteLine($"Thank you for that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("I am sorry, but I cannot afford that item.");
                        }
                    }
                    else if (buffer.Contains("elixir"))
                    {
                        if (coins >= hepotion.cost)
                        {
                            player.Sell(hepotion);
                            Sell(hepotion);
                            Console.Clear();
                            Console.WriteLine($"Thank you for that {buffer}");
                        }
                        else
                        {
                            Console.WriteLine("I am sorry, but I cannot afford that item.");
                        }
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("Invalid selection");
                    }
                }
                else if (selection == 3)
                {
                    Console.WriteLine("Which of my lovely wares has caught your eye?");

                    string buffer = Console.ReadLine().ToLower();
                    if (buffer.Contains("rapier"))
                    {
                        Console.Clear();
                        if (inventory.ContainsKey(rapier))
                        {
                            Console.WriteLine($"This {buffer} is a long pointed blade. It is the fastest weapon type but also has the weakest damage.");
                        }
                    }
                    else if (buffer.Contains("axe"))
                    {
                        Console.Clear();
                        if (inventory.ContainsKey(axe))
                        {
                            Console.WriteLine($"This {buffer} is a heavy splitting weapon. It is the slowest weapon type but also has the highest damage.");
                        }
                    }
                    else if (buffer.Contains("club"))
                    {
                        Console.Clear();
                        if (inventory.ContainsKey(club))
                        {
                            Console.WriteLine($"This {buffer} is a hefty blugeoning weapon. It is a well balance weapon with moderate speed and damage.");
                        }
                    }
                    else if (buffer.Contains("light"))
                    {
                        Console.Clear();
                        if (inventory.ContainsKey(rapier))
                        {
                            Console.WriteLine($"This {buffer} is a potion that restores 10 health.");
                        }
                    }
                    else if (buffer.Contains("moderate"))
                    {
                        Console.Clear();
                        if (inventory.ContainsKey(rapier))
                        {
                            Console.WriteLine($"This {buffer} is a potion that restores 25 health.");
                        }
                    }
                    else if (buffer.Contains("severe"))
                    {
                        Console.Clear();
                        if (inventory.ContainsKey(rapier))
                        {
                            Console.WriteLine($"This {buffer} is a potion that restores 50 health.");
                        }
                    }
                    else if (buffer.Contains("elixir"))
                    {
                        Console.Clear();
                        if (inventory.ContainsKey(rapier))
                        {
                            Console.WriteLine($"This {buffer} is a potion that restores 200 health.");
                        }
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("Invalid selection");
                    }
                }
                else if (selection == 4)
                {
                    Console.WriteLine($"So long for now {player.name}.");
                    Console.WriteLine("\n\n\n\t\t{Press any key to continue}");
                    Console.ReadKey();
                    break;
                }
            }
        }
Пример #2
0
        public void Fight(ref Player player, Enemy enemy)
        {
            pspeed = player.weapon.Speed();
            espeed = enemy.speed;
            Console.Clear();
            while (player.health > 0 && enemy.health > 0)
            {
                if (pspeed >= espeed)
                {
                    while (pspeed >= espeed)
                    {
                        Console.Write(player.Hitpoints());
                        Console.WriteLine("\t".PadRight(enemy.Condition().Length, '-'));
                        Console.Write('\t');
                        enemy.Display();
                        Console.Write('\t');
                        Console.WriteLine(enemy.Condition());
                        Console.WriteLine("\t".PadRight(enemy.Condition().Length, '-'));
                        while (true)
                        {
                            buffer = string.Empty;
                            Console.Write("\n\tWhat would you like to do:\t");
                            for (int i = 0; i < menu.Length; i++)
                            {
                                Console.Write($" {(i + 1)})  {menu[i]} ");
                            }
                            Console.WriteLine("");
                            buffer = Console.ReadLine();

                            try
                            {
                                selection = Int32.Parse(buffer);
                                break;
                            }
                            catch
                            {
                                buffer    = string.Empty;
                                selection = 0;
                            }
                        }
                        if (selection == 1)
                        {
                            Console.WriteLine($"\tYou strike {enemy.ename} with your {player.weapon.name} for {player.weapon.Attack()}");
                            Console.WriteLine("\n\t\t{Press any key to continue}");
                            Console.ReadKey();
                            enemy.health -= player.weapon.Attack();
                            if (enemy.health < 1)
                            {
                                break;
                            }
                            pspeed -= 10;
                            Console.Clear();
                        }
                        else if (selection == 2)
                        {
                            player.DisplayInventory();
                            string buffer = Console.ReadLine().ToLower();
                            if (buffer.Contains("light"))
                            {
                                player.Heal(lhpotion);
                            }
                            else if (buffer.Contains("moderate"))
                            {
                                player.Heal(mhpotion);
                            }
                            else if (buffer.Contains("severe"))
                            {
                                player.Heal(shpotion);
                            }
                            else if (buffer.Contains("elixer"))
                            {
                                player.Heal(hepotion);
                            }
                            else
                            {
                                Console.WriteLine("You can't do that during combat!");
                            }
                        }
                        else if (selection == 3)
                        {
                            Console.Clear();
                            break;
                        }
                    }
                }
                if (selection == 3 && pspeed > espeed)
                {
                    break;
                }

                while (espeed > pspeed)
                {
                    Console.WriteLine(player.Hitpoints());
                    Console.Write('\t');
                    enemy.Display();
                    Console.Write('\t');
                    Console.WriteLine(enemy.Condition());
                    Console.WriteLine($"\t{enemy.ename} hits you for {enemy.damage}");
                    player.health -= enemy.damage;
                    espeed        -= 10;
                    Console.WriteLine("\n\t\t{Press any key to continue}");
                    Console.ReadKey();
                }
            }
            if (selection == 3)
            {
                Console.WriteLine("You successfully ran away");
            }
            else if (player.health < 1)
            {
                Console.WriteLine("You have died");
            }
            else
            {
                Console.WriteLine("\n\tCongratulations on your well earned victory");
                Console.WriteLine($"\n\tYou have earned {enemy.experience} experience and {enemy.coins} coins.");
                player.experience += enemy.experience;
                player.Level();
                player.coins += enemy.coins;
            }
        }