forked from makersacademy/rps-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
39 lines (32 loc) · 888 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
require 'sinatra/base'
require './lib/player'
require './lib/game'
require './lib/automated_opponent'
class RockPaperScissorsLizardSpock < Sinatra::Base
enable :sessions
get '/' do
erb(:index)
end
post '/name' do
@player = Player.create(params[:player_name])
redirect to('/play')
end
get '/play' do
@player = Player.instance
erb(:play)
end
post '/decider' do
@player_choice = Player.instance.player_choice(params[:choice])
@computer_choice = AutomatedOpponent.create
@game_result = Game.create(params[:choice], AutomatedOpponent.instance.automated_choice)
redirect to('/results')
end
get '/results' do
@player = Player.instance
@computer_choice = AutomatedOpponent.instance.automated_choice
@game_result = Game.instance.result
@emoji = Game.instance.emoji
erb(:results)
end
run! if app_file == $0
end