forked from makersacademy/rps-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
42 lines (33 loc) · 709 Bytes
/
app.rb
File metadata and controls
42 lines (33 loc) · 709 Bytes
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
require 'sinatra/base'
require './lib/player'
require './lib/computer'
require './lib/game'
class Rps < Sinatra::Base
enable :sessions
get '/' do
erb :index
end
post '/name' do
player = Player.new(params[:player_name])
computer = Computer.new
@game = Game.create(player, computer)
redirect '/play'
end
get '/play' do
erb :play
end
before do
@game = Game.instance
end
post '/selection' do
player_option = @game.player.option(params[:option])
computer_option = @game.computer.option
@game.move(player_option, computer_option)
@game.result
redirect '/result'
end
get '/result' do
erb :result
end
run! if app_file == $0
end