Last active
December 17, 2015 04:39
-
-
Save mjhea0/5552118 to your computer and use it in GitHub Desktop.
dumb blackjack game that needs to be be refactured
smarter - https://github.com/mjhea0/blackjack-sinatra
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
| puts | |
| print "What's your name? " | |
| name = gets.chomp | |
| puts "Hi, #{name}, welcome to Blackjack!" | |
| puts | |
| def random_cards() | |
| first_card = Random.rand(1..10) | |
| second_card = Random.rand(1..10) | |
| return both_cards = {"first" => first_card, "second" => second_card} | |
| end | |
| computer_hand = random_cards() | |
| computer_card_1, computer_card_2 = computer_hand['first'], computer_hand['second'] | |
| computer_total = computer_card_1 + computer_card_2 | |
| player_hand = random_cards() | |
| player_card_1, player_card_2 = player_hand['first'], player_hand['second'] | |
| player_total = player_card_1 + player_card_2 | |
| print "The computer's cards are ", computer_card_1, " and ", computer_card_2, ", and the total is ", computer_total,".\n" | |
| print name,"'s cards are ", player_card_1, " and ", player_card_2, ", and the total is ", player_total, ".\n" | |
| puts | |
| if computer_total > player_total | |
| print "The computer won!" | |
| elsif computer_total < player_total | |
| print name, " won!" | |
| else | |
| print "It's a tie." | |
| end | |
| puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment