Class: MazePlayer
- Inherits:
-
Object
- Object
- MazePlayer
- Defined in:
- lib/maze/game/maze_player.rb
Instance Attribute Summary collapse
-
#current_position ⇒ Object
readonly
Returns the value of attribute current_position.
-
#moves ⇒ Object
readonly
Returns the value of attribute moves.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(current_position, name) ⇒ MazePlayer
constructor
A new instance of MazePlayer.
- #move(orientation) ⇒ Object
- #move_bottom ⇒ Object
- #move_left ⇒ Object
- #move_right ⇒ Object
- #move_top ⇒ Object
Constructor Details
#initialize(current_position, name) ⇒ MazePlayer
Returns a new instance of MazePlayer.
4 5 6 7 8 |
# File 'lib/maze/game/maze_player.rb', line 4 def initialize(current_position, name) @current_position = current_position @name = name @moves = 0 end |
Instance Attribute Details
#current_position ⇒ Object (readonly)
Returns the value of attribute current_position.
2 3 4 |
# File 'lib/maze/game/maze_player.rb', line 2 def current_position @current_position end |
#moves ⇒ Object (readonly)
Returns the value of attribute moves.
2 3 4 |
# File 'lib/maze/game/maze_player.rb', line 2 def moves @moves end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/maze/game/maze_player.rb', line 2 def name @name end |
Instance Method Details
#move(orientation) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/maze/game/maze_player.rb', line 10 def move(orientation) case orientation when :top move_top when :bottom move_bottom when :left move_left when :right move_right end end |
#move_bottom ⇒ Object
27 28 29 |
# File 'lib/maze/game/maze_player.rb', line 27 def move_bottom do_move [0, 1] end |
#move_left ⇒ Object
31 32 33 |
# File 'lib/maze/game/maze_player.rb', line 31 def move_left do_move [-1, 0] end |
#move_right ⇒ Object
35 36 37 |
# File 'lib/maze/game/maze_player.rb', line 35 def move_right do_move [1, 0] end |
#move_top ⇒ Object
23 24 25 |
# File 'lib/maze/game/maze_player.rb', line 23 def move_top do_move [0, -1] end |