Module: Maze::Formatter::Ascii

Included in:
Orthogonal, Sigma
Defined in:
lib/maze/formatters/ascii.rb,
lib/maze/formatters/ascii/sigma.rb,
lib/maze/formatters/ascii/orthogonal.rb

Defined Under Namespace

Classes: Orthogonal, Sigma

Instance Method Summary collapse

Instance Method Details

#canvas_drawObject



11
12
13
14
15
16
17
# File 'lib/maze/formatters/ascii.rb', line 11

def canvas_draw
  maze.height.times do |y|
    maze.width.times do |x|
      canvas_update Point.new(x, y)
    end
  end
end

#canvas_update(for_point) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/maze/formatters/ascii.rb', line 19

def canvas_update(for_point)
  origin =  calculate_origin(for_point)

  maze.directions.each do |direction|
    offset = origin + calculate_offset(direction, for_point)

    unless maze.connected?(for_point, direction)
      canvas[offset.y][offset.x] = select_character(direction)
    end
  end
end

#to_sObject Also known as: draw



5
6
7
# File 'lib/maze/formatters/ascii.rb', line 5

def to_s
  canvas.map { |line| line.join }.join("\n")
end