Dictionaries and HashMaps – a Better Map? (Complete Course in Adventure Game Programming)

Опубликовано: 13 Октябрь 2024
на канале: Code With Huw
1,459
46

What could be better than an array for creating a map of all the rooms in a game? How about a dictionary? Dictionaries are collections that are indexed not by a number but by a ‘key’. A key can be any sort of unique identifier such as a string or a constant. Each key is associated with a value. The elements of the dictionary are, in fact, formed from key-value pairs. In C#, you can create dictionaries using the Dictionary class. In Java, you could use the HashMap class. In this lesson, I take the first step towards rebuilding my game map using a dictionary instead of an array.

In this lesson, I’ll explain the Java class hierarchy of the game so far. Note that I have already explained the basics of the class hierarchy (in C#) in the previous lesson, here:    • How To Create A Game Class Hierarchy ...  
I recommend that you watch that lesson first. In this lesson, I will point out the main differences between my C# and Java classes.

To follow this course, bookmark the Complete Course In Adventure Game Programming Playlist:
   • Complete Course in Adventure Game Pro...  

Huw Collingbourne is author of The Little Book Of Adventure Game Programming In C#. Available from:
Amazon (US) https://amzn.to/33M6sQ4
Amazon (UK) https://amzn.to/2YtaBrj

And also, The Little Java Book Of Adventure Game Programming. Available from:
Amazon (US) https://amzn.to/3gizI93
Amazon (UK) https://amzn.to/3mydF0e

If you are eager to get working on your own adventure game, you can download Huw’s free game-writing code libraries, BIFF (the Bitwise Interactive Fiction Framework) from:
http://www.bitwisebooks.com

Facebook:   / codewithhuw