Constructing Instances
A class declaration is like a blueprint. Blueprints contain the details for how to construct a building, but they are not a building. Your Player class declaration works similarly: So far, a player has not been constructed – you have only created the (so far, quite sparse) blueprint.
When you start a new game of NyetHack, the main function is called, and one of the first things that you will want to do is create a player character to play the game. To construct a player so that it can be used in NyetHack, you must instantiate it – create an instance of it – by calling its constructor. In Game.kt, where variables are declared in the main function, instantiate a Player, as shown:
Listing 12.2 Instantiating ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access