Class: Tundengine::Player::InRound
- Inherits:
-
Object
- Object
- Tundengine::Player::InRound
- Extended by:
- Forwardable
- Defined in:
- lib/tundengine/player/in_round.rb
Instance Attribute Summary collapse
-
#bonus_points ⇒ Object
writeonly
Sets the attribute bonus_points.
-
#declarations ⇒ Object
readonly
Returns the value of attribute declarations.
-
#hand ⇒ Object
readonly
Returns the value of attribute hand.
-
#in_match ⇒ Object
readonly
Returns the value of attribute in_match.
-
#round ⇒ Object
Returns the value of attribute round.
Instance Method Summary collapse
- #after_declaring!(declaration) ⇒ Object
- #declare!(declaration = Declarations::Null.instance) ⇒ Object
- #has_empty_baza? ⇒ Boolean
- #has_empty_hand? ⇒ Boolean
-
#initialize(player_in_match) ⇒ InRound
constructor
A new instance of InRound.
- #on_winning_trick!(trick) ⇒ Object
- #summary ⇒ Object
- #take!(trick) ⇒ Object
- #take_card!(card) ⇒ Object
- #total_round_points ⇒ Object
Constructor Details
#initialize(player_in_match) ⇒ InRound
Returns a new instance of InRound.
12 13 14 15 16 17 18 19 20 |
# File 'lib/tundengine/player/in_round.rb', line 12 def initialize(player_in_match) @in_match = player_in_match @round = :no_round_set @hand = Hand.new([]) @baza = [] @declarations = [] @round_points = 0 @bonus_points = 0 end |
Instance Attribute Details
#bonus_points=(value) ⇒ Object (writeonly)
Sets the attribute bonus_points
9 10 11 |
# File 'lib/tundengine/player/in_round.rb', line 9 def bonus_points=(value) @bonus_points = value end |
#declarations ⇒ Object (readonly)
Returns the value of attribute declarations.
8 9 10 |
# File 'lib/tundengine/player/in_round.rb', line 8 def declarations @declarations end |
#hand ⇒ Object (readonly)
Returns the value of attribute hand.
8 9 10 |
# File 'lib/tundengine/player/in_round.rb', line 8 def hand @hand end |
#in_match ⇒ Object (readonly)
Returns the value of attribute in_match.
8 9 10 |
# File 'lib/tundengine/player/in_round.rb', line 8 def in_match @in_match end |
#round ⇒ Object
Returns the value of attribute round.
10 11 12 |
# File 'lib/tundengine/player/in_round.rb', line 10 def round @round end |
Instance Method Details
#after_declaring!(declaration) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/tundengine/player/in_round.rb', line 30 def after_declaring!(declaration) if declaration.is_declarable?(hand, round.trump_suit) declarations << declaration round.after_declaring!(declaration) else raise "cannot declare #{declaration} after trick #{round.current_trick.summary} with hand #{hand}" end end |
#declare!(declaration = Declarations::Null.instance) ⇒ Object
26 27 28 |
# File 'lib/tundengine/player/in_round.rb', line 26 def declare!(declaration = Declarations::Null.instance) strategy.declare!(self, declaration) end |
#has_empty_baza? ⇒ Boolean
53 54 55 |
# File 'lib/tundengine/player/in_round.rb', line 53 def has_empty_baza? @baza.empty? end |
#has_empty_hand? ⇒ Boolean
49 50 51 |
# File 'lib/tundengine/player/in_round.rb', line 49 def has_empty_hand? hand.empty? end |
#on_winning_trick!(trick) ⇒ Object
39 40 41 42 |
# File 'lib/tundengine/player/in_round.rb', line 39 def on_winning_trick!(trick) take! trick declare! end |
#summary ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/tundengine/player/in_round.rb', line 61 def summary { name: name, hand: hand.map(&:to_s), baza: @baza.map(&:to_s) } end |
#take!(trick) ⇒ Object
44 45 46 47 |
# File 'lib/tundengine/player/in_round.rb', line 44 def take!(trick) @baza = @baza.concat trick.cards @round_points += trick.points end |
#take_card!(card) ⇒ Object
22 23 24 |
# File 'lib/tundengine/player/in_round.rb', line 22 def take_card!(card) hand << card end |
#total_round_points ⇒ Object
57 58 59 |
# File 'lib/tundengine/player/in_round.rb', line 57 def total_round_points @round_points + @bonus_points end |