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
36 changes: 30 additions & 6 deletions blackjack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def value
end

def to_s
"#{@value}-#{suit}"
suit_abbreviation = "C" if @suit == :clubs
suit_abbreviation = "D" if @suit == :diamonds
suit_abbreviation = "H" if @suit == :hearts
suit_abbreviation = "S" if @suit == :spaids
"#{suit_abbreviation}#{@value}"
end

end
Expand All @@ -29,7 +33,7 @@ def initialize

def self.build_cards
cards = []
[:clubs, :diamonds, :spades, :hearts].each do |suit|
[:clubs, :diamonds, :spaids, :hearts].each do |suit|
(2..10).each do |number|
cards << Card.new(suit, number)
end
Expand Down Expand Up @@ -75,6 +79,7 @@ def initialize

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

def stand
Expand All @@ -83,10 +88,17 @@ def stand
end

def status
if @winner.nil?
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 Expand Up @@ -213,12 +225,24 @@ def inspect
it "should have a status" do
Game.new.status.should_not be_nil
end
it "should not display dealers full hand until player stands" do
Game.new.status[:dealer_cards][0].should eq("XX")
end
it "should not display dealers score until player stands" do
Game.new.status[:dealer_value].should eq("XX")
end
it "should hit when I tell it to" do
game = Game.new
game.hit
game.player_hand.cards.length.should eq(3)
end

it "should stand when player busts" do
game = Game.new
until game.status[:player_value] > 21
game.hit
end
game.status[:winner].should_not be_nil
end
it "should play the dealer hand when I stand" do
game = Game.new
game.stand
Expand Down