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