Skip to content

Home (class)

Jantoom edited this page Oct 19, 2021 · 1 revision

Introduction

Homes taken from the real world are not necessarily limited to one floor; home occupants have the ability to move between floors without leaving the one home.

Our team's emotional goals included bringing familiarity with the household themes, so it was deemed crucial to import multiple floor capabilities into the game.

Technical Explanation

Abstract separation of ScreenAdapter and GameArea

The Home class serves as a container of [Floor]s. This allows several Floor instances to exist simultaneously within one Screen. One of the benefits of having a Home is replacing the one-to-one relationship between the ScreenAdapter subclasses and the GameArea instances.

Construction of a Home instance and calling create( )

The default constructor for Home has no arguments, which means a Home can be created without specifying any Floors. Developers may choose to pass one Floor JSON file to a Home constructor to bypass the random selection algorithm. The file will be read and added to the list of floors. Conceptually, this is the first/ground floor of the home because the index of this object is 0.

When create( ) is called, a random floor will be selected if an initial floor was not given. At this point, the Home will have exactly one Floor instance; this will become the active floor for the player. Only one active floor should ever exist at one time, because this is the floor that is rendered to the player's screen. After this, subsequent calls to create( ) will do nothing.

Random Floor selection algorithm

The algorithm makes use of file system navigation to read JSON files and load Java instances. The static variable DIRECTORY specifies the parent directory for all map files. The default sub-directory used for selecting floor files is "_floor_plans". If developers want to add more floor JSON files, this is where they should go.

Randomly, a Floor JSON file is selected and read by the FileLoader. Deserialization of this file is handled by the [Floor] class. This process is repeated until a valid Floor instance is returned, or the list of gathered JSON files in the "_floor_plans" directory have all been checked. If no valid instance is returned, then a NullPointerException is thrown because the game cannot go any further without a Floor.

Active floor switching

Currently, the way to switch between floors is to specify which index that Floor is in the Home's internal list of floors. Functionality for adding and removing specific floors may be added if this mechanic is utilized by other studio developers.

Clone this wiki locally