Ejemplo n.º 1
0
        public void UsePotion()
        {
            MakeYouStrong.Clear();
            Console.WriteLine("");
            Console.WriteLine("*****Potions*****");
            var countPotion = 1;

            foreach (var p in this.PotionsBag)
            {
                Console.WriteLine($"{countPotion}: {p.Name} that will give you {p.HP} HP");
                MakeYouStrong.Add($"{countPotion}", p);
                countPotion++;
                Console.WriteLine("Do you like to use Potion ? Press 1. to use");
            }

            if (MakeYouStrong.Count == 0)
            {
                Console.WriteLine("You have no potions to drink");
                ShowInventory();
            }
            else
            {
                var selection = Console.ReadLine();
                var potion    = (Potion)MakeYouStrong[selection];
                PotionsBag.Remove(potion);
                CurrentHP += potion.HP;
                Console.WriteLine("");
                Console.WriteLine("You are successful to use Potion your HP regen some");
            }
        }
Ejemplo n.º 2
0
 public void DrinkPotion(Potion NewPotion)
 {
     PotionsBag.Remove(NewPotion);
     this.CurrentHP += NewPotion.HP;
     Console.WriteLine($"You Drank {NewPotion.Name} for +{NewPotion.HP}HP");
     Console.WriteLine($"Your HP Is Now {this.CurrentHP}");
     ShowInventory();
 }
Ejemplo n.º 3
0
        public void UsingPotion()
        {
            var potionQuery = (from potion in PotionsBag
                               group potion by potion.Name into newGroup
                               select new
            {
                Name = newGroup.Key,
                Quantity = newGroup.Count()
            }).ToList();

            Console.WriteLine("----------------------------------------------------------------------------------------------");

            if (potionQuery.Count() != 0)
            {
                for (var i = 0; i < potionQuery.Count(); i++)
                {
                    Console.WriteLine($" {i + 1}. {potionQuery[i].Name} ({potionQuery[i].Quantity})");
                }

                Console.WriteLine("----------------------------------------------------------------------------------------------");
                Console.Write("Selet the potion to use: ");
                var KeyInput = GetUserInputNumber();

                //var pppotion = PotionsBag.ElementAtOrDefault(0);

                if (KeyInput > potionQuery.Count() || KeyInput <= 0)
                {
                    Console.WriteLine("Type corrent the potion ID !");
                }
                else
                {
                    var usingPotionQuery = (from potion in PotionsBag
                                            where potion.Name == potionQuery[KeyInput - 1].Name
                                            select potion).FirstOrDefault();


                    this.CurrentHP = this.CurrentHP + usingPotionQuery.HealthRestored;

                    if (this.CurrentHP > this.OriginalHP)
                    {
                        Console.WriteLine($"You don't need to drink potion at this point, You wasted ({this.CurrentHP - this.OriginalHP})! ");
                        this.CurrentHP = this.OriginalHP;
                    }

                    PotionsBag.Remove(usingPotionQuery);

                    Console.WriteLine($"Drink '{potionQuery[KeyInput - 1].Name}' successfully!");
                    Console.WriteLine("----------------------------------------------------------------------------------------------");
                }
            }
            else
            {
                Console.WriteLine($" You don't have any potion");
                Console.WriteLine("----------------------------------------------------------------------------------------------");
            }
        }