Well I want to lock rooms in my game, and only when a command such as 'use key' is executed, the room unlocks. How would I implement this in my game? Taking into account that if a room is locked I would not be able to enter it etc....
Here's my fields, consturctors and some methods for the class Game:
What coding would I need to implement just in the game class to get the locked rooms working?
{private Parser parser;
private Room currentRoom;
private ArrayList inventory;
private void createRooms()
{
Room Garden, Outside;
// create the rooms
Garden = new Room("you are in the garden");
Garden.addItem(new Item("cheese", 4));
Outside = new Room("you are now outside");
Outside.addItem(new Item("milk", 4));
Home.setExits("east", Dungen);
Bridge.setExits("west", Basement);
private boolean processCommand(Command command)
{
if(command.isUnknown())
{
System.out.println("I don't know what you mean...");
return false;
}
CommandWord action = command.getCommandWord();
if (action == CommandWord.HELP)
printHelp();
private void goRoom(Command command)
{
if(!command.hasSecondWord())
{
// if there is no second word, we don't know where to go...
System.out.println("Go where?");
return;
}
String direction = command.getSecondWord();
// Try to leave current room.
Room nextRoom = currentRoom.nextRoom(direction);
if (nextRoom == null)
System.out.println("There is no door!");
else
{
currentRoom = nextRoom;
System.out.println(currentRoom.longDescription());
}
}
If anyone else wants me to post some more code from the other classes then please reply doing so. Thanks!