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
42 changes: 36 additions & 6 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].upcase}"
end

end
Expand Down Expand Up @@ -64,7 +64,8 @@ def play_as_dealer(deck)
end

class Game
attr_reader :player_hand, :dealer_hand
attr_reader :player_hand

def initialize
@deck = Deck.new
@player_hand = Hand.new
Expand All @@ -74,7 +75,8 @@ def initialize
end

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

def stand
Expand All @@ -85,7 +87,7 @@ def stand
def status
{:player_cards=> @player_hand.cards,
:player_value => @player_hand.value,
:dealer_cards => @dealer_hand.cards,
:dealer_cards => dealer_cards,
Copy link
Member

Choose a reason for hiding this comment

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

Yay! This is nice,

:dealer_value => @dealer_hand.value,
:winner => @winner}
end
Expand All @@ -105,6 +107,14 @@ def determine_winner(player_value, dealer_value)
def inspect
status
end

def dealer_cards
@winner ? @dealer_hand.cards : [@dealer_hand.cards[0], 'XX']
end

def player_cards
@player_hand.cards
end
end


Expand Down Expand Up @@ -135,7 +145,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 Expand Up @@ -208,7 +218,7 @@ def inspect
Game.new.player_hand.cards.length.should eq(2)
end
it "should have a dealers hand" do
Game.new.dealer_hand.cards.length.should eq(2)
Game.new.dealer_cards.length.should eq(2)
end
it "should have a status" do
Game.new.status.should_not be_nil
Expand All @@ -225,6 +235,26 @@ def inspect
game.status[:winner].should_not be_nil
end

it "should stand for me if I bust" do
game = Game.new
while game.player_hand.value <= 21
game.hit
end
game.status[:winner].should eq(:dealer)
end

describe "dealer cards" do
it "should not display dealer cards until player stands" do
game = Game.new
game.dealer_cards[1].should eq('XX')
game.status[:dealer_cards][1].should eq('XX')
end

it "should display dealer cards once player stands" do

end
end

describe "#determine_winner" do
it "should have dealer win when player busts" do
Game.new.determine_winner(22, 15).should eq(:dealer)
Expand Down