Class: Gemwarrior::World
- Inherits:
-
Object
- Object
- Gemwarrior::World
- Defined in:
- lib/gemwarrior/world.rb
Constant Summary collapse
- LOCATION_DATA_FILE =
CONSTANTS
"data/locations.yml"
- WORLD_DIM_WIDTH =
10
- WORLD_DIM_HEIGHT =
10
- ERROR_LIST_PARAM_INVALID =
ERRORS
'That is not something that can be listed.'
- ERROR_LOCATION_DESCRIBE_ENTITY_INVALID =
'You do not see that here.'
Instance Attribute Summary collapse
-
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
-
#locations ⇒ Object
Returns the value of attribute locations.
-
#monsters ⇒ Object
Returns the value of attribute monsters.
-
#player ⇒ Object
Returns the value of attribute player.
-
#sound ⇒ Object
Returns the value of attribute sound.
-
#use_wordnik ⇒ Object
Returns the value of attribute use_wordnik.
Instance Method Summary collapse
- #can_move?(direction) ⇒ Boolean
- #describe(point) ⇒ Object
- #describe_entity(point, entity_name) ⇒ Object
- #has_monster_to_attack?(monster_name) ⇒ Boolean
-
#initialize ⇒ World
constructor
A new instance of World.
- #list(param, details = false) ⇒ Object
- #location_by_coords(coords) ⇒ Object
- #location_coords_by_name(name) ⇒ Object
- #print_map(floor) ⇒ Object
- #print_vars ⇒ Object
Constructor Details
#initialize ⇒ World
Returns a new instance of World.
22 23 24 25 26 |
# File 'lib/gemwarrior/world.rb', line 22 def initialize self.monsters = init_monsters self.locations = init_locations self.player = nil end |
Instance Attribute Details
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
20 21 22 |
# File 'lib/gemwarrior/world.rb', line 20 def debug_mode @debug_mode end |
#locations ⇒ Object
Returns the value of attribute locations.
20 21 22 |
# File 'lib/gemwarrior/world.rb', line 20 def locations @locations end |
#monsters ⇒ Object
Returns the value of attribute monsters.
20 21 22 |
# File 'lib/gemwarrior/world.rb', line 20 def monsters @monsters end |
#player ⇒ Object
Returns the value of attribute player.
20 21 22 |
# File 'lib/gemwarrior/world.rb', line 20 def player @player end |
#sound ⇒ Object
Returns the value of attribute sound.
20 21 22 |
# File 'lib/gemwarrior/world.rb', line 20 def sound @sound end |
#use_wordnik ⇒ Object
Returns the value of attribute use_wordnik.
20 21 22 |
# File 'lib/gemwarrior/world.rb', line 20 def use_wordnik @use_wordnik end |
Instance Method Details
#can_move?(direction) ⇒ Boolean
212 213 214 |
# File 'lib/gemwarrior/world.rb', line 212 def can_move?(direction) location_by_coords(player.cur_coords).has_loc_to_the?(direction) end |
#describe(point) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/gemwarrior/world.rb', line 146 def describe(point) desc_text = "" desc_text << "[ #{point.name} ]".colorize(:green) if debug_mode desc_text << " DL[#{point.danger_level.to_s}] MLR[#{point.monster_level_range.to_s}]".colorize(:yellow) end desc_text << "\n" desc_text << point.description point.populate_monsters(self.monsters) unless point.checked_for_monsters? desc_text << "\n >> Curious object(s): #{point.list_items.join(', ')}" unless point.list_items.empty? desc_text << "\n >> Monster(s) abound: #{point.list_monsters.join(', ')}" unless point.list_monsters.empty? desc_text << "\n >> Boss(es) abound: #{point.list_bosses.join(', ')}" unless point.list_bosses.empty? desc_text << "\n >> Paths: #{point.list_paths.join(', ')}" if debug_mode desc_text << "\n >>> Actionable words: " desc_text << point.list_actionable_words.colorize(:white) end return desc_text end |
#describe_entity(point, entity_name) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/gemwarrior/world.rb', line 172 def describe_entity(point, entity_name) if point.has_item?(entity_name) point.items.each do |i| if i.name.downcase.eql?(entity_name.downcase) if debug_mode return i.describe else return i.description end end end elsif if point.has_monster?(entity_name) point.monsters_abounding.each do |m| if m.name.downcase.eql?(entity_name.downcase) if debug_mode return m.describe else return m.description end end end end elsif if point.has_boss?(entity_name) point.bosses_abounding.each do |b| if b.name.downcase.eql?(entity_name.downcase) if debug_mode return b.describe else return b.description end end end end else ERROR_LOCATION_DESCRIBE_ENTITY_INVALID end end |
#has_monster_to_attack?(monster_name) ⇒ Boolean
216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/gemwarrior/world.rb', line 216 def has_monster_to_attack?(monster_name) possible_combatants = location_by_coords(player.cur_coords).monsters_abounding.map(&:name) | location_by_coords(player.cur_coords).bosses_abounding.map(&:name) possible_combatants.each do |combatant| if combatant.downcase.eql?(monster_name.downcase) return true end end return false end |
#list(param, details = false) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/gemwarrior/world.rb', line 82 def list(param, details = false) case param when 'players' puts '[PLAYERS]' player.check_self(false) when 'monsters' puts "[MONSTERS](#{monsters.length})".colorize(:yellow) if details monsters.map { |m| print m.describe } return else monster_text = ">> monsters: #{monsters.map(&:name).join(', ')}" end when 'items' item_count = 0 locations.each do |l| l.items.each do |i| item_count = item_count + 1 end end puts "[ITEMS](#{item_count})".colorize(:yellow) if details locations.each do |l| l.items.map { |i| print i.describe } end return else item_list = [] locations.each do |l| l.items.map { |i| item_list << i.name } end ">> #{item_list.sort.join(', ')}" end when 'locations' puts "[LOCATIONS](#{locations.length})".colorize(:yellow) if details locations.map { |l| print l.status(self.debug_mode) } return else ">> #{locations.map(&:name).join(', ')}" end else ERROR_LIST_PARAM_INVALID end end |
#location_by_coords(coords) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/gemwarrior/world.rb', line 128 def location_by_coords(coords) locations.each do |l| if l.coords.eql?(coords) return l end end return nil end |
#location_coords_by_name(name) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/gemwarrior/world.rb', line 137 def location_coords_by_name(name) locations.each do |l| if l.name.downcase.eql?(name.downcase) return l.coords end end return nil end |
#print_map(floor) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gemwarrior/world.rb', line 38 def print_map(floor) 0.upto(WORLD_DIM_HEIGHT-1) do |count_y| print ' ' 0.upto(WORLD_DIM_WIDTH-1) do print '---' end print "\n" print "#{(WORLD_DIM_HEIGHT-1) - count_y} " 0.upto(WORLD_DIM_WIDTH-1) do |count_x| cur_map_coords = { :x => count_x, :y => (WORLD_DIM_HEIGHT-1) - count_y, :z => floor.nil? ? self.player.cur_coords[:z] : floor.to_i } if self.player.cur_coords.eql?(cur_map_coords) print '|O|' elsif location_by_coords(cur_map_coords) print '|X|' else print '| |' end end print "\n" end print ' ' 0.upto(WORLD_DIM_WIDTH-1) do print '---' end puts print ' ' 0.upto(WORLD_DIM_WIDTH-1) do |count_x| print "#{count_x} " end if debug_mode puts puts puts "Current level: #{player.cur_coords[:z]}" puts '| | = invalid location' puts '|X| = valid location' puts '|O| = player' end return end |
#print_vars ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/gemwarrior/world.rb', line 28 def print_vars puts "======================\n" puts "All Variables in World\n" puts "======================\n" puts "#{list("players", true)}\n" puts "#{list("monsters", true)}\n\n" puts "#{list("items", true)}\n\n" puts "#{list("locations", true)}\n" end |