class LOTS::World

Attributes

the_map[R]

Public Class Methods

new() click to toggle source
# File lib/world.rb, line 46
def initialize
  # Set initial world 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/world.rb, line 105
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/world.rb, line 55
def get_height
  MAP_HEIGHT
end
get_map(args) click to toggle source

Return map data in a display format

# File lib/world.rb, line 60
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 sourcerer
      if x == MAP_SOURCERER_X and y == MAP_SOURCERER_Y
        tmp_row << MAP_KEY_SOURCERER.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 character, 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/world.rb, line 51
def get_width
  MAP_WIDTH
end

Private Instance Methods

generate_map() click to toggle source

Create a random world map

# File lib/world.rb, line 133
def generate_map
  tmp_map = Array.new

  # Step through MAX_HEIGHT times
  MAP_HEIGHT.times do
    tmp_row = Array.new
    MAP_WIDTH.times do
      tmp_row << MAP_POSSIBLE_KEYS.sample
    end

    # 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/world.rb, line 128
def new_line
  print "\n"
end