Class: Tundengine::Stages::Round

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

Constant Summary collapse

LAST_TRICK_BONUS_POINTS =
10

Instance Attribute Summary collapse

Attributes inherited from Base

#child_in_play, #children, #parent

Instance Method Summary collapse

Methods inherited from Base

#as_hash, #fast_forward!, #lock!, #play!, #rewind!

Constructor Details

#initialize(match, players_in_round, trump_suit) ⇒ Round

Returns a new instance of Round.



13
14
15
16
17
18
19
20
# File 'lib/tundengine/stages/round.rb', line 13

def initialize(match, players_in_round, trump_suit)
  @players = players_in_round
  @players.each { |p| p.round = self }
  @trump_suit = trump_suit.freeze
  @last_declaration = Declarations::Null.instance
  super(match)
  Dealer.instance.deal!(players, trump_suit)
end

Instance Attribute Details

#last_declarationObject (readonly)

Returns the value of attribute last_declaration.



9
10
11
# File 'lib/tundengine/stages/round.rb', line 9

def last_declaration
  @last_declaration
end

#playersObject (readonly)

Returns the value of attribute players.



9
10
11
# File 'lib/tundengine/stages/round.rb', line 9

def players
  @players
end

#trump_suitObject (readonly)

Returns the value of attribute trump_suit.



9
10
11
# File 'lib/tundengine/stages/round.rb', line 9

def trump_suit
  @trump_suit
end

Instance Method Details

#after_declaring!(declaration) ⇒ Object



40
41
42
43
# File 'lib/tundengine/stages/round.rb', line 40

def after_declaring!(declaration)
  current_trick.after_declaring!(declaration)
  @last_declaration = declaration
end

#declare!(declaration = Declarations::Null.instance) ⇒ Object



26
27
28
# File 'lib/tundengine/stages/round.rb', line 26

def declare!(declaration = Declarations::Null.instance)
  last_winner_player.declare!(declaration)
end

#on_complete_child!Object

when the current trick is completed



30
31
32
33
# File 'lib/tundengine/stages/round.rb', line 30

def on_complete_child! # when the current trick is completed
  super
  rotate_players!
end

#on_completed!Object



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

def on_completed!
  last_winner_player.bonus_points = LAST_TRICK_BONUS_POINTS
  parent.on_complete_child!(result)
end

#summaryObject



45
46
47
48
49
50
# File 'lib/tundengine/stages/round.rb', line 45

def summary
  {
    trump_suit: trump_suit.to_s,
    players: players.map(&:summary)
  }
end