2 mins
For my class system in my text based adventure I have three main ones. These are Location, Item, and Player which all inherit from my game object class. Location == The class that is a location in the game. The game stores an array of these for the whole map The location class stores:
The class that is an item in the game. The item class stores:
The class that is a player in the game. The player class stores:
When the player whishes to move to a different location they must enter the direction they whish to go. This is inputted as a string and is converted to the directions enum prevoiusly mentioned. This direction is then passed into a movePlayer function in the player and compared to the array of directions within the location stored within the player. If the player can move in that direction the movePlayer function returns the change in index needed to move in that direction. For example, if the player wanted to go east and they could then movePlayer would return 1 which would get added onto the player’s location array index making them go to the next location in the index (or east). If the player cannont go in that direction the game tells the user this and their location is not changed.
When the player wants to use an item they input the item’s name and correspoding verb as strings. The verb is then converted to the verb enum and these are passed into the useItem function in the player class. The name of the item is checked with the names of the items the player has in their inventory and the item is returned if found. Next, the item’s use index is checked with the player’s location’s index to see if the player is using the item in the correct room. Thirdly, the verb passed in is checked with the item’s verb to see if the user is giving the right verb. If any of these checks fail the user is notified of where they failed and the function returns false. Otherwise the description of the item is rendered and the function returns true so that the use of the item can be performed. [hampden]: https://github.com/jekyll/jekyll
Subscribe to this blog via RSS.
C++ 30
Directx12 11
Mario kart 11
Commercial games development 15
Unity 15
Low-level programming (19) C++ (30) Text based adventure (5) Ex-machina (9) Game engine programming (11) Directx12 (11) Mario kart (11) Land of gold (5) Audio visual production (1) Commercial games development (15) Unity (15) Don't walk by (15)