intializing code

we have some code and when i try to compile it i get a few problems, some of the current code for this class is:

publicclass Game

{

private Parser parser;

private Player player;

private Room currentRoom, previousRoom;

private String playerName;

privateint number;

/**

* Create the game and initialise its internal map.

*/

public Game()

{

createRooms();

parser =new Parser();

previousRoom = currentRoom;

player =new Player(20, 0);

}

/**

* Create all the rooms and link their exits together.

*/

privatevoid createRooms()

{

Room home, registry, route, weatherspoons, union, burgerVan,

trafalgar, oneEyedDog, theHonestPolitician, fuzzyDuck, tesco;

// create the rooms

theHonestPolitician =new Room("in the the Honest Politician", 0);

registry =new Room("in the Registry", 1);

oneEyedDog =new Room("in the One Eyed Dog", 2);

weatherspoons =new Room("in Wetherspoons", 3);

fuzzyDuck =new Room("in the Fuzzy Duck", 4);

route =new Room("in Route 66", 5);

trafalgar =new Room("in the Trafalgar Arms", 6);

union =new Room("in the Union", 7);

burgerVan =new Room("at a Burger Van", 8);

tesco =new Room("at Tesco", 9);

home =new Room("at home", 10);

currentRoom = home;// start game home

// initialise room exits

home.setExit("north", registry);

home.setExit("east", weatherspoons);

home.setExit("south", route);

home.setExit("west", tesco);

registry.setExit("south", home);

registry.setExit("west", theHonestPolitician);

registry.setExit("east", oneEyedDog);

oneEyedDog.setExit("west", registry);

theHonestPolitician.setExit("east", registry);

tesco.setExit("east", home);

weatherspoons.setExit("west", home);

weatherspoons.setExit("east", fuzzyDuck);

fuzzyDuck.setExit("west", weatherspoons);

route.setExit("west", union);

route.setExit("east", trafalgar);

route.setExit("south", burgerVan);

route.setExit("north", home);

union.setExit("east", route);

trafalgar.setExit("west",route);

burgerVan.setExit("north", route);

Character steph =new Character ("steph","The girl of your dreams");

RandomNumbers randNums =new RandomNumbers();

// generates a random number which assigns the character

// 'steph' to a room

number = randNums.getRandomInt();

if (number == 0)

theHonestPolitician.setCharacter("steph",steph);

elseif (number == 1)

registry.setCharacter("steph",steph);

elseif (number == 2)

oneEyedDog.setCharacter("steph",steph);

elseif (number == 3)

weatherspoons.setCharacter("steph",steph);

elseif (number == 4)

fuzzyDuck.setCharacter("steph",steph);

elseif (number == 5)

route.setCharacter("steph",steph);

elseif (number == 6)

trafalgar.setCharacter("steph",steph);

elseif (number == 7)

union.setCharacter("steph",steph);

Item pen =new Item (3,"pen","A Parker Pen",true);

Item paper =new Item (1,"paper","Piece of Paper",true);

Item beer =new Item (10,"beer","A Can of Beer",true);

Item bigIssue =new Item (2,"bigIssue","A Big Issue",true);

Item gun =new Item (15,"gun","A Gun!",true);

Item bread =new Item (4,"bread","A loaf of bread",true);

Item cat =new Item (10,"cat","A ginger cat",false);

burgerVan.setItem("bigIssue", bigIssue);

tesco.setItem("bread", bread);

// generates a random number which assigns the item

// 'pen' to a room

number = randNums.getRandomInt();

if (number == 0)

theHonestPolitician.setItem("pen", pen);

elseif (number == 1)

registry.setItem("pen", pen);

elseif (number == 2)

oneEyedDog.setItem("pen", pen);

elseif (number == 3)

weatherspoons.setItem("pen", pen);

elseif (number == 4)

fuzzyDuck.setItem("pen", pen);

elseif (number == 5)

route.setItem("pen", pen);

elseif (number == 6)

trafalgar.setItem("pen", pen);

elseif (number == 7)

union.setItem("pen", pen);

// generates a random number which assigns the item

// 'paper' to a room

number = randNums.getRandomInt();

if (number == 0)

theHonestPolitician.setItem("paper", paper);

elseif (number == 1)

registry.setItem("paper", paper);

elseif (number == 2)

oneEyedDog.setItem("paper", paper);

elseif (number == 3)

weatherspoons.setItem("paper", paper);

elseif (number == 4)

fuzzyDuck.setItem("paper", paper);

elseif (number == 5)

route.setItem("paper", paper);

elseif (number == 6)

trafalgar.setItem("pen", pen);

elseif (number == 7)

union.setItem("paper", paper);

// generates a random number which assigns the item

// 'beer' to a room

number = randNums.getRandomInt();

if (number == 0)

theHonestPolitician.setItem("beer", beer);

elseif (number == 1)

registry.setItem("beer", beer);

elseif (number == 2)

oneEyedDog.setItem("beer", beer);

elseif (number == 3)

weatherspoons.setItem("beer", beer);

elseif (number == 4)

fuzzyDuck.setItem("beer", beer);

elseif (number == 5)

route.setItem("beer", beer);

elseif (number == 6)

trafalgar.setItem("beer", beer);

elseif (number == 7)

union.setItem("beer", beer);

// generates a random number which assigns the item

// 'gun' to a room

number = randNums.getRandomInt();

if (number == 0)

theHonestPolitician.setItem("gun", gun);

elseif (number == 1)

registry.setItem("gun", gun);

elseif (number == 2)

oneEyedDog.setItem("gun", gun);

elseif (number == 3)

weatherspoons.setItem("gun", gun);

elseif (number == 4)

fuzzyDuck.setItem("gun", gun);

elseif (number == 5)

route.setItem("gun", gun);

elseif (number == 6)

trafalgar.setItem("gun", gun);

elseif (number == 7)

union.setItem("gun", gun);

// generates a random number which assigns the item

// 'cat' to a room

number = randNums.getRandomInt();

if (number == 0)

theHonestPolitician.setItem("cat", cat);

elseif (number == 1)

registry.setItem("cat", cat);

elseif (number == 2)

oneEyedDog.setItem("cat", cat);

elseif (number == 3)

weatherspoons.setItem("cat", cat);

elseif (number == 4)

fuzzyDuck.setItem("cat", cat);

elseif (number == 5)

route.setItem("cat", cat);

elseif (number == 6)

trafalgar.setItem("cat", cat);

elseif (number == 7)

union.setItem("cat", cat);

}

/**

* Main play routine. Loops until end of play.

*/

publicvoid play()

{

printWelcome();

// Enter the main command loop. Here we repeatedly read commands and

// execute them until the game is over.

boolean finished =false;

while (! finished){

Command command = parser.getCommand();

finished = processCommand(command);

}

System.out.println("Thanks for playing.");

}

/**

* Print out the opening message for the player.

*/

privatevoid printWelcome()

{

System.out.println();

System.out.println("Welcome to the challenging World of Zuul!");

System.out.println("World of Zuul is a new incredibly sexy adventure game.");

System.out.println("You are a sexual predator and you're looking to pull!");

System.out.println("You start at home, ");

System.out.println("You can view your items by typing 'items'.");

System.out.println("Type 'help' if you need help.");

System.out.println();

}

i believe the problem occurs here (this code follows the code above):

/**

* Given a command, process (that is: execute) the command.

* @param command The command to be processed.

* @return true If the command ends the game, false otherwise.

*/

privateboolean processCommand(Command command)

{

Room home, registry, route, weatherspoons, union, burgerVan,

trafalgar, oneEyedDog, theHonestPolitician, fuzzyDuck, tesco;

Character tom =new Character ("tom","a man called tom");

RandomNumbers randNums =new RandomNumbers();

boolean wantToQuit =false;

if(command.isUnknown()){

System.out.println("I don't know what you mean...");

returnfalse;

}

String commandWord = command.getCommandWord();

if (commandWord.equals("help")){

printHelp();

}

elseif (commandWord.equals("go")){

goRoom(command);

// generates a random number which assigns the character

// 'tom' to a room

number = randNums.getRandomInt();

if (number == 0)

theHonestPolitician.setCharacter("tom",tom);

elseif (number == 1)

registry.setCharacter("tom",tom);

elseif (number == 2)

oneEyedDog.setCharacter("tom",tom);

elseif (number == 3)

weatherspoons.setCharacter("tom",tom);

elseif (number == 4)

fuzzyDuck.setCharacter("tom",tom);

elseif (number == 5)

route.setCharacter("tom",tom);

elseif (number == 6)

trafalgar.setCharacter("tom",tom);

elseif (number == 7)

union.setCharacter("tom",tom);

}

elseif (commandWord.equals("quit")){

wantToQuit = quit(command);

}

elseif(commandWord.equals("pickup")){

pickUpItem(command);

}

elseif(commandWord.equals("drop")){

dropItem(command);

}

elseif(commandWord.equals("items"))

{

if(command.hasSecondWord())

System.out.println("Type 'items' to view all your items");

else

System.out.println(player.playersInventory(command.getSecondWord()));

}

elseif (commandWord.equals("back"))

{

if(command.hasSecondWord())

System.out.println("Please type 'back' to go back.");

else

goBack();

}

elseif(commandWord.equals("look"))

{

System.out.println(currentRoom.getItemDescription());

System.out.println(currentRoom.getCharacterDescription());

}

// else command not recognised.

return wantToQuit;

}

i believe it wont compile because i have stated the rooms:

Room home, registry, route, weatherspoons, union, burgerVan,

trafalgar, oneEyedDog, theHonestPolitician, fuzzyDuck, tesco;

in two places, the first near the top under the meathod createRooms() and also under the method processCommand(Command command).

however, if i remove this Room bit of code from either of those places then i get hte error missing verriable, then the room.

im not to sure how to solve this problem, and my knowledge on jave is very basic, please advise,

thnx chias

also, can sugesst how i can write a for loop to make my code tidier, i think i need to put the items in a list, but i need the Item and itemName, which are part of a hashMap - i believe and im not too sure how to go about it

for example: for the item pen

Item pen =new Item (3,"pen","A Parker Pen",true);

if (number == 0)

theHonestPolitician.setItem("pen", pen);

i think the two parts ("pen", pen) maybe a hashMap but not really sure

Message was edited by:

chias

Message was edited by:

chias

Message was edited by:

chias

[22604 byte] By [chiasa] at [2007-11-27 3:52:08]
# 1

The places where you are specifying..

Room .......really long comma separated list.... ;

These "Room" objects only exist for the scope of the method they are created in...

I am guessing THAT is why it won't compile..

If you put that list up top ..(with currentRoom and previousRoom) ... and remove the declarations from the beginning of the two methods..you might have better luck.

Also--it's ALOT of code to read through...

Good luck,

Dave

PS-Thanks for using 'code' tags, though :)

xiarcela at 2007-7-12 8:56:10 > top of Java-index,Java Essentials,New To Java...
# 2
> Also--it's ALOT of code to read through... Yes, that's a lot of code. Most forum members will skip such a thread as soonas they see that.Post a small (<1 page) but complete sample program that forum members can copy and compile to see your errors.
DrLaszloJamfa at 2007-7-12 8:56:10 > top of Java-index,Java Essentials,New To Java...
# 3

> If you put that list up top ..(with currentRoom

> and previousRoom) ... and remove the declarations

> from the beginning of the two methods..you might have

> better luck.

thnx - i think i did that and it compiles now and works

> Also--it's ALOT of code to read through...

thnx guys for taking the time to read it, and sorry it was so big, just now i was going to edit, but i couldnt find the edit icon, just above the reply button for some reason

> PS-Thanks for using 'code' tags, though :)

n lol ur welcome :)

chiasa at 2007-7-12 8:56:10 > top of Java-index,Java Essentials,New To Java...
# 4
you are welcome
xiarcela at 2007-7-12 8:56:10 > top of Java-index,Java Essentials,New To Java...