Dungeon Rooms and Actions
Explore how to create interconnected structs for dungeon rooms and actions in Elixir. Learn to refactor and reuse code for handling player choices, enabling interactive game design and better application structure.
We'll cover the following...
We'll cover the following...
Building structs that use structs
When the hero is in a room, the player can choose an action and face the consequences. We have two new structs to build, and one will reference the other. The Room struct will have many Action structs.
Let’s define the room action module in lib/dungeon_crawl/room. Then we’ll add the following module to the file action.ex:
The DungeonCrawl.Room.Action struct has id and label attributes. We also created helper functions to build common actions that we’ll need to build the rooms. The next step is to create the room module. Create ...