class Blackjack::Turn
Constants
- HIT
- VALID_OPTIONS
Attributes
deck[RW]
input[RW]
player[RW]
Public Class Methods
new(args)
click to toggle source
# File lib/blackjack/turn.rb, line 7 def initialize(args) @player = args[:player] @deck = args[:deck] @input end
Public Instance Methods
take()
click to toggle source
# File lib/blackjack/turn.rb, line 13 def take 2.times do puts deal_to_player end until over? puts player.formatted_score puts hit_or_stand end end
Private Instance Methods
deal_to_player()
click to toggle source
# File lib/blackjack/turn.rb, line 26 def deal_to_player "#{player.name} was dealt #{deck.deal_to(player.hand.cards).display}" end
get_action()
click to toggle source
# File lib/blackjack/turn.rb, line 56 def get_action gets.chomp.downcase end
get_input()
click to toggle source
# File lib/blackjack/turn.rb, line 43 def get_input self.input = invalid_input until VALID_OPTIONS.include?(self.input) puts "That is not a valid choice!" if !self.input == invalid_input print "Hit or Stand? (h/s) " self.input = get_action end end
hit_or_stand()
click to toggle source
# File lib/blackjack/turn.rb, line 30 def hit_or_stand get_input if player.human? player_hits! ? deal_to_player : player.stand! end
invalid_input()
click to toggle source
# File lib/blackjack/turn.rb, line 52 def invalid_input "#{VALID_OPTIONS}" end
over?()
click to toggle source
# File lib/blackjack/turn.rb, line 22 def over? player.bust? || player.stand? end
player_chooses_hit?()
click to toggle source
# File lib/blackjack/turn.rb, line 39 def player_chooses_hit? input == HIT end
player_hits!()
click to toggle source
# File lib/blackjack/turn.rb, line 35 def player_hits! player.human? ? player_chooses_hit? : player.wants_to_hit? end