class MISSIONGAME::NewOrleans
Attributes
the_map[R]
Public Class Methods
new()
click to toggle source
# File lib/neworleans.rb, line 39 def initialize # Set initial New Orleans map generate_map end
Public Instance Methods
check_area(args)
click to toggle source
Check the current area on the map and describe it
# File lib/neworleans.rb, line 101 def check_area(args) player = args[:player] ui = args[:ui] story = args[:story] x = player.x y = player.y current_area = @the_map[y - 1][x - 1] case current_area when MAP_KEY_TREE ui.draw_frame({ text: story.area_tree }) when MAP_KEY_WATER ui.draw_frame({ text: story.area_water }) when MAP_KEY_MOUNTAIN ui.draw_frame({ text: story.area_mountain }) when MAP_KEY_ENEMY ui.draw_frame({ text: story.area_enemy }) return false end return true end
get_height()
click to toggle source
# File lib/neworleans.rb, line 48 def get_height MAP_HEIGHT end
get_map(args)
click to toggle source
Return map data in a display format
# File lib/neworleans.rb, line 53 def get_map(args) player = args[:player] buffer = Array.new x = 1 y = 1 @the_map.each do |row| tmp_row = Array.new x = 1 row.each do |col| placed = 0 # Place WITCH if x == MAP_WITCH_X and y == MAP_WITCH_Y tmp_row << MAP_KEY_WITCH.colorize(color: :white, background: :red) placed = 1 end # If player is here, display them if x == player.x and y == player.y tmp_row << MAP_KEY_PLAYER.colorize(color: :red, background: :white) placed = 1 end # If we haven't already placed the Player, run through the rest of the options if placed == 0 case col when MAP_KEY_TREE tmp_row << col.colorize(color: :light_green, background: :green) when MAP_KEY_GRASS tmp_row << col.colorize(color: :green, background: :green) when MAP_KEY_WATER tmp_row << col.colorize(color: :white, background: :blue) when MAP_KEY_MOUNTAIN tmp_row << col.colorize(color: :yellow, background: :green) when MAP_KEY_ENEMY tmp_row << col.colorize(color: :red, background: :green) end end x += 1 end buffer << tmp_row y += 1 end return buffer end
get_width()
click to toggle source
# File lib/neworleans.rb, line 44 def get_width MAP_WIDTH end
Private Instance Methods
generate_map()
click to toggle source
Create a random new orleans map
# File lib/neworleans.rb, line 129 def generate_map tmp_map = Array.new # Step through MAX_HEIGHT times MAP_HEIGHT.times do tmp_row = Array.new MAP_WIDTH.times { tmp_row << MAP_POSSIBLE_KEYS.sample } # Add our assembled row to the map tmp_map << tmp_row tmp_row = nil end @the_map = tmp_map end
new_line()
click to toggle source
# File lib/neworleans.rb, line 124 def new_line print "\n" end