/****
* A game of zork.
*
*****/
import jpb.*;
class Game {
static Person princess;
public static void main(String[] args){
init();
play();
}
static void play(){
System.out.println(" ");
System.out.println(" ============================================= ");
System.out.println(" ===== WELCOME, oh foolish one. ======== ");
System.out.println(" ===== Many have entered. ======== ");
System.out.println(" ===== Few have returned. ======== ");
System.out.println(" ===== You have been warned... ======== ");
System.out.println(" ============================================= ");
boolean playing = true;
while (playing) {
princess.status();
SimpleIO.prompt(" What would you like to do next? "+
"(north,south,eath,west,look,quit) ");
String choice = SimpleIO.readLine();
if (choice.equals("n") || choice.equals("north")){
princess.moveTo(0);
}
else if (choice.equals("s") || choice.equals("south")){
princess.moveTo(1);
}
else if (choice.equals("e") || choice.equals("east")){
princess.moveTo(2);
}
else if (choice.equals("w") || choice.equals("west")){
princess.moveTo(3);
}
else if (choice.equals("l") || choice.equals("look")){
princess.look();
}
else {
System.out.println(" Bye.\n");
playing = false;
}
}
}
static void init(){
// ----- Define starting location ------
Room startHere = new Room("the cave entrance");
startHere.setDescription(" Dark trees surround you on all sides,\n"+
" except to the north where you see"+
" the entrance to a dimly lit cave.");
startHere.addThing(0,"a small knife");
// ----- Put the princess there.
princess = new Person("Princess Peach", startHere);
// ----- Define entryway -----------------
Room entry = new Room("the front hall");
entry.setDescription(" A torch set in the wall barely"+
" lights the entry.");
// ------ connect 'em together -------
startHere.addDoor(Room.NORTH, entry);
entry.addDoor(Room.SOUTH, startHere);
// add more rooms...
Room maze1 = new Room("a maze of twisty halls all alike");
maze1.setDescription(" The dirty floor and bare walls give you "+
" little clue as to where you are.");
maze1.addThing(0,"a women's field hockey team");
maze1.addThing(1,"some popcorn");
entry.addDoor(Room.EAST, maze1);
maze1.addDoor(Room.WEST, entry);
Room maze2 = new Room("a maze of twisty halls all alike");
maze2.setDescription(" The dirty floor and bare walls give you "+
" little clue as to where you are.");
maze2.addThing(0,"a broken copper bracelet");
maze1.addDoor(Room.EAST, maze2);
maze2.addDoor(Room.EAST, maze1);
maze2.addDoor(Room.WEST, maze1);
maze2.addDoor(Room.NORTH, maze2);
}
}
syntax highlighted by Code2HTML, v. 0.9.1