Skip to content

Instantly share code, notes, and snippets.

@Osagiede
Last active August 29, 2015 13:59
Show Gist options
  • Save Osagiede/10562512 to your computer and use it in GitHub Desktop.
Save Osagiede/10562512 to your computer and use it in GitHub Desktop.
My first game in ruby
card_suits = ["Hearts", "Spades", "Clubs", "Diamonds"]
card_values = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"]
deck = []
# Loop over each suit
card_suits.each do |suit|
card_values.each do |card|
deck << [suit, card]
end
end
# Acess get values of one and eleven
deck[12] << 1 << 11
deck[38] << 1 << 11
deck[25] << 1 << 11
deck[51] << 1 << 11
# Queens get values of ten
deck[10] << 10
deck[36] << 10
deck[23] << 10
deck[49] << 10
# Kings get values of ten
deck[11] << 10
deck[37] << 10
deck[24] << 10
deck[50] << 10
# Jacks get values of ten
deck[9] << 10
deck[35] << 10
deck[22] << 10
deck[48] << 10
deck.shuffle!
puts
# Methods(Functions) that play as commands in the game
# Ideas: Add more methods in future?
def comparing_game_points(user_cards, cpu_cards)
if cpu_cards && user_cards > 21
puts
puts "No one wins."
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif cpu_cards == user_cards
puts
puts "It is a tie!"
puts "How rare is that!"
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif cpu_cards == 21 && user_cards != 21 # Computer has blackjack and User is not equal to blackjack
puts
puts "Computer wins."
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif cpu_cards < 21 && user_cards > 21 # Computer is less than blackjack and User is bust!
puts
puts "Computer wins."
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif cpu_cards < 21 && user_cards < cpu_cards
puts
puts "Computer wins."
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif user_cards == 21 && cpu_cards != 21
puts
puts "Congratulations! You win!"
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif user_cards < 21 && cpu_cards > 21
puts
puts "Congratulations! You win!"
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
else user_cards < 21 && user_cards < cpu_cards
puts
puts "Congratulations! You win!"
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
end
end
def commands
key_commands = %(
During the game..
Enter h to recieve a random number card value.
Enter s to stay with your current amount of points.
Enter help to see the rules again.
Enter xhelp for elaboration on the rules.
Enter commands to see these commands again.
)
puts "#{key_commands}"
end
def help
begin
puts
key_help = %(
21 is a card game.
It is the most widely played casino banking game in the world.
Your opponent will be the computer.
The game is very simple to play, here's how you play.
Try to get a number card value to as close to 21 as you can.
Anything beyond 21 is an automatic loss.
If you get a number card value of 21, you automatically win.
)
puts "#{key_help}"
end
end
def xhelp
x_help = %(
You have two objectives:
Get more points then your opponent(computer).
Get the highest card value possible without going over blackjack.
Your opponent is the computer.
If you get 21 points before cpu then you automatically win.
If you have a number card value less than computer then cpu wins.
However, you want to avoid going over 21 or you lose.
To get any amount of cards, you need to make a selection.
-----------------------------------------------------------------------
There are two selections that are made in 21
Hit and Stay
About Hit:
-----------------------------------------------------------------------
- To select hit, enter in h.
- Hit will add a random number card value 1 - 11
to your existing amount of points.
- WARNING!: If it is used to often then,
you might go over 21 and lose the game.
-In order to avoid losing the game,
you would choose a different selection (stay).
About Stay:
-----------------------------------------------------------------------
- To select stay, enter in s.
- Stay will not to add any more points to your existing amount of points.
- You would select stay if you are confident with the amount of points
you possess that wont go over blackjack.
- This selection cannot be undone so think twice before
making this decision.
)
puts "#{x_help}"
end
# For Computer
cpu_card_one = deck.first
cpu_card_two = deck.first
cpu_cards = cpu_card_one[1].to_i + cpu_card_two[1].to_i
# Computer gets dealt as many cards as possible while trying not to go over 17, lines 111 - 188
loop {
rand_card = deck.first
case rand_card
when ["Hearts", "Ace", 1, 11]
if cpu_cards < 11
cpu_cards += rand_card[3].to_i
deck.delete(rand_card)
else
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
end
when ["Clubs", "Ace", 1, 11]
if cpu_cards < 11
cpu_cards += rand_card[3].to_i
deck.delete(rand_card)
else
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
end
when ["Spades", "Ace", 1, 11]
if cpu_cards < 11
cpu_cards += rand_card[3].to_i
deck.delete(rand_card)
else
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
end
when ["Diamonds", "Ace", 1, 11]
if cpu_cards < 11
cpu_cards += rand_card[3].to_i
deck.delete(rand_card)
else
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
end
when ["Hearts", "Queen", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Clubs", "Queen", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Spades", "Queen", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Diamonds", "Queen", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Hearts", "King", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Clubs", "King", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Spades", "King", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Diamonds", "King", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Hearts", "Jack", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Clubs", "Jack", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Spades", "Jack", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Diamonds", "Jack", 10]
cpu_cards += rand_card[2].to_i
deck.delete(rand_card)
else
cpu_cards += rand_card[1].to_i
deck.delete(rand_card)
end
break if cpu_cards >= 17
}
=begin
end
# Computer asks the user if they would like to play, lines 195 - 310
puts "~Blackjack~"
puts
puts "Welcome to 21, would you like to play?"
print "(Y/N): "
user_input = gets.chomp
if (user_input != "Y") && (user_input != "N")
begin
puts
puts "What was your answer, I didn't catch that."
print "Please enter in either 'Y'(Yes) or 'N'(No): "
user_input = gets.chomp
end while (user_input != "Y") && (user_input != "N")
end
if user_input == "Y"
puts
puts "Progress: 1/3"
puts
end
if user_input == "N"
puts
puts "Have a nice day!"
abort
end
# Second: Have the computer ask if we know how to play
# If computer doesn't know how to play then have the computer explain the rules and commands
puts "Do you know how to play 21?"
print "(Y/N): "
user_input = gets.chomp
if (user_input != "Y") && (user_input != "N")
begin
puts
puts "What was your answer, I didn't catch that."
print "Please enter in either 'Y'(Yes) or 'N'(No): "
user_input = gets.chomp
end while (user_input != "Y") && (user_input != "N")
end
if user_input == "N"
help
puts "Please enter the text below when you're ready."
puts '- - -> "I got it"'
user_input = gets.chomp
if user_input != "I got it"
begin
puts
puts "I am sorry, please enter in the text when you're ready."
puts '- - -> "I got it"'
user_input = gets.chomp
end while user_input != "I got it"
puts
puts "Progress: 2/3"
puts
else user_input == "I got it"
puts
puts "Progress: 2/3"
puts
end
else user_input == "Y"
puts
puts "Progress: 2/3"
puts
end
puts "Do you know the commands of this game to play 21?"
print "(Y/N): "
user_input = gets.chomp
if (user_input != "Y") && (user_input != "N")
begin
puts
puts "What was your answer, I didn't catch that."
print "Please enter in either 'Y'(Yes) or 'N'(No): "
user_input = gets.chomp
end while (user_input != "Y") && (user_input != "N")
end
if user_input == "N"
commands
puts "Please enter the text below when you're ready"
puts '- - -> "I got it"'
user_input = gets.chomp
puts
if user_input != "I got it"
begin
puts "I am sorry, please enter in the text when you're ready."
puts '- - -> "I got it"'
user_input = gets.chomp
puts
end while user_input != "I got it"
puts "Progress: 3/3"
puts
puts "Great, lets get started!"
puts "*Dealing cards*"
sleep 2
else user_input == "I got it"
puts
puts "Progress: 3/3"
puts
puts "Great, lets get started!"
puts "*Dealing cards*"
sleep 2
end
else user_input == "Y"
puts
puts "Progress: 3/3"
puts
puts "Great, lets get started!"
puts "*Dealing cards*"
sleep 2
end
# Cpu gets its points before the user even starts, lines 312 - 575
=end
# Two cards are dealt to user after user agrees to play blackjack, lines 316 - 583
user_cards = 0
cards_user_has = []
# Added 7:08 AM 6/4/14, Store and display cards user has
card_one = deck.first
=begin
if card_one[1] == "Ace"
print "You have recieved an #{card_one[1]} of #{card_one[0]} and "
else
print "You have recieved a #{card_one[1]} of #{card_one[0]} and "
end
=end
# Commenting out code, trying to find new way to display cards one and two
# The first card would get added to user cards and deleted from the deck (Array)
case card_one
when ["Hearts", "Ace", 1, 11]
cards_user_has << card_one
puts
puts "You have received an #{card_one[1]} of #{card_one[0]}"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += card_one[2]
deck.delete(card_one)
else
user_cards += card_one[3]
deck.delete(card_one)
end
when ["Clubs", "Ace", 1, 11]
cards_user_has << card_one
puts
puts "You have received an #{card_one[1]} of #{card_one[0]}"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += card_one[2]
deck.delete(card_one)
else
user_cards += card_one[3]
deck.delete(card_one)
end
when ["Spades", "Ace", 1, 11]
cards_user_has << card_one
puts
puts "You have recieved an #{card_one[1]} of #{card_one[0]}"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += card_one[2]
deck.delete(card_one)
else
user_cards += card_one[3]
deck.delete(card_one)
end
when ["Diamonds", "Ace", 1, 11]
cards_user_has << card_one
puts
puts "You have received an #{card_one[1]} of #{card_one[0]}"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += card_one[2]
deck.delete(card_one)
else
user_cards += card_one[3]
deck.delete(card_one)
end
when ["Hearts", "Queen", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Clubs", "Queen", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Spades", "Queen", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Diamonds", "Queen", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Hearts", "King", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Clubs", "King", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Spades", "King", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Diamonds", "King", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Hearts", "Jack", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Clubs", "Jack", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Spades", "Jack", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
when ["Diamonds", "Jack", 10]
cards_user_has << card_one
user_cards += card_one[2]
deck.delete(card_one)
else
cards_user_has << card_one
user_cards += card_one[1].to_i
deck.delete(card_one)
end
# The second card would get added to user cards and deleted from the deck (Array)
card_two = deck.first
case card_two
when ["Hearts", "Ace", 1, 11]
cards_user_has << card_two
puts "You have received an #{card_two[1]} of #{card_two[0]}"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += card_two[2]
deck.delete(card_two)
else
user_cards += card_two[3]
deck.delete(card_two)
end
when ["Clubs", "Ace", 1, 11]
cards_user_has << card_two
puts "You have received an #{card_two[1]} of #{card_two[0]}"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += card_two[2]
deck.delete(card_two)
else
user_cards += card_two[3]
deck.delete(card_two)
end
when ["Spades", "Ace", 1, 11]
cards_user_has << card_two
puts "You have received an #{card_two[1]} of #{card_two[0]}"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += card_two[2]
deck.delete(card_two)
else
user_cards += card_two[3]
deck.delete(card_two)
end
when ["Diamonds", "Ace", 1, 11]
cards_user_has << card_two
puts "You have received an #{card_two[1]} of #{card_two[0]}"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += card_two[2]
deck.delete(card_two)
else
user_cards += card_two[3]
deck.delete(card_two)
end
when ["Hearts", "Queen", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Clubs", "Queen", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Spades", "Queen", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Diamonds", "Queen", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Hearts", "King", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Clubs", "King", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Spades", "King", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Diamonds", "King", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Hearts", "Jack", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Clubs", "Jack", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Spades", "Jack", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
when ["Diamonds", "Jack", 10]
cards_user_has << card_two
user_cards += card_two[2]
deck.delete(card_two)
else
cards_user_has << card_two
user_cards += card_two[1].to_i
deck.delete(card_two)
end
# Random card from top of deck is dealt to user cards and then removed from the deck, lines 577 - 749
begin
puts "Your cards"
puts "- - - - - - - - - - - - - - - - - - - - -"
cards_user_has.each { |card|
puts %( #{card[1]} of #{card[0]})
}
rand_card = deck.first
puts
if user_cards == 21
sleep 2
puts "Blackjack!"
sleep 3
puts
puts "Congratulations! You win!"
puts
puts "You: #{user_cards} Computer: #{cpu_cards}"
abort
elsif user_cards > 21
puts
sleep 2
puts "Bust!"
puts
sleep 1.5
comparing_game_points(user_cards, cpu_cards)
else
nil
end
puts
print "What would you like to do?: "
user_input = gets.chomp
puts
if user_input != "xhelp" && user_input != "commands" && user_input != "help" && user_input != "h" && user_input != "s" && user_input != "cards"
begin
puts "Unknown Command"
print "Please enter in a command: "
user_input = gets.chomp
puts
end while user_input != "xhelp" && user_input != "commands" && user_input != "help" && user_input != "h" && user_input != "s" && user_input != "cards"
end
case user_input
when "xhelp"
xhelp
when "help"
help
when "commands"
commands
when "cards"
cards
when "h"
# _------------------------------------------------------------------_
if rand_card == ["Hearts", "Ace", 1, 11]
cards_user_has << rand_card
puts "#{rand_card[1]} of #{rand_card[0]}!"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += rand_card[2].to_i
deck.delete(rand_card)
else
user_cards += rand_card[3].to_i
deck.delete(rand_card)
end
elsif rand_card == ["Clubs", "Ace", 1, 11]
cards_user_has << rand_card
puts "#{rand_card[1]} of #{rand_card[0]}!"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += rand_card[2].to_i
deck.delete(rand_card)
else
user_cards += rand_card[3].to_i
deck.delete(rand_card)
end
elsif rand_card == ["Spades", "Ace", 1, 11]
cards_user_has << rand_card
puts "#{rand_card[1]} of #{rand_card[0]}!"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += rand_card[2].to_i
deck.delete(rand_card)
else
user_cards += rand_card[3].to_i
deck.delete(rand_card)
end
elsif rand_card == ["Diamonds", "Ace", 1, 11]
cards_user_has << rand_card
puts "#{rand_card[1]} of #{rand_card[0]}!"
puts "Which number would you like to be the Ace?"
print "Please choose 1 or 11: "
user_input = gets.chomp
if user_input != "1" && user_input != "11"
begin
puts
print "Please enter in either 1 or 11: "
user_input = gets.chomp
end while user_input != "1" && user_input != "11"
end
if user_input == "1"
user_cards += rand_card[2].to_i
deck.delete(rand_card)
else
user_cards += rand_card[3].to_i
deck.delete(rand_card)
end
end
# _----------------------------------------------------------------------_
case rand_card
when ["Hearts", "Queen", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Clubs", "Queen", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Spades", "Queen", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Diamonds", "Queen", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Hearts", "King", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Clubs", "King", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Spades", "King", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Diamonds", "King", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Hearts", "Jack", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Clubs", "Jack", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Spades", "Jack", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
when ["Diamonds", "Jack", 10]
cards_user_has << rand_card
user_cards += rand_card[2].to_i
deck.delete(rand_card)
else
cards_user_has << rand_card
user_cards += rand_card[1].to_i
deck.delete(rand_card)
end
end
sleep 1.5
puts
end while user_input == "h" || user_input == "commands" || user_input == "xhelp" || user_input == "help" || user_input == "cards" || user_input == "1" || user_input == "11"
# Line 757, when user_input is not equal to above end while condition then the loop breaks
puts "You have chosen to stay with #{user_cards}."
puts
puts
sleep 4
# Comparison of user_cards and cpu_cards to determine winner, lines 765 - 813
if cpu_cards > 21 && user_cards > 21
puts
puts "No one wins."
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif cpu_cards == user_cards
puts
puts "It is a tie!"
puts "How rare is that!"
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif cpu_cards == 21 && user_cards != 21 # Computer has blackjack and User is not equal to blackjack
puts
puts "Computer wins."
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif cpu_cards < 21 && user_cards > 21 # Computer is less than blackjack and User is bust!
puts
puts "Computer wins."
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif cpu_cards < 21 && user_cards < cpu_cards
puts
puts "Computer wins."
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif user_cards == 21 && cpu_cards != 21
puts
puts "Congratulations! You win!"
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
elsif user_cards < 21 && cpu_cards > 21
puts
puts "Congratulations! You win!"
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
else user_cards < 21 && user_cards < cpu_cards
puts
puts "Congratulations! You win!"
sleep 2
puts "Computer: #{cpu_cards} You: #{user_cards}"
abort
end
# Ideas
# Make money
# Use classes
# Keep adding new features
# In case h put another when/case menu
# Bugs
# Sometimes when I put in h, I automatically stay
# Status: Unsolved, discovered 6/12/14 4:38 PM
# Make a function(method) and put it outside the loop for user cards so
# it won't say you stayed with etc etcs
# Need to improve code where program compares user_cards and cpu_cards
# When user uses `h`, sometimes they stay at the same number
# Status: Fixed - 6/3/14 5:17 PM
# rand_card.first caused the bug
# When user and computer both bust, computer still wins
# Status: Unsolved
# Attempted to fix: 6/11/14 11:41 PM
# Failed
# Attempted to fix: 6/12/14
# Success, line 653, replaced abort with break
# When I chose `s`, I think it hits still but I am not sure
# Status : Unsolved
# Lines 645 - 653? Check it out, abort program not good!!
# When I use `h`, sometimes when I get a face card (King, Jack or Queen), it doesn't get added to user_cards
# Status: Fixed
# user_card_has loop shows cards twice
# Status: Fixed - 6/6/2014 1:57 PM, had card_one in h card case/when menu
# When you get an Ace and you don't put in either a one or eleven first, after
# you finally put in one or eleven in loop the program goes to stay
# Status: Fixed?
# Put user_input == "1" || "11" in while condition pertaining to h loop
# When I get a Jack, Queen, or King (10), one of them seem not to add up user cards
# Maybe I'll check all face cards (10)s
# Status: Fixed? - 6/12/14 11:36 AM, changed the position of
# card one and user card; card_one[2] += user_cards -> user_cards += card_one[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment