forked from scoliono/secreth_discordbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
49 lines (42 loc) · 1.52 KB
/
Game.py
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
from random import shuffle
class Game(object):
"""Represents a game of Secret Hitler."""
def __init__(self, cid, initiator):
self.playerlist = {}
self.player_sequence = []
self.channel = cid
self.board = None
self.initiator = initiator
self.timeout = None
def add_player(self, uid, player):
self.playerlist[uid] = player
def get_hitler(self):
for uid in self.playerlist:
if self.playerlist[uid].role == "Hitler":
return self.playerlist[uid]
def get_fascists(self):
fascists = []
for uid in self.playerlist:
if self.playerlist[uid].role == "Fascist":
fascists.append(self.playerlist[uid])
return fascists
def shuffle_player_sequence(self):
for uid in self.playerlist:
self.player_sequence.append(self.playerlist[uid])
shuffle(self.player_sequence)
def remove_from_player_sequence(self, Player):
for p in self.player_sequence:
if p.user.id == Player.user.id:
p.remove(Player)
def print_roles(self):
rtext = ""
if self.board is None:
#game was not started yet
return rtext
else:
for p in self.playerlist:
rtext += self.playerlist[p].name + "'s "
if self.playerlist[p].is_dead:
rtext += "(dead) "
rtext += "secret role was " + self.playerlist[p].role + "\n"
return rtext