forked from makersacademy/rps-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
45 lines (35 loc) · 865 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'sinatra/base'
require 'sinatra/reloader'
require_relative 'lib/game'
require_relative 'lib/player'
class RPS < Sinatra::Base
configure :development do
register Sinatra::Reloader
end
enable :sessions
get '/' do
$game = Game.new
erb :index
end
post '/sign_in' do
$player = Player.new(params[:player_name])
redirect '/play'
end
get '/play' do
erb :play
end
post '/choice' do
$player.choice = params[:choice]
$result = $game.turn($player.choice)
$game.opponent_choice
# puts 'Player choice is ' + $player.choice
# puts 'Opponent choice is ' + $game.opponent_choice
# puts 'Result is ' + $result
redirect '/result'
end
get '/result' do
erb :result
end
# # Start the server if this file is executed directly (do not change the line below)
run! if app_file == $0
end