Class: Tundengine::Stages::Trick

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Includes:
CardPercolator
Defined in:
lib/tundengine/stages/trick.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#child_in_play, #children, #parent

Instance Method Summary collapse

Methods included from CardPercolator

#percolate

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

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

#cardsObject



43
44
45
# File 'lib/tundengine/stages/trick.rb', line 43

def cards
  turns.map(&:card)
end

#first_suitObject



35
36
37
# File 'lib/tundengine/stages/trick.rb', line 35

def first_suit
  cards.fetch(0, Cards::Null.instance).suit
end

#next_playerObject

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

#pointsObject



39
40
41
# File 'lib/tundengine/stages/trick.rb', line 39

def points
  cards.reduce(0) { |acum, card| acum + card.round_points }
end

#summaryObject



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