forked from makersacademy/rps-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
62 lines (49 loc) · 1.1 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'sinatra/base'
require './lib/game'
require './lib/player'
require './lib/computer'
require 'csv'
class RPS < Sinatra::Base
enable :sessions
before do
@game = Game.instance
end
get '/' do
erb(:index)
end
post '/register' do
@player2 = params[:mode_2]
erb(:register)
end
post '/twoplayer_name' do
@game = Game.create(Player.new(params[:player1_name]), Player.new(params[:player2_name]))
redirect '/play'
end
post '/oneplayer_name' do
@game = Game.create(Player.new(params[:player1_name]), Computer.new)
redirect '/play'
end
get '/play' do
erb(:play)
end
get '/switch_turn' do
@game.players[0].choose_weapon(params[:weapon])
erb(:play2)
end
get '/twoplayer_result' do
@game.players[1].choose_weapon(params[:weapon])
erb(:twoplayer_result)
end
get '/oneplayer_result' do
@game.players[0].choose_weapon(params[:weapon])
@game.players[1].choose_weapon
erb(:oneplayer_result)
end
post '/save_game' do
@game.save_game
redirect '/saved_game'
end
get '/saved_game' do
erb(:saved_game)
end
end