Question
These are room and thing class: ROOM Constructor Summary Constructor and Description Room (java.lang.String description) Method Summary Modifier and Type Method and Description void addExit
These are room and thing class:
ROOM
Constructor Summary
Constructor and Description |
---|
Room(java.lang.String description) |
Method Summary
Modifier and Type | Method and Description |
---|---|
void | addExit(java.lang.String name, Room target) Add a new exit to this Room. |
void | enter(Thing item) Add Thing to this Room. |
java.util.List | getContents() What Things are in this Room? |
java.lang.String | getDescription() A description of the room. |
java.util.Map | getExits() What exits are there from this Room? |
boolean | leave(Thing item) Remove item from Room. |
static void | makeExitPair(Room room1, Room room2, java.lang.String label1, java.lang.String label2) Connects two rooms both ways. |
void | removeExit(java.lang.String name) Remove an exit from this Room Note: silently fails if exit does not exist. |
void | setDescription(java.lang.String description) Change Room description Note: each or in the new description will be replaced with a `*`. |
THING
Constructor and Description |
---|
Thing(java.lang.String shortDescription, java.lang.String longDescription) Note: each, , and semi-colon in the parameter will be replaced by * |
Method Summary
Modifier and Type | Method and Description |
---|---|
java.lang.String | getDescription() Get long description of the Thing (possibly with extra info at subclass' discretion).. |
protected java.lang.String | getLong() Allows subclasses to read the raw longDescription value. |
protected java.lang.String | getShort() Allows subclasses to read the raw longDescription value. |
java.lang.String | getShortDescription() Get short description of the Thing. |
abstract java.lang.String | repr() Get a representation of the object suitable for saving. |
protected void | setLong(java.lang.String longDescription) Change the long description for the Thing. |
protected void | setShort(java.lang.String shortDescription) Change the short description for the Thing. |
Need help with this class and methods please:
Constructor Summary (MapIO Class)
Constructor and Description |
---|
MapIO() Methods: public static boolean saveMap(Room root, java.lang.String filename) Write Rooms to a new file (using encoded String form) Parameters: root - Start room filename - Filename to write to Returns: true if successful Detail.: The structure of a file is: The number of rooms in the file Room descriptions Room exits Room contents Rooms are always listed in the same order with the start room first. Note that this format does not preserver player inventory. The file format is as follows: number_of_rooms description_of_room_0 description_of_room_1 description_of_room_2 ... (more descriptions) number_of_exits_from_room_0 number_0_0 name_0_0 number_0_1 name_0_1 ... (more room_0) number_of_exits_from_room_1 number_1_0 name_1_0 number_1_1 name_1_1 ... (more room_1) number_of_exits_from_room_2 number_2_0 name_2_0 ... (more room_2) ... (more rooms) number_items_in_room_0 repr_for_item_0_0 repr_for_item_0_1 ... (more items in room 0) number_items_in_room_0 repr_for_item_0_0 repr_for_item_0_1 ... (more items in room 0) ... (more rooms) Note: even if a entry would have zero items, it still needs to be there. As an example: Room r1=new Room("#1"); Room r2=new Room("#2"); r2.enter(new Critter("frog", "a frog", 1, 5)); r1.enter(new Explorer("doris", "a doris")); try { r1.addExit("North", r2); r2.addExit("South", r1); } catch (ExitExistsException ee) { } catch (NullRoomException nr) { } MapIO.saveMap(r1, "mymap"); Would produce a file containing: 2 #1 #2 1 1 North 1 0 South 1 E;10;doris;a doris 1 C;1.0;5;frog;a frog Require: There is exactly one player object anywhere in the map(appearing exactly once). public static Thing decodeThing(java.lang.String encoded, Room root) Decode a String into a Thing. (Need to be able to decode, Treasure, Critter, Builder and Explorer) <-- create Thing object from String (encoded) Parameters: encoded - String to decode root - start room for the map Returns: Decoded Thing or null on failure. (null arguments or incorrectly encoded input) public static java.lang.Object[] loadMap(java.lang.String filename) Read information from a file created with saveMap Parameters: filename - Filename to read from Returns: null if unsucessful. If successful, an array of two Objects. [0] being the Player object (if found) and [1] being the start room. Detail.: Do not add the player to the room they appear in, the caller will be responsible for placing the player in the start room. |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started