Listing the Heroes
Make the game display a list of heroes for the player.
We'll cover the following...
Displaying
The next step is to make the game display a list of heroes to the player. The actions of displaying an interface and displaying the heroes list are two different contexts. We’ll learn how to separate them. First, let’s create the heroes list by creating the heroes.ex
file in the lib/dungeon_crawl
folder. Our directory structure should look like this:
Let’s build the module in heroes.ex
:
Press + to interact
defmodule DungeonCrawl.Heroes doalias DungeonCrawl.Characterdef all, do: [%Character{name: "Knight",description: "Knight has strong defense and consistent damage.",hit_points: 18,max_hit_points: 18,damage_range: 4..5,attack_description: "a sword"},%Character{name: "Wizard",description: "Wizard has strong attack, but low health.",hit_points: 8,max_hit_points: 8,damage_range: 6..10,attack_description: "a fireball"},%Character{name: "Rogue",description: "Rogue has high variability of attack damage.", hit_points: 12,max_hit_points: 12,damage_range: 1..12,attack_description: "a dagger"},]end
We’ve made a list of heroes using the DungeonCrawl.Character
struct. The first line of ...