Created
June 1, 2015 20:02
-
-
Save bsterno/9ad6a96a6ba7ae4d1ca7 to your computer and use it in GitHub Desktop.
MMORPS
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Brian's To-Do List</title> | |
</head> | |
<body> | |
<h3>Human: <%= human_score %></h3> | |
<h3>Computer: <%= computer_score %></h3> | |
<br> | |
<form action='/rps' method='post'> | |
<input type='submit' id='Rock' value='Rock' name='Rock'> | |
<input type='submit' id='Paper' value='Paper' name='Paper'> | |
<input type='submit' id='Scissors' value='Scissors' name='Scissors'> | |
</form> | |
</body> | |
</html> |
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
require "sinatra" | |
require "pry" | |
use Rack::Session::Cookie, { | |
secret: "keep_it_secret_keep_it_safe" | |
} | |
def rps_game | |
computer = [ 0, 1, 2 ] | |
computer_choice = computer[rand(3)] | |
computer_choice | |
end | |
get "/" do | |
session[:human_score] ||= 0 | |
session[:computer_score] ||= 0 | |
redirect "/rps" | |
end | |
get "/rps" do | |
erb :index, locals: { human_score: session[:human_score], computer_score: session[:computer_score] } | |
end | |
post "/rps" do | |
# human_choice = params[:human_choice] | |
# computer_choice = rand(3) | |
if params["Rock"] == "Rock" | |
session[:human_score] += 1 | |
elsif params["Paper"] == "Paper" | |
session[:human_score] += 1 | |
elsif params["Scissors"] == "Scissors" | |
session[:human_score] += 1 | |
end | |
binding.pry | |
# if human_choice < computer_choice | |
# session[:computer_score] += 1 | |
# elsif human_choice > computer_choice | |
# session[:human_score] += 1 | |
# end | |
redirect "/rps" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment