Class: Player
- Inherits:
-
Object
- Object
- Player
- Defined in:
- lib/player.rb
Instance Method Summary collapse
- #draw ⇒ Object
- #exchange(tiles) ⇒ Object
-
#initialize(board, pouch, rack = []) ⇒ Player
constructor
A new instance of Player.
- #play(move) ⇒ Object
- #score ⇒ Object
Constructor Details
#initialize(board, pouch, rack = []) ⇒ Player
Returns a new instance of Player.
2 3 4 5 6 7 |
# File 'lib/player.rb', line 2 def initialize(board, pouch, rack = []) @board = board @pouch = pouch @score = 0 @rack = rack end |
Instance Method Details
#draw ⇒ Object
19 20 21 22 |
# File 'lib/player.rb', line 19 def draw need = 7 - @rack.length @rack.concat(@pouch.draw(need)) end |
#exchange(tiles) ⇒ Object
24 25 26 27 |
# File 'lib/player.rb', line 24 def exchange(tiles) remove_tiles(tiles) @rack.concat(@pouch.exchange(tiles)) end |
#play(move) ⇒ Object
9 10 11 12 13 |
# File 'lib/player.rb', line 9 def play(move) score, tiles_used = @board.play(move) @score += score remove_tiles(tiles_used) end |
#score ⇒ Object
15 16 17 |
# File 'lib/player.rb', line 15 def score @score end |