///<summary> ///No need to Pass a room since Items can only be used in the CurrentRoom ///Make sure you validate the item is in the room or player inventory before ///being able to use the item ///</summary> public void UseItem(string itemName) { //Found IItem //if item from inventory //else if not try from room list //if still not cant use //return //RoomItemUse //GlobalItemUse IRoom room = _game.CurrentRoom; if (room is TrapRoom) { // IItem found = _game.CurrentPlayer.Inventory.Find(itemName); // var itemm = _game.CurrentPlayer.Inventory.IndexOf(itemName as Item); for (int i = 0; i < _game.CurrentPlayer.Inventory.Count; i++) { var item = _game.CurrentPlayer.Inventory[i]; if (item.Name.ToLower() == itemName) { TrapRoom trap = (TrapRoom)room; trap.UseItem(item); Messages.Add(trap.UseItem(item)); // _game.CurrentPlayer.Inventory.Remove(item); Messages.Add($"Used your {item.Name}"); return; } } { Messages.Add("Invalid Item"); } } else if (room is SafeTrapRoom) { for (int i = 0; i < _game.CurrentPlayer.Inventory.Count; i++) { var item = _game.CurrentPlayer.Inventory[i]; if (item.Name.ToLower() == itemName) { SafeTrapRoom trap = (SafeTrapRoom)room; Messages.Add(trap.UseItem(item)); // _game.CurrentPlayer.Inventory.Remove(item); Messages.Add($"Used your {item.Name}"); return; } } { Messages.Add("Invalid Item"); } } else if (room is ThroneRoom) { for (int i = 0; i < _game.CurrentPlayer.Inventory.Count; i++) { var item = _game.CurrentPlayer.Inventory[i]; if (item.Name.ToLower() == itemName) { ThroneRoom winningRoom = (ThroneRoom)room; Messages.Add(winningRoom.UseItem(item)); return; } } { Messages.Add("Invalid Item"); } } else { for (int i = 0; i < _game.CurrentPlayer.Inventory.Count; i++) { var item = _game.CurrentPlayer.Inventory[i]; if (item.Name.ToLower() == itemName) { Messages.Add($"Used your {item.Name} but it has little effect here."); return; } } { Messages.Add("Invalid Item"); } } }
//NOTE Make yo rooms here... public void Setup() { IRoom start = new Room("An Unknown Room", "You come to your senses in a pile of your own vomit."); IRoom two = new Room("Outside", "To your north you hear a loud ruckus but to your west you see somebody disappear down a sewage lid."); IRoom three = new TrapRoom("Pub", "The bar is very crowded but there is an open spot off to the side"); IRoom four = new TrapRoom("Hidden Tunnel", "There is ancient markings on the walls of this poorly lit corridor the only way to advance is north."); IRoom five = new Room("Courtyard", "You see large arch doors to your north but a smaller normal door to your west."); IRoom six = new TrapRoom("Jailor", "You walk into the room to see a group of guards sitting around a table looking up at you."); IRoom seven = new SafeTrapRoom("Dark Hallway", $@" You enter the arch doors to a long dark hallway. Do you dare go north?"); IRoom eight = new ThroneRoom("Throne Room", "There is the Iron Throne with nobody to claim it... Do you dare sit in the throne"); IRoom nine = new TrapRoom("Kings Room", "The King is sleeping with his Crown tucked under his arms.... "); start.AddRoomConnection(two, "west"); two.AddRoomConnection(start, "east"); two.AddRoomConnection(three, "north"); three.AddRoomConnection(two, "south"); two.AddRoomConnection(four, "west"); four.AddRoomConnection(two, "east"); four.AddRoomConnection(five, "north"); five.AddRoomConnection(four, "south"); five.AddRoomConnection(six, "west"); six.AddRoomConnection(five, "east"); five.AddRoomConnection(seven, "north"); seven.AddRoomConnection(five, "south"); seven.AddRoomConnection(eight, "north"); eight.AddRoomConnection(seven, "south"); nine.AddRoomConnection(seven, "east"); seven.AddRoomConnection(nine, "west"); eight.AddRoomConnection(start, "secret"); Item sword = new Item("Sword", "Big long sword"); Item drink = new Item("Ale", "Biggest container of beer you've ever seen."); Item torch = new Item("Torch", "Used to light even the darkest of places."); Item crown = new Item("Crown", "Fit for a king"); Item test = new Item("Key", "This must open something important"); start.Items.Add(sword); three.Items.Add(drink); four.Items.Add(torch); nine.Items.Add(crown); seven.Items.Add(test); (seven as SafeTrapRoom).addUnlockable(test); (four as TrapRoom).addUnlockable(torch); (six as TrapRoom).addUnlockable(sword); (three as TrapRoom).addUnlockable(drink); (eight as ThroneRoom).addUnlockable(crown); CurrentRoom = start; }