-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgames_manager.py
35 lines (30 loc) · 1.22 KB
/
games_manager.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
from game import Game
class GamesManager:
challenges = {} #Member: Member
games = {} #Member: Game
async def challenge(self, challenger, challenged):
if challenger in self.challenges:
return "You must wait for your first challenge to expire!"
if challenger in self.games:
return "You are already in game!"
self.challenges[challenger] = challenged
async def accept(self, challenger, challenged):
if self.challenges.get(challenger, None) != challenged:
return f"{challenger.display_name} has not challenged you!"
if challenged in self.games:
return "You are already in game!"
del self.challenges[challenger]
async def expire(self, challenger):
if challenger in self.challenges:
del self.challenges[challenger]
return True
else:
return False
async def start_game(self, ch, wait_for, player1, player2):
game = Game(ch, wait_for, player1, player2)
self.games[player1] = game
self.games[player2] = game
await game.start()
del self.games[player1]
if player2 in self.games: #could be playing myself
del self.games[player2]