public void BuyHealthPotion(ref Player player, ref HealthPotion hp) { if (player.GetGold() > 10) { player.SetGold(-10); player.PickupItem(hp); player.ShowInventory(); } else { Console.WriteLine("You don't have enough gold!"); } }
public void ShowShop(ref Player player) { Console.Clear(); List <object> shop = new List <object>(); HealthPotion hp = new HealthPotion("Health Potion", true); object[] healthpotion = new object[3]; healthpotion[0] = hp; healthpotion[1] = "Health Potion"; healthpotion[2] = 1; shop.Add(healthpotion); BuyShop(ref player, ref healthpotion, ref shop, ref hp); }
public void BuyShop(ref Player player, ref object[] healthpotion, ref List <object> shop, ref HealthPotion hp) { string input; Console.WriteLine("Rik: 'Welcome to my shop!'"); Console.WriteLine("Rik: 'Here you can buy anything you see below!'"); Console.WriteLine("{0}) {1} {2}", 1, healthpotion[1], healthpotion[2]); Console.WriteLine("2) Make Rik go away!"); do { input = Console.ReadLine(); if (input != "1" && input != "2") { Console.WriteLine("Please select a number between 1 and 2"); } } while (input != "1" && input != "2"); if (input == "1") { BuyHealthPotion(ref player, ref hp); } }
static void Start(ref Map map, ref Player player) { Rik rik = new Rik("Rik", 10000, 10000); BloodDrake blooddrake = new BloodDrake("Blood Drake", 50, 10); AngryMan angryman = new AngryMan("Angry Man", 70, 10); CastleBoss boss = new CastleBoss("Castle Boss", 250, 10); List <string> menuItems = new List <string>(); int choice; rik.EncounterRik(); // Refactored by Michiel and Alex do { Console.Clear(); map.GetLocation().Description(); choice = ShowMenu(map, ref menuItems, ref player, ref blooddrake, ref angryman); if (choice != menuItems.Count()) { if (validDirections.Contains(menuItems[choice])) { map.Move(menuItems[choice]); } switch (menuItems[choice]) { case ACTION_SEARCH: // Add code to perform an item pickup break; case ACTION_FIGHT: // Add code for fighting here break; case ACTION_RUN: // Add code for running here break; case ACTION_SHOWINVENTORY: player.ShowInventory(); Console.ReadLine(); choice = 0; break; case ACTION_SHOP: Shop shop = new Shop(); shop.ShowShop(ref player); choice = 0; Console.ReadLine(); break; case "Fight the Blood Drake": Console.Clear(); blooddrake.StartEncouter(ref player, ref map); Console.ReadLine(); map.Move("Go North"); break; case "Go via the side of the bridge": Console.Clear(); player.ClimbBridge(ref player); Console.ReadLine(); map.Move("Go North"); break; case ACTION_USEHEALTHPOTION: HealthPotion hp = new HealthPotion("Health Potion", true); hp.UsePotion(ref player); choice = 0; break; case "Fight the man": Console.Clear(); angryman.StartEncounter(ref player, ref map); Console.ReadLine(); break; case "Leave the man": Console.Clear(); map.Move("Go West"); Console.ReadLine(); break; case "Climb over the wall": map.Move("Go North"); break; case "Fight the Boss": Console.Clear(); boss.StartEncounter(ref player); Console.ReadLine(); break; } } } // When the choice is equal to the total item it means exit has been chosen. while (choice < menuItems.Count() - 1); }