-
Notifications
You must be signed in to change notification settings - Fork 44
Feature: Completed all examples #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ def value | |
| end | ||
|
|
||
| def to_s | ||
| "#{@value}-#{suit}" | ||
| "#{@value}#{@suit[0,1].capitalize}" | ||
| end | ||
|
|
||
| end | ||
|
|
@@ -75,17 +75,29 @@ def initialize | |
|
|
||
| def hit | ||
| @player_hand.hit!(@deck) | ||
| if @player_hand.value > 21 | ||
| stand | ||
| else | ||
| status(:unstood) | ||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like if you create a |
||
| 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 | ||
|
|
@@ -103,7 +115,7 @@ def determine_winner(player_value, dealer_value) | |
| end | ||
|
|
||
| def inspect | ||
| status | ||
| status (:unstood) | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
||
There was a problem hiding this comment.
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: