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.
-
#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 |
# File 'lib/maze/game/maze_player.rb', line 4 def initialize(current_position, name) @current_position = current_position @name = name 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 |
#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
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/maze/game/maze_player.rb', line 9 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
26 27 28 |
# File 'lib/maze/game/maze_player.rb', line 26 def move_bottom do_move [0, 1] end |
#move_left ⇒ Object
30 31 32 |
# File 'lib/maze/game/maze_player.rb', line 30 def move_left do_move [-1, 0] end |
#move_right ⇒ Object
34 35 36 |
# File 'lib/maze/game/maze_player.rb', line 34 def move_right do_move [1, 0] end |
#move_top ⇒ Object
22 23 24 |
# File 'lib/maze/game/maze_player.rb', line 22 def move_top do_move [0, -1] end |