java - Text Adventure Game, adding time and game ending -


i making simple text adventure game, got 2 little problems..

problem 1: want make end game goal.. once player reached room, game ends.. cannot seem if statement correct..

problem 2: want make time limit(steps) lets user 30 steps complete game.. every room enters, counter +1.. , once reaches 30 steps loose.

i have createrooms method creates rooms , locations

private void createrooms() {     room gate, graveyard, church, crypt, entrance, hall, kitchen, buttery, greathall, staircase,         dungeon, topstaircase, throne, solar, wardrobe, privy;      // create rooms     gate = new room("outside old gate of castle");     graveyard = new room("on wind-swept gaveyard");     church = new room("in small ancient church medieval windows");     crypt = new room("in crypt of church");     entrance = new room("at big wooden entrance of castle");     hall = new room("in dark entrance hall of castle");     kitchen = new room("in kitchen huge table , big stove");     buttery = new room("in buttery of castle");     greathall = new room("in great hall of castle magnificient huge windows");     staircase = new room("at staircase");     dungeon = new room("in dark dungeon of castle");     topstaircase = new room("at top of staircase");     throne = new room("in throne room golden walls");     solar = new room("in solar of castle");     wardrobe = new room("in wardroble of lord of castle");     privy = new room("in privy");      // initialise room exits      gate.setexit("north", graveyard);      graveyard.setexit("south", gate);     graveyard.setexit("east", church);     graveyard.setexit("north", entrance);      church.setexit("west", graveyard);     church.setexit("south", crypt);      crypt.setexit("north", church);      entrance.setexit("south", graveyard);     entrance.setexit("north", hall);      hall.setexit("south", graveyard);     hall.setexit("west", kitchen);     hall.setexit("north", greathall);     hall.setexit("east", staircase);      kitchen.setexit("east", hall);     kitchen.setexit("south", buttery);      buttery.setexit("north", kitchen);      greathall.setexit("south", hall);      staircase.setexit("west", hall);     staircase.setexit("down", dungeon);     staircase.setexit("up", topstaircase);      topstaircase.setexit("down", staircase);     topstaircase.setexit("north", throne);     topstaircase.setexit("south", solar);      throne.setexit("south", topstaircase);      solar.setexit("north", topstaircase);     solar.setexit("west", wardrobe);     solar.setexit("east", privy);      wardrobe.setexit("east", solar);      privy.setexit("west", solar);      currentroom = gate;  // start game @ gate } 

this tried

if(room == throne) {     system.out.println("congratulations have won game!");     system.out.println("press key enter continue")     system.exit();  } 

im not sure how how make pause after congratulations message, , make user press key enter, before closing game.

as times.. dont know begin.. presume need write like:

for(every goroom) int +1 when(int ==30) system.out.println("you have lost game") game exits or starts game.. 

would correct?

this not full answer problems, seems have problems make program run: first, can decide victory , user interactions.

your room variables defined within scope of createrooms method, seem wrong. need define them globally in class (try moving line

room gate, graveyard, church, crypt, entrance, hall, kitchen, buttery, greathall, staircase, dungeon, topstaircase, throne, solar, wardrobe, privy; 

outside method (and make them private, it's make variables private unless need access them outside: preserves encapsulation.)

also if want count user steps, need variable hold count, in class.

private room gate, graveyard, church, crypt, entrance, hall, kitchen, buttery, greathall, staircase, dungeon, topstaircase, throne, solar, wardrobe, privy = null; private int steps = 0  private void createrooms() {   gate = new room("outside old gate of castle");   graveyard = new room("on wind-swept gaveyard");   ... 

then can call of class method:

if (room.equals(throne)) {   // of victory printout 

that @ least put on right path.

i suggest don't put system.out.println statement directly in main class, should separate concerns of game mechanics (your main class) , user interface, using pluggable interface (dependency injection).

for example can define interface useroutput, methods on onvictory, onroomchange, etc. , implement class consoleuseroutput system.out.printlnstatements in these methods. , inject consoleuseroutputin main class @ creation time (so main class knows interface useroutput). better, can plug user interactions way: waiting him press key, etc.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -