Info in "The Crypt" Game

In the game "The Crypt," the term 'info' refers to the details associated with a player. This information encompasses the player's name, health status, and the items they possess. The method showInfo is utilized to display this information. Notably, the player's current location is not included in this display, as 'Place' objects have their own dedicated showInfo method to handle location-specific information.

Player Information

The player's information is crucial for understanding their status and capabilities within the game. The showInfo method provides a streamlined way to present this data, focusing on the player's identity and inventory without delving into their current location. This separation of concerns allows for a more organized and modular approach to displaying game information.

Place Information

In addition to player information, the game also manages data related to different locations or 'places' within the game world. The updated Place constructor, as shown in the following figure, demonstrates how data hiding is implemented using parameters and variables. This approach ensures that the internal workings of a place are encapsulated, providing a cleaner interface for interacting with place data.

Figure: Hiding Place Info in the Constructor

Listing 11.16. Hiding place info in the constructor (http://jsbin.com/riviga/edit?js,console) Listing 11.16. Hiding place info in the constructor (http://jsbin.com/riviga/edit?js,console)

The figure above illustrates the updated version of the Place constructor. It includes:

  • Data Hiding: Parameters and variables are used to encapsulate place information.
  • getExit Function: This function returns the destination for a specified direction, allowing players to navigate the game world.
  • getLastItem Method: This method retrieves the last item from the items array, providing a way to access the most recently added item in a place.

By organizing player and place information in this manner, "The Crypt" game maintains a clear and efficient structure for managing and displaying game data.