Class: SplendorGame::Player
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nobles ⇒ Object
readonly
Returns the value of attribute nobles.
-
#tableau ⇒ Object
readonly
Returns the value of attribute tableau.
-
#turn_order ⇒ Object
readonly
Returns the value of attribute turn_order.
Instance Method Summary collapse
- #can_afford_noble?(noble) ⇒ Boolean
- #claim_noble(noble) ⇒ Object
-
#initialize(name, turn_order, token_limit) ⇒ Player
constructor
A new instance of Player.
- #points ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/splendor_game/player.rb', line 5 def name @name end |
#nobles ⇒ Object (readonly)
Returns the value of attribute nobles.
5 6 7 |
# File 'lib/splendor_game/player.rb', line 5 def nobles @nobles end |
#tableau ⇒ Object (readonly)
Returns the value of attribute tableau.
5 6 7 |
# File 'lib/splendor_game/player.rb', line 5 def tableau @tableau end |
#turn_order ⇒ Object (readonly)
Returns the value of attribute turn_order.
5 6 7 |
# File 'lib/splendor_game/player.rb', line 5 def turn_order @turn_order end |
Instance Method Details
#can_afford_noble?(noble) ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/splendor_game/player.rb', line 19 def can_afford_noble?(noble) noble.cost.each do |k, v| return false if @tableau.colours_on_cards(k) < v end true end |
#claim_noble(noble) ⇒ Object
26 27 28 29 30 |
# File 'lib/splendor_game/player.rb', line 26 def claim_noble(noble) return false if !can_afford_noble?(noble) @nobles << noble true end |
#points ⇒ Object
14 15 16 17 |
# File 'lib/splendor_game/player.rb', line 14 def points card_points = @tableau.cards.inject(0) { |sum,c| sum + c.points } card_points + @nobles.inject(0) { |sum,c| sum + c.points } end |