-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
39 lines (31 loc) · 788 Bytes
/
app.rb
File metadata and controls
39 lines (31 loc) · 788 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
require 'sinatra'
require 'sinatra/reloader' if development?
require_relative './lib/game'
require_relative './lib/player'
require_relative './lib/computer'
class RockPaperScissors < Sinatra::Base
configure :development do
register Sinatra::Reloader
end
enable :sessions
get '/' do
erb(:index)
end
post '/player_name' do
session[:game] = Game.new(Player.new(params[:player_name]), Computer.new)
redirect to('/rock-paper-scissors')
end
get '/rock-paper-scissors' do
@game = session[:game]
erb(:rock_paper_scissors)
end
post '/player_move' do
session[:game].player1.choose(params[:player_move])
session[:game].computer.move
redirect to('/result')
end
get '/result' do
@game = session[:game]
erb(:game)
end
end