Created
October 5, 2012 05:48
-
-
Save mhriess/3838308 to your computer and use it in GitHub Desktop.
Rock-Paper-Scissors bad
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
CHOICES = ["Rock", "Paper", "Scissors"] | |
def new_game | |
print %q"Let's play some Rock-Paper-Scissors! | |
Enter your choice below: | |
>" | |
outcome | |
end | |
def player_choice | |
player_input = gets.chomp.capitalize | |
if !CHOICES.include?(player_input) | |
new_game | |
end | |
end | |
def computer_choice | |
CHOICES[rand(3)] | |
end | |
def outcome | |
player_decision = player_choice | |
computer_decision = computer_choice | |
decision = if player_decision == "Rock" | |
if computer_decision == "Rock" | |
"draw" | |
else | |
computer_decision == "Paper" ? "lose" : "win" | |
end | |
elsif player_decision == "Paper" | |
if computer_decision == "Paper" | |
"draw" | |
else | |
computer_decision == "Rock" ? "win" : "lose" | |
end | |
else # player_decision == "Scissors" | |
if computer_decision == "Scissors" | |
"draw" | |
else | |
computer_decision == "Rock" ? "lose" : "win" | |
end | |
end | |
puts "You chose #{player_decision} and the computer chose #{computer_decision}. You #{decision}!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment