Skip to content

Instantly share code, notes, and snippets.

@Spesm
Created January 6, 2019 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spesm/b50c39e31bfd9377acbafac95e610188 to your computer and use it in GitHub Desktop.
Save Spesm/b50c39e31bfd9377acbafac95e610188 to your computer and use it in GitHub Desktop.
def rock_paper_scissors
choice = ["Rock", "Paper", "Scissors"]
p_win = 0
c_win = 0
draw = 0
round = 0
puts ""
puts "Welcome to Rock, Paper, Scissors!"
puts "Please enter your name:"
name = gets.chomp
puts "Do you feel like playing me, #{name}? Yes or no please (y/n)."
while wanna_play = gets.chomp
case wanna_play.downcase
when "y", "yes"
loop do
round += 1
puts "Ready for round #{round}?"
puts ""
puts "Okay, make your choice! Press 1 for \'rock\', 2 for \'paper\' or 3 for \'scissors\' please."
(0..2).each do |n|
puts "#{n+1}. #{choice[n]}"
end
while input = gets.to_i
case input
when 1, 2, 3
break
else
puts "Try and hit the right key. 1, 2 or 3"
end
end
p_choice = choice[input-1]
puts "Your choice: #{p_choice}."
c_choice = choice[rand(3)]
puts "My choice: #{c_choice}."
puts ""
if p_choice == c_choice
puts "That\'s a draw."
draw += 1
elsif p_choice == choice[0] && c_choice == choice[2] || p_choice == choice[1] && c_choice == choice[0] || p_choice == choice[2] && c_choice == choice[1]
puts "Well blow me... you win :/"
p_win += 1
else
puts "Yeah!!! I WIN :D"
c_win += 1
end
puts ""
puts "That makes the score:"
puts "#{name}: #{p_win} me: #{c_win} draw: #{draw}"
puts ""
puts "Wanna try again? Yes or no please (y/n)."
while play_again = gets.chomp
case play_again.downcase
when "n", "no"
puts "Too bad, catch you later."
puts ""
break
when "y", "yes"
puts "Alright, let\'s go then!"
puts ""
break
else
puts "Try and answer my question. Yes or no?"
end
end
case play_again.downcase
when "n", "no"
break
end
end
break
when "n", "no"
puts "Why bother me then? Bye now!!!"
puts ""
break
else
puts "That wasn\'t a yes or no. Try again."
end
end
end
rock_paper_scissors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment