-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.py
More file actions
44 lines (32 loc) · 877 Bytes
/
Copy pathstorage.py
File metadata and controls
44 lines (32 loc) · 877 Bytes
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
import uuid
rooms = {}
def generate_id():
return str(uuid.uuid4())
def create_player(name):
return {
"player_id": generate_id(),
"name": name,
"role": None,
"score": 0
}
def create_room(player_name):
room_id = generate_id()
player = create_player(player_name)
room = {
"room_id": room_id,
"players": [player],
"state": "waiting",
"roles_assigned": False,
"mantri_guess": None
}
rooms[room_id] = room
return room_id, player["player_id"]
def join_room(room_id, player_name):
if room_id not in rooms:
return None, "Room not found"
room = rooms[room_id]
if len(room["players"]) >= 4:
return None, "Room is full"
player = create_player(player_name)
room["players"].append(player)
return player["player_id"], None