Created
September 5, 2016 16:52
-
-
Save dvoryankin/5c34eb5a4d7b05b4ac76ad868d22b0ee to your computer and use it in GitHub Desktop.
rock scissors paper autoplay less code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options = [:paper, :rock, :scissors] | |
player1 = "" | |
player2 = "" | |
loop do | |
p1 = rand(0..2) | |
p2 = rand(0..2) | |
puts "Player 1: #{options[p1]}, Player 2: #{options[p2]}" | |
sleep 1 | |
if p1 == p2 | |
puts 'Draw! Start again. One, two, three..' | |
elsif ((p1 - p2) == options.size - 1) | |
puts 'Player 1 - win' | |
elsif ((p2 - p1) == options.size - 1) | |
puts 'Player 2 - win' | |
elsif p1 < p2 | |
puts 'Player 1 - win' | |
else | |
puts 'Player 2 - win' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment