Created
July 28, 2013 21:23
-
-
Save marcoroman89/6100302 to your computer and use it in GitHub Desktop.
The start of my procedural 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
# Interactive Ruby Based Blackjack Game | |
def calculate_total(cards) #[['H', '3'] ['K', '7']] | |
end | |
puts "Welcome to Ruby Blackjack" | |
suits = ['H', 'D', 'S', 'C'] | |
cards = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] | |
deck = suits.product(cards) | |
deck.shuffle! | |
# Deal Cards | |
mycards = [] | |
dealercards = [] | |
mycards << deck.pop | |
dealercards << deck.pop | |
mycards << deck.pop | |
dealercards << deck.pop | |
dealertotal = calculate_total(dealercards) | |
mytotal = calculate_total(mycards) | |
# Show the Cards | |
puts "The dealer has: #{dealercards[0]} and #{dealercards[1]}, for a total of #{dealertotal}" | |
puts "You have #{mycards[0]} and #{mycards[1]}, for a total of #{mytotal}" | |
puts "" | |
# Show What the Player Wants to Do | |
puts "What would you like to do? Chose either 1) to hit, or 2) to stay" | |
hit_or_stay = gets.chomp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment