...

/

Appendix 2: Adding Rooms to the Game

Appendix 2: Adding Rooms to the Game

Find extra challenges to the game you developed.

A game where you only face an enemy and find an exit isn’t that interesting. A game should have more challenges and places to explore. You can use your imagination to create additional interesting ideas for the game you built in Chapter 7, Designing Your Elixir Applications. Here are some suggestions that you can implement in your game.

Trap trigger

Press + to interact
defmodule DungeonCrawl.Room.Triggers.Trap do
alias DungeonCrawl.Room.Action
alias Mix.Shell.IO, as: Shell
@behaviour DungeonCrawl.Room.Trigger
def run(character, %Action{id: :forward}) do
Shell.info("You're walking cautiously and can see the next room.")
{character, :forward}
end
def run(character, %Action{id: :search}) do
damage = 3
Shell.info("You search the room looking for something useful.")
Shell.info("You step on a false floor and fall into a trap.")
Shell.info("You are hit by an arrow, losing #{damage} hit points.")
{
DungeonCrawl.Character.take_damage(character, damage),
:forward
}
end
end

The ...