Created
March 31, 2014 16:15
-
-
Save RyanSnodgrass/9895982 to your computer and use it in GitHub Desktop.
BlackJack Game
This file contains hidden or 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
| def blackjack | |
| base_card = rand(1..10) | |
| next_card = rand(1..10) | |
| puts "your number is #{base_card} and #{next_card}." | |
| puts "continue? Say Yes or No." | |
| answer = gets.chomp.downcase | |
| my_cards = [base_card, next_card] | |
| while answer == "yes" | |
| another_card = rand(1..10) | |
| puts "your next card is #{next_card}" | |
| my_cards.push(another_card) | |
| sum = 0 | |
| my_cards.each { |card| sum += card } | |
| puts "your total card sum is #{sum}" | |
| if sum == 21 | |
| puts "you win" | |
| return | |
| elsif sum > 21 | |
| puts "BUST" | |
| return | |
| end | |
| puts "continue?" | |
| answer = gets.chomp | |
| end | |
| end | |
| blackjack | |
| puts "play again?" | |
| play = gets.chomp.downcase | |
| while play == "yes" | |
| blackjack | |
| puts "play again?" | |
| play = gets.chomp | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment