Skip to content

Instantly share code, notes, and snippets.

@jmscholen
Last active August 29, 2015 13:57
Show Gist options
  • Save jmscholen/9897306 to your computer and use it in GitHub Desktop.
Save jmscholen/9897306 to your computer and use it in GitHub Desktop.
BlackJack Game
#BlackJack Game created by Jeff Scholen. Iron Yard Rails Engineering Class 3/31/2014
puts "Would you like to play blackjack? Yes or No"
playtime = gets.chomp
exit if playtime.downcase == "no"
my_cards = []
my_cards.push(base_card = rand(10))
puts "Your first card is #{base_card}."
my_cards.push(next_card = rand(10))
puts "Your second card is #{next_card}"
puts "Your card count is #{my_cards.reduce(:+)}."
puts "Would you like to Hit? Yes or No"
answer = gets.chomp
while answer.downcase == "yes"
next_card = rand(10)
my_cards.push(next_card)
puts "Next card is #{next_card}."
sum = 0
my_cards.each { |card| sum += card }
puts "Your total Card Count is #{sum}."
if sum > 21
puts "You Busted!"
exit
end
puts "Continue?"
answer = gets.chomp
end
if answer.downcase == "no"
dealer_cards=[]
dealer_cards.push(2, rand(10))
dealer_cards.each {|card| puts "Dealer has delt: #{card}"}
dealer_total = dealer_cards.reduce(:+)
while dealer_total < 17
dealer_cards.push(rand(10))
puts "The next Dealer card is #{dealer_cards.last}."
dealer_total = dealer_cards.reduce(:+)
puts "Dealer Total is #{dealer_total}. "
if dealer_total > 21
puts "Dealer Busted! You Win!!!"
exit
end
end
if dealer_total > sum
puts "Dealer wins!"
elsif dealer_total < sum
puts "You Win!"
else
puts "It's a DRAW!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment