Classes - nt314p/Zork GitHub Wiki

Item

Every item or object used the game is an Item. Items have a name, weight, and a HashMap of descriptions. Why a HashMap? A HashMap is used to store the descriptions because items can have multiple descriptions, not just one. Read more on HashMaps here.

Key

A Key is a subclass of Item. They have a String code, which allows a relation between a lockable Door and its respective Key.

Inventory

An inventory is an ArrayList of Items. The class also contains several helpful methods for manipulating Inventories.

Character

A Character is a subclass of Item. They have an inventory, and health, food, and water values. They also have a Location, which is mentioned below. Characters in game are NPCs or non-player characters. They have the ability to move around based on predefined parameters, and they can also be interacted with by the Player.

Player

A Player is a subclass of Character. Their movement is controlled based on input via the console. They have the ability to interact with Items inside Rooms, including the ability to add and remove Items from their inventory. They can also use Keys to unlock/lock Doors.

Map Related

Zork must be played on a map, the game space, which holds certain map components such as rooms, items, characters, etc. Our game is played on a 3D grid. This conveniently allows for the use of a coordinate system to access the places, rooms, and other things inside our map. Due to the possible complexity of the Zork game space, multiple maps can be created to provide a modular approach to map making. However, with multiple maps, we can no longer reference a Place inside a map using its coordinates (x, y, z) alone. This requires the creation of a new class, namely a Location.

Coordinate

The coordinate class is a simple class that has a x, y, and z variables to represent a coordinate on a 3D grid.

Map

In each map, we used a 3D array of Places to represent our game space. To access any Place, we use a Coordinate.

Location

A Location has two components, a Coordinate, and a String that holds the name of the map that the coordinate is found under. A Location can now fully define a Place in the game space, by first pointing to a specific map, and then a coordinate inside that map.

Link

A Link contains two Locations. Its purpose is to link (ha!) maps together. If the Player is at one of the mentioned locations, it can have the option to move to the other location, even if it is on another map. It also has a property that determines whether or not the Player can move back to the other location (bidirectional, or in a single direction).

Place

Place is a subclass of Item. Places have a new property that maps did not have, a Location. This means that Places can be "found" using their location. Place is abstract, however all of its subclasses except Side can be instantiated. Due to polymorphism, this allows for Walls, Openings, Doors, and Rooms to all be stored in the map, using a 3D array of Places.

Side

A Side is a subclass of Place. It has a new property, a boolean (isExit) that determines if the side is an exit or not. Only if the Side is an exit, players/things can move through the Side. However, Side is an abstract class, which means that it cannot be instantiated. To be useful, Side has additional subclasses which can be instantiated.

Wall

Wall is a subclass of Side. It's isExit is set to false.

Opening

Opening is a subclass of Side. It's isExit is set to true.

Door

Door is a subclass of Side. It's isExit boolean can be changed based on if the door is open or closed. Doors can also be lockable. If they are lockable, they also have a Key variable, which can unlock/lock the door.

Room

Room is a subclass of Place. It has a new property, an Inventory. This allows the Room to store not only Items, but also Characters and Players because they are subclasses of Items (yay polymorphism).