class Theseus::TriangleMask

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)

Attributes

height[R]
width[R]

Public Class Methods

new(height) click to toggle source

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

# 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

Public Instance Methods

[](x,y) click to toggle source

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

# File lib/theseus/mask.rb, line 90
def [](x,y)
  @grid[y][x]
end