Class: CribbageGame::Player
- Inherits:
-
Object
- Object
- CribbageGame::Player
- Defined in:
- lib/cribbage_game/player.rb
Instance Attribute Summary collapse
-
#hand ⇒ Object
Returns the value of attribute hand.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#total_score ⇒ Object
Returns the value of attribute total_score.
Instance Method Summary collapse
- #discard(cards) ⇒ Object
-
#initialize(game, id) ⇒ Player
constructor
A new instance of Player.
- #play_card(card) ⇒ Object
- #score_hand ⇒ Object
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
#hand ⇒ Object
Returns the value of attribute hand.
3 4 5 |
# File 'lib/cribbage_game/player.rb', line 3 def hand @hand end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/cribbage_game/player.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/cribbage_game/player.rb', line 3 def name @name end |
#total_score ⇒ Object
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_hand ⇒ Object
22 23 24 |
# File 'lib/cribbage_game/player.rb', line 22 def score_hand @game.score_hand self end |