Class: Maze::Orthogonal

Inherits:
Generic show all
Defined in:
lib/maze/orthogonal.rb

Constant Summary collapse

OPPOSITE =
{ N => S, S => N, E => W, W => E }

Constants inherited from Generic

Generic::E, Generic::N, Generic::NE, Generic::NW, Generic::S, Generic::SE, Generic::SW, Generic::W

Instance Attribute Summary

Attributes inherited from Generic

#algorithm, #grid, #height, #width

Instance Method Summary collapse

Methods inherited from Generic

#[], #[]=, #connect, #connected?, #draw, #generate, #initialize, #tessellation

Constructor Details

This class inherits a constructor from Maze::Generic

Instance Method Details

#calculate_offset_x_axis(*args) ⇒ Object



18
19
20
21
# File 'lib/maze/orthogonal.rb', line 18

def calculate_offset_x_axis(*args)
  distance_x = { N => 0, S => 0, E => 1, W => -1 }
  distance_x[args.first]
end

#calculate_offset_y_axis(*args) ⇒ Object



23
24
25
26
# File 'lib/maze/orthogonal.rb', line 23

def calculate_offset_y_axis(*args)
  distance_y = { N => -1, S => 1, E => 0, W => 0 }
  distance_y[args.first]
end

#opposite(direction) ⇒ Object



14
15
16
# File 'lib/maze/orthogonal.rb', line 14

def opposite(direction)
  OPPOSITE[direction]
end

#random_directionsObject Also known as: directions



8
9
10
# File 'lib/maze/orthogonal.rb', line 8

def random_directions
  [N, S, E, W].sort_by { rand }
end