Class: Shithead::Turn
- Inherits:
-
Object
- Object
- Shithead::Turn
- Defined in:
- lib/shithead/turn.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(deck, stack, discards, player) ⇒ Turn
constructor
A new instance of Turn.
Constructor Details
#initialize(deck, stack, discards, player) ⇒ Turn
Returns a new instance of Turn.
6 7 8 9 10 11 12 |
# File 'lib/shithead/turn.rb', line 6 def initialize(deck, stack, discards, player) @deck = deck @stack = stack @player = player @discards = discards @offer = Shithead::AI::Offer.call player, stack.top end |
Class Method Details
.call(deck, stack, discards, player) ⇒ Object
2 3 4 |
# File 'lib/shithead/turn.rb', line 2 def self.call(deck, stack, discards, player) new(deck, stack, discards, player).call end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/shithead/turn.rb', line 14 def call if offer.empty? puts "Picking up", "" stack.release_to player else puts "Playing: #{offer.to_s}", "" offer.release_to stack while player.hand.size < 3 && !deck.empty? player.add deck.draw end end if player.clear? raise Shithead::GameOverError, "Game over, #{player.name} has won." end if stack.clearable? puts "> Clearing", "" stack.release_to discards Shithead::Turn.call deck, stack, discards, player end end |