Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Implementing locked rooms in my java game

807591Mar 5 2008 — edited Mar 7 2008
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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 4 2008
Added on Mar 5 2008
7 comments
698 views