/**
* This class is the main class of the "World of Zuul" application.
* "World of Zuul" is a very simple, text based adventure game. Users
* can walk around some scenery. That's all. It should really be extended
* to make it more interesting!
*
* To play this game, create an instance of this class and call the "play"
* method.
*
* This main class creates and initialises all the others: it creates all
* rooms, creates the parser and starts the game. It also evaluates and
* executes the commands that the parser returns.
*
* @author Sama Adil Shekh
* @version October 21, 2017
*/
public class Game
{
private Parser parser;
private Room currentRoom;
private Room backRoom;
private Stack<Room> sBack;
/**
* Create the game and initialise its internal map.
*/
public Game()
{
createRooms();
parser = new Parser();
backRoom = null;
//intializes a stack of rooms
sBack = new Stack<Room>();
}
/**
* Create all the rooms and link their exits together.
*/
private void createRooms()
{
Room outside, theatre, pub, lab, office;
//some items to be in the rooms
Item bench, waterfountain, desk, stool, chair, computer, book;
//create the items
bench = new Item("Bench", 35);
waterfountain= new Item ("Water fountain", 43);
desk = new Item("Desk", 25);
stool = new Item("Stool", 7);
chair = new Item("Chair", 13);
computer = new Item("Computer", 20);
book = new Item("Book", 3);
// create the rooms
outside = new Room("outside the main entrance of the university");
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");
This study source was downloaded by 100000850872992 from CourseHero.com on 02-18-2023 22:53:49 GMT -06:00
https://www.coursehero.com/file/27690749/Gamejava/
, //items in each room
outside.addItem(bench);
outside.addItem(waterfountain);
theatre.addItem(chair);
theatre.addItem(book);
theatre.addItem(desk);
pub.addItem(stool);
lab.addItem(desk);
lab.addItem(chair);
lab.addItem(computer);
lab.addItem(book);
office.addItem(desk);
office.addItem(computer);
office.addItem(chair);
// initialise room exits
outside.setExit("east", theatre);
outside.setExit("south", lab);
outside.setExit("west", pub);
theatre.setExit("west", outside);
pub.setExit("east", outside);
lab.setExit("north", outside);
lab.setExit("east", office);
office.setExit("west", lab);
currentRoom = outside; // start game outside
}
/**
* Main play routine. Loops until end of play.
*/
public void 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("Thank you for playing. Good bye.");
}
/**
* Print out the opening message for the player.
*/
private void printWelcome()
{
System.out.println();
System.out.println("Welcome to the World of Zuul!");
System.out.println("World of Zuul is a new, incredibly boring adventure
game.");
System.out.println("Type 'help' if you need help.");
System.out.println();
This study source was downloaded by 100000850872992 from CourseHero.com on 02-18-2023 22:53:49 GMT -06:00
https://www.coursehero.com/file/27690749/Gamejava/