Class: Pacman::Arcade::Player
- Inherits:
-
Object
- Object
- Pacman::Arcade::Player
- Defined in:
- lib/pacman/arcade/player.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
- #advance(maze) ⇒ Object
-
#initialize(position:, direction:) ⇒ Player
constructor
A new instance of Player.
- #queue_turn(new_direction) ⇒ Object
- #respawn ⇒ Object
Constructor Details
#initialize(position:, direction:) ⇒ Player
Returns a new instance of Player.
8 9 10 11 12 13 |
# File 'lib/pacman/arcade/player.rb', line 8 def initialize(position:, direction:) @start = position @initial_direction = direction @position = position @direction = direction end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
6 7 8 |
# File 'lib/pacman/arcade/player.rb', line 6 def direction @direction end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
6 7 8 |
# File 'lib/pacman/arcade/player.rb', line 6 def position @position end |
Instance Method Details
#advance(maze) ⇒ Object
25 26 27 28 29 |
# File 'lib/pacman/arcade/player.rb', line 25 def advance(maze) apply_queued_turn(maze) ahead = maze.wrap(position.step(direction)) @position = ahead unless maze.wall?(ahead) end |
#queue_turn(new_direction) ⇒ Object
21 22 23 |
# File 'lib/pacman/arcade/player.rb', line 21 def queue_turn(new_direction) @queued_turn = new_direction end |
#respawn ⇒ Object
15 16 17 18 19 |
# File 'lib/pacman/arcade/player.rb', line 15 def respawn @position = @start @direction = @initial_direction @queued_turn = nil end |