Dungeon Rooms and Actions
Build upon the game by adding rooms and actions for the characters.
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
:
Press + to interact
defmodule DungeonCrawl.Room.Action doalias DungeonCrawl.Room.Actiondefstruct label: nil, id: nildef forward, do: %Action{id: :forward, label: "Move forward."}def rest, do: %Action{id: :rest, label: "Take a better look and rest."}def search, do: %Action{id: :search, label: "Search the room."}end
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. ...