Created
March 31, 2014 16:11
-
-
Save switzersc/9895894 to your computer and use it in GitHub Desktop.
blackjack game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
game_decision = "yes" | |
while game_decision == "yes" | |
base_card = rand(10) | |
puts "Your number is #{base_card}." | |
puts "Continue? Yes or No" | |
answer = gets.chomp | |
my_cards = [base_card] | |
while answer.downcase == "yes" | |
next_card = rand(10) | |
my_cards << next_card | |
puts "Next card is #{next_card}" | |
sum = 0 | |
my_cards.each { |card| sum += card } | |
puts "Your total card sum is #{sum}." | |
if sum == 21 | |
puts "You win!" | |
exit | |
elsif sum > 21 | |
puts "BUST" | |
exit | |
end | |
puts "Continue?" | |
answer = gets.chomp | |
end | |
puts "Play again? yes or no" | |
game_decision = gets.chomp | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment