Created
May 5, 2015 00:25
-
-
Save awhit012/5db080d691ed79ea2d37 to your computer and use it in GitHub Desktop.
Rock Paper Scissors in Ruby
This file contains 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
MESSAGES = [ | |
"Choose your weapon", | |
"Computer has chosen ", | |
"TIE!", | |
"Computer Wins", | |
"You Win!" | |
] | |
def run | |
puts MESSAGES[0] | |
human = gets.chomp | |
computer = ["rock", "paper", "scissors"].sample | |
puts MESSAGES[1] + " " + computer | |
if human == computer | |
puts MESSAGES[2] | |
run | |
end | |
case human | |
when "rock" | |
if computer == "paper" | |
puts MESSAGES[3] | |
else puts MESSAGES[4] | |
end | |
when "paper" | |
if computer == "scissors" | |
puts MESSAGES[3] | |
else puts MESSAGES[4] | |
end | |
when "scissors" | |
if computer == "rock" | |
puts MESSAGES[3] | |
else puts MESSAGES[4] | |
end | |
end | |
end | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment