-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday.rb
More file actions
54 lines (36 loc) · 1.12 KB
/
day.rb
File metadata and controls
54 lines (36 loc) · 1.12 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
require 'eventmachine'
require_relative 'player.rb'
class Day < Phase
def start
send_all("@YThe day begins.@d")
@players.each do |player|
player.brief_day(@players) unless player.dead
end
EM.add_timer(@game.time) do
send_all("@cThe sun sinks below the horizon.@d")
@end_callbacks.each(&:call)
# tell the game that the night is over
@game.day_over
end
@actions = ACTIONS.dup
core_callbacks
end
def core_callbacks
at_end do
votes = {}
@players.each do |player| # tally up the votes
@player_status[player] ||= { lynch_vote: :none }
votes[@player_status[player][:lynch_vote]] ||= 0
votes[@player_status[player][:lynch_vote]] += 1
end
next if votes == {}
most_votes = votes.max_by { |(player, number)| number }.first
if most_votes == :none
send_all("The town decides to not lynch anybody.")
else
kill(most_votes, :lynch, "The town decides to lynch %s.")
end
end
end
end
require_relative 'day_actions.rb'