Class: Maze::Point
- Inherits:
-
Struct
- Object
- Struct
- Maze::Point
- Defined in:
- lib/maze/point.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #next(maze, direction) ⇒ Object
- #out_of_bounds?(maze) ⇒ Boolean
- #raw ⇒ Object
- #unvisited?(maze) ⇒ Boolean
- #update {|other| ... } ⇒ Object
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x
2 3 4 |
# File 'lib/maze/point.rb', line 2 def x @x end |
#y ⇒ Object
Returns the value of attribute y
2 3 4 |
# File 'lib/maze/point.rb', line 2 def y @y end |
Class Method Details
.random(maze) ⇒ Object
4 5 6 |
# File 'lib/maze/point.rb', line 4 def self.random(maze) new(rand(maze.width), rand(maze.height)) end |
Instance Method Details
#+(other) ⇒ Object
30 31 32 |
# File 'lib/maze/point.rb', line 30 def +(other) self.class.new(x + other.x, y + other.y) end |
#next(maze, direction) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/maze/point.rb', line 16 def next(maze, direction) next_x = x + maze.calculate_offset_x_axis(direction, self) next_y = y + maze.calculate_offset_y_axis(direction, self) next_point = self.class.new(next_x, next_y) next_point.out_of_bounds?(maze) ? nil : next_point end |
#out_of_bounds?(maze) ⇒ Boolean
8 9 10 |
# File 'lib/maze/point.rb', line 8 def out_of_bounds?(maze) !(x.between?(0, maze.width - 1) && y.between?(0, maze.height - 1)) end |
#raw ⇒ Object
34 35 36 |
# File 'lib/maze/point.rb', line 34 def raw [x, y] end |
#unvisited?(maze) ⇒ Boolean
12 13 14 |
# File 'lib/maze/point.rb', line 12 def unvisited?(maze) maze[self].nil? end |
#update {|other| ... } ⇒ Object
24 25 26 27 28 |
# File 'lib/maze/point.rb', line 24 def update other = self.dup yield other if block_given? other end |