forked from makersacademy/rps-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
45 lines (34 loc) · 709 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 './lib/computer'
require './lib/game'
require './lib/player'
class Rps < Sinatra::Base
enable :sessions
before do
@game = Game.instance
end
get '/' do
erb :index
end
post '/name' do
@game = Game.create(Player.new(params[:player_name]), Computer.new)
redirect '/play'
end
get '/play' do
@player = @game.player
erb :play
end
post '/play' do
@player = @game.player
redirect '/play'
end
post '/choice' do
@game.computer.choice = Computer.new.rand_choice
@game.player.choice = params[:choice].downcase.to_sym
redirect '/result'
end
get '/result' do
erb :result
end
run! if app_file == $0
end