-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroom.py
More file actions
27 lines (24 loc) · 718 Bytes
/
Copy pathroom.py
File metadata and controls
27 lines (24 loc) · 718 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
import json
class Room:
def __init__(self, name, admin):
self.name = name
self.players = []
self.admin = admin
self.save()
def connect(self, name):
for player in self.players:
if (player == name):
return False
self.players.append(name)
self.save()
return True
def save(self):
room = {}
room["players"] = []
room["name"] = self.name
room["status"] = 'waiting'
for player in self.players:
room["players"].append(player)
room["admin"] = self.admin
with open('rooms/{}.json'.format(self.name), 'w') as outfile:
json.dump(room, outfile)