Class: LOTS::World

Inherits:
Object
  • Object
show all
Defined in:
lib/world.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorld

Returns a new instance of World.



46
47
48
49
# File 'lib/world.rb', line 46

def initialize
  # Set initial world map
  generate_map
end

Instance Attribute Details

#the_mapObject (readonly)

Returns the value of attribute the_map.



44
45
46
# File 'lib/world.rb', line 44

def the_map
  @the_map
end

Instance Method Details

#check_area(args) ⇒ Object

Check the current area on the map and describe it



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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_heightObject



55
56
57
# File 'lib/world.rb', line 55

def get_height
  MAP_HEIGHT
end

#get_map(args) ⇒ Object

Return map data in a display format



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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_widthObject



51
52
53
# File 'lib/world.rb', line 51

def get_width
  MAP_WIDTH
end