Class: DungeonMap
- Inherits:
-
Object
- Object
- DungeonMap
- Defined in:
- lib/dungeon_map.rb
Instance Method Summary collapse
- #choices(location) ⇒ Object
- #door_to(current_location, command) ⇒ Object
- #doors_at(location) ⇒ Object
-
#initialize(map) ⇒ DungeonMap
constructor
A new instance of DungeonMap.
- #to_s ⇒ Object
Constructor Details
#initialize(map) ⇒ DungeonMap
Returns a new instance of DungeonMap.
12 13 14 |
# File 'lib/dungeon_map.rb', line 12 def initialize map @map = map end |
Instance Method Details
#choices(location) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/dungeon_map.rb', line 25 def choices location doors = doors_at location door_choices = {} doors.keys.each do |command| door_choices[command.to_sym] = "Go through the #{DoorNames[command]}." end Choice.new 'Where will you go next?', door_choices end |
#door_to(current_location, command) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/dungeon_map.rb', line 16 def door_to current_location, command doors = doors_at current_location if doors[command.to_sym] return doors[command.to_sym] else return current_location end end |
#doors_at(location) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/dungeon_map.rb', line 34 def doors_at location doors = {} @map[location].each_with_index do |door, next_room| doors[door.to_sym] = next_room if door != ' ' end doors end |
#to_s ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/dungeon_map.rb', line 42 def to_s rows = [] @map.each_with_index do |row, i| rows << "#{i}|#{row.join '|'}" end rows.join "\n" end |