Class: Tundengine::Stages::Trick
Instance Attribute Summary collapse
-
#declaration ⇒ Object
readonly
Returns the value of attribute declaration.
Attributes inherited from Base
#child_in_play, #children, #parent
Instance Method Summary collapse
- #after_declaring!(declaration) ⇒ Object
- #cards ⇒ Object
- #first_suit ⇒ Object
-
#initialize(round) ⇒ Trick
constructor
A new instance of Trick.
-
#next_player ⇒ Object
in round.
-
#on_complete_child!(beats) ⇒ Object
when the current turn is completed.
- #points ⇒ Object
- #summary ⇒ Object
Methods included from CardPercolator
Methods inherited from Base
#as_hash, #declare!, #fast_forward!, #lock!, #play!, #rewind!
Constructor Details
#initialize(round) ⇒ Trick
Returns a new instance of Trick.
14 15 16 17 18 19 |
# File 'lib/tundengine/stages/trick.rb', line 14 def initialize(round) @next_player_index = 0 super @winner_turn = current_turn @declaration = :no_declaration end |
Instance Attribute Details
#declaration ⇒ Object (readonly)
Returns the value of attribute declaration.
12 13 14 |
# File 'lib/tundengine/stages/trick.rb', line 12 def declaration @declaration end |
Instance Method Details
#after_declaring!(declaration) ⇒ Object
30 31 32 33 |
# File 'lib/tundengine/stages/trick.rb', line 30 def after_declaring!(declaration) @declaration = declaration on_completed_with_declaration! end |
#cards ⇒ Object
43 44 45 |
# File 'lib/tundengine/stages/trick.rb', line 43 def cards turns.map(&:card) end |
#first_suit ⇒ Object
35 36 37 |
# File 'lib/tundengine/stages/trick.rb', line 35 def first_suit cards.fetch(0, Cards::Null.instance).suit end |
#next_player ⇒ Object
in round
47 48 49 |
# File 'lib/tundengine/stages/trick.rb', line 47 def next_player # in round players.fetch(@next_player_index - 1) end |
#on_complete_child!(beats) ⇒ Object
when the current turn is completed
25 26 27 28 |
# File 'lib/tundengine/stages/trick.rb', line 25 def on_complete_child!(beats) # when the current turn is completed @winner_turn = current_turn if beats super() end |
#points ⇒ Object
39 40 41 |
# File 'lib/tundengine/stages/trick.rb', line 39 def points cards.reduce(0) { |acum, card| acum + card.round_points } end |
#summary ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/tundengine/stages/trick.rb', line 51 def summary { cards: cards.map(&:to_s), winner_player: winner_player.name, winner_card: winner_card.to_s, declaration: declaration.to_s, } end |