forked from makersacademy/rps-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
42 lines (34 loc) · 954 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
# frozen_string_literal: true
require 'sinatra/base'
require 'sinatra/reloader'
require 'rack'
require './lib/game.rb'
require './lib/computer.rb'
# RPS class is responsible for Controller actions to run the webapp game functionality
class RPS < Sinatra::Base
enable :sessions
get '/' do
erb :index
end
post '/name' do
session[:player_name] = params[:player_name]
redirect '/play'
end
get '/play' do
@player_name = session[:player_name]
erb :play
end
post '/weapon_selection' do
session[:player_weapon] = params[:weapon].downcase.to_sym
redirect '/result'
end
get '/result' do
@player_weapon = session[:player_weapon]
@player_name = session[:player_name]
game = Game.new(@player_name)
@computer_weapon = Computer.new.select_random
game.winner_weapon(@player_weapon, @computer_weapon)
@winner = game.winning_player(@player_weapon, @computer_weapon)
erb :result
end
end