Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Created July 4, 2014 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRadev/96e502042ec75810b824 to your computer and use it in GitHub Desktop.
Save AndrewRadev/96e502042ec75810b824 to your computer and use it in GitHub Desktop.
require 'sinatra'
get '/play/:choice' do
player_choice = params[:choice]
choices = ["rock", "paper", "scissors"]
if player_choice == "random"
player_choice = choices.sample
end
if not choices.include? player_choice
next "Your choice, '#{player_choice}', is invalid"
end
computer_choice = choices.sample
game_rules = {
"rock" => "scissors",
"scissors" => "paper",
"paper" => "rock",
}
if player_choice == computer_choice
"Your choice was #{player_choice}, Computer choice is #{computer_choice}. It's a tie"
elsif player_choice == game_rules[computer_choice]
"Your choice was #{player_choice}, Computer choice is #{computer_choice}. You lose"
else
"Your choice was #{player_choice}, Computer choice is #{computer_choice}. You win"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment