Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using inheritance for the World of Zuul project, create a TransporterRoom class that inherits the Room class and transports you to another room Some pieces

Using inheritance for the World of Zuul project, create a TransporterRoom class that inherits the Room class and transports you to another room

Some pieces of code that may help:

import java.util.Scanner;

public class Game { private Room currentRoom; public Game() { createRooms(); }

/** * Create all the rooms and link their exits together. */ private void createRooms() { Room outside, theater, teleport;

// create the rooms outside = new Room("outside *burp* the main entrance *burp* of the university"); theater = new Room("in a lecture theater"); teleport = new Room("in my space cruiser");

// initialise room exits outside.setExit("east", theater); theater.setExit("west", outside); outside.setExit("north", teleport); teleport.setExit("south", outside);

currentRoom = outside; //start game outside }

/** * 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. */ private boolean processCommand(Command command) { boolean wantToQuit = false;

CommandWord commandWord = command.getCommandWord();

switch (commandWord) { case UNKNOWN: System.out.println("I don't know what you mean..."); break;

case GO: goRoom(command); setRoom(); break; } return wantToQuit; }

/** *Sets the current room for player if the description of *the current location matches the room */ private void setRoom() { String str = currentRoom.getShortDescription().toString();

if (!(str.equals(null))) { if (str.equals("in a lecture theater")) player.setCurrentRoom("theater");

else if (str.equals("outside *burp* the main entrance *burp* of the university")) player.setCurrentRoom("outside");

else if (str.equals("in my space cruiser")) { player.setCurrentRoom("teleport"); } }

else return; } /** * Try to go in a direction. If there is an exit, enter the new * room, otherwise print an error message. * @param command User input the direction desired */ private void goRoom(Command command) { String direction = command.getSecondWord();

// Try to leave current room. Room nextRoom = currentRoom.getExit(direction);

currentRoom = nextRoom; } }

import java.util.Set; import java.util.HashMap;

public class Room { private String description; public HashMap exits; // stores "exits" of Room class

/** * Create a room * @param description The room's description */ public Room(String description) { this.description = description; exits = new HashMap<>(); }

public void setExit(String direction, Room neighbor) { exits.put(direction, neighbor); }

public String getShortDescription() { return description; }

public Room getExit(String direction) { return exits.get(direction); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions