Class: Theseus::TriangleMask

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

Overview

This is a specialized mask, intended for use with DeltaMaze instances (although it will work with any maze). This lets you easily create triangular delta mazes.

mask = Theseus::TriangleMask.new(10)
maze = Theseus::DeltaMaze.generate(mask: mask)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(height) ⇒ TriangleMask

Returns a new TriangleMask instance with the given height. The width will always be 2h+1 (where h is the height).



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/theseus/mask.rb', line 76

def initialize(height)
  @height = height
  @width = @height * 2 + 1
  @grid = Array.new(@height) do |y|
    run = y * 2 + 1
    from = @height - y
    to = from + run - 1
    Array.new(@width) do |x| 
      (x >= from && x <= to) ? true : false
    end
  end
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



72
73
74
# File 'lib/theseus/mask.rb', line 72

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



72
73
74
# File 'lib/theseus/mask.rb', line 72

def width
  @width
end

Instance Method Details

#[](x, y) ⇒ Object

Returns the true/false value for the corresponding cell in the grid.



90
91
92
# File 'lib/theseus/mask.rb', line 90

def [](x,y)
  @grid[y][x]
end