// User selects enchant private void EnchantmentOption() { ObjectMenu <WeaponEnchantment> menu = new ObjectMenu <WeaponEnchantment>(shop.Enchantments, Status); WeaponEnchantment enchantment = menu.Run(); if (enchantment != null) { if (enchantment.Cost <= player.Gold) { ObjectMenu <Weapon> weaponMenu = new ObjectMenu <Weapon>(player.Inventory.Weapons, "Select weapon to enchant"); Weapon weapon = weaponMenu.Run(); if (weapon != null) { player.RemoveGold(enchantment.Cost); weapon.AddEnchantment(enchantment); } } else { Console.WriteLine(INSUFFCIENT_FUNDS_PROMPT); } } this.Run(); // Run this menu again }
// User selects potions private void PotionOption() { ObjectMenu <Potion> menu = new ObjectMenu <Potion>(player.Inventory.Potions, Status); Potion potion = menu.Run(); if (potion != null) { player.Inventory.RemoveItem(potion); player.AddGold(potion.Cost); } this.Run(); }
// User selects armours private void ArmourOption() { ObjectMenu <Armour> menu = new ObjectMenu <Armour>(player.Inventory.Armours, Status); Armour armour = menu.Run(); if (armour != player.EquippedArmour) { player.Inventory.RemoveItem(armour); player.AddGold(armour.Cost); } else { Console.WriteLine(EQUIPPED_ITEM_ERROR); // user has the item equipped } this.Run(); // run the menu again }
// User selects weapons private void WeaponOption() { ObjectMenu <Weapon> menu = new ObjectMenu <Weapon>(player.Inventory.Weapons, Status); Weapon weapon = menu.Run(); if (weapon != player.EquippedWeapon) { player.Inventory.RemoveItem(weapon); player.AddGold(weapon.Cost); } else { Console.WriteLine(EQUIPPED_ITEM_ERROR); // If the item is equipped } this.Run(); // Run the menu again }
// User selects Potions private void PotionOption() { ObjectMenu <Potion> menu = new ObjectMenu <Potion>(shop.Potions, Status); Potion potion = menu.Run(); if (potion != null) { if (potion.Cost <= player.Gold) { player.RemoveGold(potion.Cost); player.Inventory.AddItem(potion.Clone()); } else { Console.WriteLine(INSUFFCIENT_FUNDS_PROMPT); } } this.Run(); // Run the menu again }
// User selects Armours private void ArmourOption() { ObjectMenu <Armour> menu = new ObjectMenu <Armour>(shop.Armours, Status); Armour armour = menu.Run(); if (armour != null) { if (armour.Cost <= player.Gold) { player.RemoveGold(armour.Cost); player.Inventory.AddItem(armour.Clone()); } else { Console.WriteLine(INSUFFCIENT_FUNDS_PROMPT); } } this.Run(); // Run the menu again }
// Generic Item picker returns the item user selects private E ChooseItem <E>(List <E> list, string prompt) where E : Item { ObjectMenu <E> m = new ObjectMenu <E>(list, prompt); return(m.Run()); }