This repository was archived by the owner on Jun 17, 2020. It is now read-only.
forked from CMU-Assassins/CMU-Assassins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.rb
More file actions
63 lines (55 loc) · 1.42 KB
/
game.rb
File metadata and controls
63 lines (55 loc) · 1.42 KB
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
63
# encoding: utf-8
require 'data_mapper'
require 'slim'
module Assassins
class Game
def winner
alive = Player.all(:is_verified => true, :is_alive => true)
if (alive.count == 1)
alive[0]
else
nil
end
end
end
class App < Sinatra::Base
before do
@game = Game.first
if @game.nil?
@game = Game.new
@game.save
end
end
set(:game_state) do |*vals|
condition {(vals.include? game_state)}
end
set(:freeforall) do |*vals|
condition {(vals.include? freeforall)}
end
helpers do
def game_state
if defined?(@game_state) && !@game_state.nil?
@game_state
else
if !@game.start_time.nil? && Time.now >= @game.start_time
if Player.count(:is_verified => true, :is_alive => true) == 1
@game_state = :postgame
else
@game_state = :ingame
end
else
@game_state = :pregame
end
end
end
def freeforall
$stderr.puts @game
@game.freeforall
end
end
get '/leaderboard', :game_state => [:ingame, :postgame] do
slim :leaderboard, :locals => { :percent => 100 * Assassins::Player.count(:is_verified => true, :is_alive => true, :has_paid => true) / Assassins::Player.count(:is_verified => true, :has_paid => true) }
end
end
end
# vim:set ts=2 sw=2 et: