Class: RogueGenerator

Inherits:
Map
  • Object
show all
Defined in:
lib/delve/generator/rogue.rb

Instance Method Summary collapse

Methods inherited from Map

#fill, #height, #width

Constructor Details

#initialize(width = nil, height = nil, opts = Hash.new) ⇒ RogueGenerator

Returns a new instance of RogueGenerator.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/delve/generator/rogue.rb', line 5

def initialize(width=nil, height=nil, opts=Hash.new)
  super width, height

  @options = {
    :cell_width => 3,
    :cell_height => 3,
  }

  opts.keys.each do |key|
    @options[key] = opts[key]
  end

  @options[:room_width] ||= calculate_room_size width, @options[:cell_width]
  @options[:room_height] ||= calculate_room_size height, @options[:cell_height]
end

Instance Method Details

#generateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/delve/generator/rogue.rb', line 21

def generate
  @map = fill 1
  @rooms = Array.new
  @connected_cells = Array.new

  init_rooms
  connect_rooms
  connect_unconnected_rooms
  create_rooms
  create_corridors

  if block_given?
    (0..@map.length-1).each do |x|
      (0..@map[0].length-1).each do |y|
        yield x, y, @map[x][y]
      end
    end
  end
end