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
23 changes: 18 additions & 5 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}"
"#{@value}#{suit.to_s.chars.first.upcase}"
end

end
Expand Down Expand Up @@ -75,15 +75,28 @@ def initialize

def hit
@player_hand.hit!(@deck)
if @player_hand.value > 21
puts "Player busted!"
stand
end_status
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than two methods, one names "end_status" and one named "pre_status", I think you should have 1 method "status" that returns different data based on its game state

else
pre_status
end
end

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

def status
{:player_cards=> @player_hand.cards,
def pre_status
{ :player_cards => @player_hand.cards,
:player_value => @player_hand.value,
:dealer_cards => @dealer_hand.cards[0] }
end

def end_status
{:player_cards => @player_hand.cards,
:player_value => @player_hand.value,
:dealer_cards => @dealer_hand.cards,
:dealer_value => @dealer_hand.value,
Expand All @@ -103,7 +116,7 @@ def determine_winner(player_value, dealer_value)
end

def inspect
status
pre_status
end
end

Expand Down Expand Up @@ -135,7 +148,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("AD")
end
end

Expand Down