• Post Reply Bookmark Topic Watch Topic
  • New Topic

Beginner Trying  RSS feed

Pete Malis
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone

I am trying to put an object into a room and having a hard time figuring this out. Here is my coding to get the object, but only want it to take the sword if it is in the cellar...

* Try to take an item.If you just put take it will say, "Take what?" If there is an item take it, enter the name,
* example take sword, otherwise print an message saying the item is not here.
private void takeItem(Command command)

if(!command.hasSecondWord()) {
// if there is no second word, we don't know where to go...
System.out.println("Take what?");

String itemCommand = command.getSecondWord();

if(itemCommand.equals("sword")) {

System.out.println("The sword");

// Try to take the item.
System.out.println("There is no " + itemCommand + " here ok.");

here is my method in the same Game class to create the rooms and items

* Create all the rooms and link their exits together.
private void createRooms()
Room wakedup, path, outside, theatre, pub, lab, office, cellar, gym;

// create the rooms

wakedup = new Room("Begging of the path of river rocks. ");
path = new Room("You are on the path; you see an old looking town a head through the trees.");
outside = new Room("sign that says, �Welcome to the town of Grace Woods�.");
theatre = new Room("in a lecture theatre");
pub = new Room("in the campus pub");
lab = new Room("in a computing lab");
office = new Room("in the computing admin office");
cellar= new Room("in the cellar");
gym= new Room("in the gym");
// initialise room exits
wakedup.setExit("south", path);
path.setExit("south", outside);
outside.setExit("east", theatre);
pub.setExit("east", outside);
pub.setExit("down", gym);
gym.setExit("up", pub);
lab.setExit("north", outside);
lab.setExit("east", office);
office.setExit("west", lab);
office.setExit("down", cellar);
cellar.setExit("up", office);

currentRoom = wakedup; // start game outside

Item sword, shield, potion, immunity, money;

// Create the items to put in the game

sword = new Item("Sword to clear brush and kills the mutants in the town Grace Woods", 20, 10);
shield = new Item("To protect if the mutants touch you, they are radio active, lowers your immunity to die", 20, 10);
potion = new Item("This potion replenishes your health if you get hurt", 20, 10);
immunity = new Item("This ads points to your immunity", 0, 100);
money = new Item("To buy food to stay alive and other Items", 20, 10);
// add the items to the room intalization

Was wondering if anyone could help
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what structure are you using to store the objects inside the room's?
I.e. the what does addItem do with the item?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!