public void BuyPotion() { //Display weapon list Console.Clear(); Console.WriteLine("----------------------------------------------------------------------------------------------"); Console.WriteLine("# Potions"); Console.WriteLine("----------------------------------------------------------------------------------------------"); Console.WriteLine(String.Format("{0,3} | {1,-25} | {2,-7} | {3,-7} |", "ID", "Name", "Healing", "Price")); Console.WriteLine("----------------------------------------------------------------------------------------------"); for (var i = 0; i < Potions.Count(); i++) { Console.WriteLine(String.Format("{0,3} | {1,-25} | {2,-7} | {3,-7} |", i + 1, Potions[i].Name, Potions[i].HealthRestored + " HP", Potions[i].Price + " Gold")); } Console.WriteLine("----------------------------------------------------------------------------------------------"); Console.WriteLine($"# You have {Hero.GoldCoin} Gold now!"); Console.WriteLine("----------------------------------------------------------------------------------------------"); Console.Write("# Select the Potion ID you want to buy : "); var KeyInput = Hero.GetUserInputNumber(); var shopPotion = Potions.ElementAtOrDefault(0); if (KeyInput > Potions.Count() || KeyInput <= 0) { Console.WriteLine("# Select the corrent Potion ID : "); shopPotion = null; } else { shopPotion = Potions.ElementAtOrDefault(KeyInput - 1); } if (shopPotion != null) { if ((Hero.GoldCoin - shopPotion.Price) >= 0) { Hero.PotionsBag.Add(shopPotion); Hero.GoldCoin = Hero.GoldCoin - shopPotion.Price; Console.WriteLine($"Buying '{shopPotion.Name}' is Completed!"); } else { Console.WriteLine("Sorry, you don't have enough Gold !"); } } else { Console.WriteLine("Sorry,No result!"); } Console.WriteLine("----------------------------------------------------------------------------------------------"); }
public void ShowInventory() { for (var i = 0; i < Weapons.Count(); i++) { Console.WriteLine($"W{i} - Name: {Weapons[i].Name} / Original Value: {Weapons[i].OriginalValue}"); buyProducts.Add($"W{i}", Weapons[i]); } for (var i = 0; i < Armors.Count(); i++) { Console.WriteLine($"A{i} - Name: {Armors[i].Name} / Original Value: {Armors[i].OriginalValue}"); buyProducts.Add($"A{i}", Armors[i]); } for (var i = 0; i < Potions.Count(); i++) { Console.WriteLine($"P{i} - Name: {Potions[i].Name} / Original Value: {Potions[i].OriginalValue}"); buyProducts.Add($"P{i}", Potions[i]); } Console.WriteLine("Buy item or return to menu"); Console.WriteLine("If you want to buy item, type the b"); Console.WriteLine("If you want to return to menu, type the r"); var choose = Console.ReadLine(); if (choose == "b") { Sell(); } else if (choose == "r") { Menu(); } else { Console.WriteLine("You type wrong letter. Please enter correct letter."); Console.WriteLine(""); Menu(); } }