/** * Try to go to one direction. If there is an exit, enter the new * room, otherwise print an error message. */ private void goRoom(Command command) { if (!command.hasSecondWord()) { // if there is no second word, we don't know where to go... Console.WriteLine("Go where?"); return; } string direction = command.getSecondWord(); // Try to leave current room. Room nextRoom = user.currentRoom.getExit(direction); if (nextRoom == null) { Console.WriteLine("There is no door to " + direction + "!\n"); } else { if (user.inv.overweight == false) { if (nextRoom.locked != true) { user.damage(5); if (user.dead == true) { Console.WriteLine("\nYou seem to have died.\n better luck next time\n"); } else { if (nextRoom.roominv.slots == null) { Console.WriteLine("------------------\nYou're really bad at walking and trip,\nyour current health is " + user.health + ".\n"); user.currentRoom = nextRoom; Console.WriteLine(user.currentRoom.getLongDescription()); } else { Console.WriteLine("------------------\nYou're really bad at walking and trip,\nyour current health is " + user.health + ".\n"); for (int i = nextRoom.roominv.slots.Count - 1; i >= 0; i--) { Console.WriteLine("There seems to be a " + nextRoom.roominv.slots[i].name + " in this room, \nmaybe you want 'take' it with you!\n"); } user.currentRoom = nextRoom; Console.WriteLine(user.currentRoom.getLongDescription()); } } } else { Console.WriteLine("The Door to the " + nextRoom.roomname + " Seems to be locked, you should find a Key and 'use' it here"); } } else { Console.WriteLine("\nYou are carrying too much!\nYou should 'drop' something to continue.\n"); } } }
public override void use(Object obj) { if (obj.GetType() == typeof(Player)) { Player player = (Player)obj; // must cast Console.WriteLine("That was a solid donut, you lost all your teeth, that cost you 20 hp"); player.damage(20); } else { // Object o is not a Room Console.WriteLine("Can't use a Donut on Object " + obj.GetType()); } }