Class: GooseGame::Player
- Inherits:
-
Object
- Object
- GooseGame::Player
- Defined in:
- lib/goose_game/player.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
-
#initialize(name) ⇒ Player
constructor
A new instance of Player.
- #move(pos) ⇒ Object
- #prev ⇒ Object
- #won? ⇒ Boolean
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute name.
3 4 5 |
# File 'lib/goose_game/player.rb', line 3 def name @name end |
#position ⇒ Object
Returns the value of attribute position.
4 5 6 |
# File 'lib/goose_game/player.rb', line 4 def position @position end |
Instance Method Details
#move(pos) ⇒ Object
14 15 16 17 |
# File 'lib/goose_game/player.rb', line 14 def move(pos) return if pos == @position @prev, @position = @position, pos.to_i end |
#prev ⇒ Object
23 24 25 |
# File 'lib/goose_game/player.rb', line 23 def prev @prev.to_i.zero? ? START : @prev end |
#won? ⇒ Boolean
19 20 21 |
# File 'lib/goose_game/player.rb', line 19 def won? @position == FINISH end |