class Tundengine::Stages::Trick

Attributes

declaration[R]

Public Class Methods

new(round) click to toggle source
Calls superclass method Tundengine::Stages::Base::new
# File lib/tundengine/stages/trick.rb, line 14
def initialize(round)
  @next_player_index = 0
  super
  @winner_turn = current_turn
  @declaration = :no_declaration
end

Public Instance Methods

after_declaring!(declaration) click to toggle source
# File lib/tundengine/stages/trick.rb, line 30
def after_declaring!(declaration)
  @declaration = declaration
  on_completed_with_declaration!
end
cards() click to toggle source
# File lib/tundengine/stages/trick.rb, line 43
def cards
  turns.map(&:card)
end
first_suit() click to toggle source
# File lib/tundengine/stages/trick.rb, line 35
def first_suit
  cards.fetch(0, Cards::Null.instance).suit
end
next_player() click to toggle source
# File lib/tundengine/stages/trick.rb, line 47
def next_player # in round
  players.fetch(@next_player_index - 1)
end
on_complete_child!(beats) click to toggle source
# 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() click to toggle source
# File lib/tundengine/stages/trick.rb, line 39
def points
  cards.reduce(0) { |acum, card| acum + card.round_points }
end
summary() click to toggle source
# 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

Protected Instance Methods

completed?() click to toggle source
# File lib/tundengine/stages/trick.rb, line 71
def completed?
  turns.length == players.length
end
is_taken_by?(card) click to toggle source
# File lib/tundengine/stages/trick.rb, line 83
def is_taken_by?(card)
  card.beats? winner_card, trump_suit
end
Also aliased as: passes_card_percolator?
new_child() click to toggle source
# File lib/tundengine/stages/trick.rb, line 62
def new_child
  Turn.new(self)
end
new_child_in_play!() click to toggle source
# File lib/tundengine/stages/trick.rb, line 66
def new_child_in_play! # before starting a new turn
  @next_player_index += 1
  super
end
on_completed!() click to toggle source
# File lib/tundengine/stages/trick.rb, line 75
def on_completed!
  winner_player.on_winning_trick!(self)
end
on_completed_with_declaration!() click to toggle source
# File lib/tundengine/stages/trick.rb, line 79
def on_completed_with_declaration!
  round.on_complete_child!
end
passes_card_percolator?(card)
Alias for: is_taken_by?