Adding the Adventurer

The adventurer is the player’s avatar in the dungeon. The adventurer roams the dungeon, hopefully collecting loot but likely dying at the hands of vicious monsters.

The game needs to know what tiles the adventurers can enter so that they don’t walk through walls. It also needs to store where the adventurer is, handle movement with the keyboard, and actually perform the movement. This section will address each of these requirements.

Extend the map API

Let’s add some more map functions to support player functionality. We need to determine if an x/y coordinate pair is within the bounds of the map. If we don’t perform bounds checking, the adventurer can move off of the edge of the map and will either wrap around or crash the program. Add the following to our Map implementation:

Get hands-on with 1200+ tech skills courses.