Class: GooseGame::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/goose_game/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Player

Returns a new instance of Player.



6
7
8
9
10
# File 'lib/goose_game/player.rb', line 6

def initialize(name)
  @name = name
  @position = START
  @prev = nil
end

Instance Attribute Details

#nameObject (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

#positionObject

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

#prevObject



23
24
25
# File 'lib/goose_game/player.rb', line 23

def prev
  @prev.to_i.zero? ? START : @prev
end

#won?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/goose_game/player.rb', line 19

def won?
  @position == FINISH
end