Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions blackjack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def value
end

def to_s
"#{@value}-#{suit}"
"#{suit[0].upcase}#{@value}"
end

end
Expand Down Expand Up @@ -69,24 +69,36 @@ def initialize
@deck = Deck.new
@player_hand = Hand.new
@dealer_hand = Hand.new
@hidden = true
2.times { @player_hand.hit!(@deck) }
2.times { @dealer_hand.hit!(@deck) }
end

def hit
@player_hand.hit!(@deck)
stand if @player_hand.value > 21
status
end

def stand
@hidden = false
@dealer_hand.play_as_dealer(@deck)
@winner = determine_winner(@player_hand.value, @dealer_hand.value)
status
end

def status
if @hidden
dealer_hand = ["XX", @dealer_hand.cards[1]]
dealer_value = "XX"
else
dealer_hand = @dealer_hand.cards
dealer_value = @dealer_hand.value
end
{:player_cards=> @player_hand.cards,
:player_value => @player_hand.value,
:dealer_cards => @dealer_hand.cards,
:dealer_value => @dealer_hand.value,
:dealer_cards => dealer_hand,
:dealer_value => dealer_value,
:winner => @winner}
end

Expand Down Expand Up @@ -135,7 +147,7 @@ def inspect

it "should be formatted nicely" do
card = Card.new(:diamonds, "A")
card.to_s.should eq("A-diamonds")
card.to_s.should eq("DA")
end
end

Expand Down