Class: CribbageGame::Player

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game, id) ⇒ Player

Returns a new instance of Player.



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

def initialize game, id
  @id = id
  @game = game
  @hand = {}
  @total_score = 0
end

Instance Attribute Details

#handObject

Returns the value of attribute hand.



3
4
5
# File 'lib/cribbage_game/player.rb', line 3

def hand
  @hand
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/cribbage_game/player.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/cribbage_game/player.rb', line 3

def name
  @name
end

#total_scoreObject

Returns the value of attribute total_score.



3
4
5
# File 'lib/cribbage_game/player.rb', line 3

def total_score
  @total_score
end

Instance Method Details

#discard(cards) ⇒ Object



12
13
14
15
16
# File 'lib/cribbage_game/player.rb', line 12

def discard cards
  [cards].flatten.each do |card|
    @game.discard self, card
  end
end

#play_card(card) ⇒ Object



18
19
20
# File 'lib/cribbage_game/player.rb', line 18

def play_card card
  @game.play_card self, card
end

#score_handObject



22
23
24
# File 'lib/cribbage_game/player.rb', line 22

def score_hand
  @game.score_hand self
end