Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 40 additions & 0 deletions .idea/Episode1-Summer2012.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/scopes/scope_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 27 additions & 8 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[0,1].capitalize}"
end

end
Expand Down Expand Up @@ -75,17 +75,29 @@ def initialize

def hit
@player_hand.hit!(@deck)
if @player_hand.value > 21
stand
else
status(:unstood)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you could not have the else block here.

Or, more in the language of the game:

if @player_hand.value > 21
  bust!
end

end

end

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

def status
def status (stood)
if stood == :stood
dlr_cards_to_show = @dealer_hand.cards

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like if you create a DealerHand class and contain that functionality there

else
dlr_cards_to_show = ['X','X']
end
{:player_cards=> @player_hand.cards,
:player_value => @player_hand.value,
:dealer_cards => @dealer_hand.cards,
:dealer_cards => dlr_cards_to_show,
:dealer_value => @dealer_hand.value,
:winner => @winner}
end
Expand All @@ -103,7 +115,7 @@ def determine_winner(player_value, dealer_value)
end

def inspect
status
status (:unstood)
end
end

Expand Down Expand Up @@ -134,8 +146,8 @@ def inspect
end

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

Expand Down Expand Up @@ -211,7 +223,7 @@ def inspect
Game.new.dealer_hand.cards.length.should eq(2)
end
it "should have a status" do
Game.new.status.should_not be_nil
Game.new.status(:unstood).should_not be_nil
end
it "should hit when I tell it to" do
game = Game.new
Expand All @@ -222,7 +234,14 @@ def inspect
it "should play the dealer hand when I stand" do
game = Game.new
game.stand
game.status[:winner].should_not be_nil
game.status(:stood)[:winner].should_not be_nil
end

it "should stand for the player when player hand is 21 or more" do
game = Game.new
let(game.player_hand.value) {21}
game.hit
game.should_receive(stand)
end

describe "#determine_winner" do
Expand Down