Class: SplendorGame::Player

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, turn_order, token_limit) ⇒ Player

Returns a new instance of Player.



7
8
9
10
11
12
# File 'lib/splendor_game/player.rb', line 7

def initialize(name, turn_order, token_limit)
  @name = name
  @turn_order = turn_order
  @tableau = Tableau.new(token_limit)
  @nobles = Array.new()
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/splendor_game/player.rb', line 5

def name
  @name
end

#noblesObject (readonly)

Returns the value of attribute nobles.



5
6
7
# File 'lib/splendor_game/player.rb', line 5

def nobles
  @nobles
end

#tableauObject (readonly)

Returns the value of attribute tableau.



5
6
7
# File 'lib/splendor_game/player.rb', line 5

def tableau
  @tableau
end

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

Returns:

  • (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

#pointsObject



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