jQuery in Action, 2nd edition*
The moose likes Game Development and the fly likes Beginner Trying Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Beginner Trying" Watch "Beginner Trying" New topic
Author

Beginner Trying

Pete Malis
Greenhorn

Joined: Dec 05, 2008
Posts: 3
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?");
return;
}

String itemCommand = command.getSecondWord();

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

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

// Try to take the item.
else
{
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);
outside.setExit("south",lab);
outside.setExit("west",pub);
theatre.setExit("west",outside);
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
cellar.addItem(sword);

}
Was wondering if anyone could help
Josh
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
So what structure are you using to store the objects inside the room's?
I.e. the what does addItem do with the item?
 
jQuery in Action, 2nd edition
 
subject: Beginner Trying
 
Similar Threads
Locked door help
Please help me do what I'm doing...but better.
Storing location in a text game
is it an array i need?
Null Pointer Exception