Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rock, Paper, Scissors game
puts "Welcome to Rock, paper or scissors... I actually tried to do a blackjack but i got stuck on arrays... i believe ill get to that with a bit more of knowledge.\n\n"
puts "Alright... give me 'rock', 'paper' or 'scissors'."
puts "You can also choose to 'quit' the game.\n\n"
answer = gets.chomp
case answer.downcase
when "quit"
puts "Alright... game will quit. Bye.\n\n"
return
when "rock", "paper", "scissors"
cpuPlay = rand(1..3)
case cpuPlay
when 1
cpuPick = "rock"
when 2
cpuPick = "paper"
when 3
cpuPick = "scissors"
end
else
puts "Wrong answer dude.. aborting game.\n\n"
return
end
puts "You picked #{answer} and CPU picked #{cpuPick}"
if cpuPick === answer
puts "What a hell?! you both ansered #{cpuPick}. That's a tie! Game ended.\n\n"
return
end
outputWin = "Wow! GG! You won. #{answer} beats #{cpuPick}.\n\n"
outputLost = "Ups... You lost. #{cpuPick} beats #{answer}.\n\n"
case answer
when "rock"
if cpuPick === "paper"
puts outputLost
else
puts outputWin
end
when "paper"
if cpuPick === "scissors"
puts outputLost
else
puts outputWin
end
when "scissors"
if cpuPick === "rock"
puts outputLost
else
puts outputWin
end
end
puts "Game terminated.\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.