Class: MazeOperation
- Defined in:
- lib/my_own_maze/operation/maze_operation.rb
Constant Summary collapse
- ACTIONS =
['a', 'd', 'w', 's', 'h']
Instance Method Summary collapse
- #do(action) ⇒ Object
-
#do_a ⇒ Object
go left.
-
#do_d ⇒ Object
go right.
-
#do_h ⇒ Object
help.
-
#do_s ⇒ Object
go down.
-
#do_w ⇒ Object
go up.
- #print_maze ⇒ Object
Methods inherited from Operation
Constructor Details
This class inherits a constructor from Operation
Instance Method Details
#do(action) ⇒ Object
4 5 6 7 |
# File 'lib/my_own_maze/operation/maze_operation.rb', line 4 def do(action) return unless ACTIONS.include?(action) send("do_#{action}") end |
#do_a ⇒ Object
go left
22 23 24 |
# File 'lib/my_own_maze/operation/maze_operation.rb', line 22 def do_a go(@player.x - 1, @player.y) end |
#do_d ⇒ Object
go right
27 28 29 |
# File 'lib/my_own_maze/operation/maze_operation.rb', line 27 def do_d go(@player.x + 1, @player.y) end |
#do_h ⇒ Object
help
15 16 17 18 19 |
# File 'lib/my_own_maze/operation/maze_operation.rb', line 15 def do_h points = @rule.calculate(@player.x, @player.y) print_maze @style.print_points(points, 'result') end |
#do_s ⇒ Object
go down
37 38 39 |
# File 'lib/my_own_maze/operation/maze_operation.rb', line 37 def do_s go(@player.x, @player.y + 1) end |
#do_w ⇒ Object
go up
32 33 34 |
# File 'lib/my_own_maze/operation/maze_operation.rb', line 32 def do_w go(@player.x, @player.y - 1) end |
#print_maze ⇒ Object
9 10 11 12 |
# File 'lib/my_own_maze/operation/maze_operation.rb', line 9 def print_maze @style.print_maze(@maze) @style.print_player(@player) end |