Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Game.java Carleton University SYSC 2004

Rating
-
Sold
-
Pages
6
Grade
A+
Uploaded on
19-02-2023
Written in
2022/2023

import .Stack; /** * 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 StackRoom sBack; /** * Create the game and initialise its internal map. */ public Game() { createRooms(); parser = new Parser(); backRoom = null; //intializes a stack of rooms sBack = new StackRoom(); } /** * 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 Ite

Show more Read less
Institution
Course

Content preview

import java.util.Stack;
/**
* 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/

Written for

Course

Document information

Uploaded on
February 19, 2023
Number of pages
6
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$10.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ExamsConnoisseur Self
Follow You need to be logged in order to follow users or courses
Sold
587
Member since
3 year
Number of followers
344
Documents
1492
Last sold
1 week ago

4.2

68 reviews

5
40
4
11
3
13
2
1
1
3

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions