Class: Tundengine::Player::InTurn

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tundengine/player/in_turn.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(turn, player_in_round) ⇒ InTurn

Returns a new instance of InTurn.



10
11
12
13
# File 'lib/tundengine/player/in_turn.rb', line 10

def initialize(turn, player_in_round)
  @turn     = turn
  @in_round = player_in_round
end

Instance Attribute Details

#in_roundObject (readonly)

Returns the value of attribute in_round.



8
9
10
# File 'lib/tundengine/player/in_turn.rb', line 8

def in_round
  @in_round
end

#turnObject (readonly)

Returns the value of attribute turn.



8
9
10
# File 'lib/tundengine/player/in_turn.rb', line 8

def turn
  @turn
end

Instance Method Details

#after_playing!(card) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/tundengine/player/in_turn.rb', line 19

def after_playing!(card)
  playable_cards, beats = hand.playable_cards(turn.trick)
  if playable_cards.include? card
    hand.delete card
    turn.on_completed!(card, beats)
  else
    raise "cannot play card #{card} in trick with cards #{turn.trick.cards.map(&:to_s)} when your hand is #{@hand.map(&:to_s)}"
  end
end

#play!(card = Cards::Null.instance) ⇒ Object



15
16
17
# File 'lib/tundengine/player/in_turn.rb', line 15

def play!(card = Cards::Null.instance)
  strategy.play!(self, card)
end