Skip to content

Instantly share code, notes, and snippets.

@sjoulbak
Forked from nielsdoorn/rockPaperScissors.rb
Last active August 29, 2015 14:11
Show Gist options
  • Save sjoulbak/09f55464631e23f45aa6 to your computer and use it in GitHub Desktop.
Save sjoulbak/09f55464631e23f45aa6 to your computer and use it in GitHub Desktop.
def do_i_win my_choice, your_choice
if my_choice == 'rock' and your_choice == 'scissors'
return true
elsif my_choice == 'paper' and your_choice == 'rock'
return true
elsif my_choice == 'scissors' and your_choice == 'paper'
return true
end
return false
end
system"cls"
system"clear"
choices = ['rock','paper','scissors']
my_choice = choices.sample
while true
puts "type 1 for rock, 2 for paper or 3 for scissors"
your_choice = gets.chomp.to_i
if your_choice == 1 || your_choice == 2 || your_choice == 3
your_choice = choices[your_choice.to_i-1]
break
else
system"cls"
system"clear"
end
end
puts "I had #{my_choice} and you had #{your_choice}"
if do_i_win my_choice, your_choice
puts 'I win'
elsif do_i_win your_choice, my_choice
puts 'You win'
else
puts 'Draw'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment