Skip to content

Instantly share code, notes, and snippets.

@Nerajno
Created January 27, 2019 22:46
Show Gist options
  • Save Nerajno/00fe7bc733acd06dfe2ef7130d78566b to your computer and use it in GitHub Desktop.
Save Nerajno/00fe7bc733acd06dfe2ef7130d78566b to your computer and use it in GitHub Desktop.
Other ppls gist ==> Ruby Cli
##################
# shared methods #
##################
def welcome
# code #welcome here
end
def deal_card
rand(1..11)
end
def display_card_total(card_total)
puts "Your cards add up to #{card_total}"
end
##########
# rounds #
##########
def welcome
puts "Welcome to the Blackjack Table"
end
def prompt_user
puts "Type 'h' to hit or 's' to stay"
end
def initial_round
first_round = deal_card + deal_card
display_card_total(first_round)
return first_round
end
def get_user_input
gets.chomp.strip
end
def end_game(card_total)
puts "Sorry, you hit #{card_total}. Thanks for playing!"
end
def hit?(card_total)
prompt_user
input = get_user_input
until input == 'h' || input == 's'
invalid_command
prompt_user
input = get_user_input
end
if input == 'h'
card_total += deal_card
elsif input == 's'
card_total
end
end
def invalid_command
puts "Please enter a valid command"
end
##########
# runner #
##########
def runner
welcome
card_total = initial_round
until card_total > 21
card_total = hit?(card_total)
display_card_total(card_total)
end
end_game(card_total)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment