This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rooms.py
84 lines (75 loc) · 2.29 KB
/
rooms.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import definecards
from defineerrors import *
import players
import random
CARDS=definecards.CARDS.copy()
ROOMS={}
class room(object):
def __init__(self,rid):
global ROOMS
if rid in ROOMS:
raise RoomAlreadyExistError('This rid has already exists.')
ROOMS[rid]=self
self.cards={}
self.currentColour=None
self.plusCount=0
self.rid=rid
self.cards_not_used=[x for x in CARDS]
self.lastCard=None #self.cards_not_used[random.randint(-1, len(self.cards_not_used)-1)]
self.players={}
self.winners={}
self.currentPlayer=0
self.skipCount=0
self.currentType=None
self.orientation=True #Clockwise
self.playTurn=[]
def allCards(self):
return list(self.cards.keys())
def winner(self,pid):
self.winners[pid]=players.findPlayerById(pid)
print(pid,'is the %s Winner!'%str(len(self.winners)))
if len(self.players)<=1:
print('Game ends!')
self.destroy()
def destroy(self):
s=self.players.copy()
for x in s:
s[x].quit()
del(s)
for x in self.cards:
self.cards[x].destroy()
del(self)
raise GameCompleted
def nextPlayer(self):
# print('NextPlayer')
if self.orientation == True: # Next Player
if self.currentPlayer >= len(self.playTurn)-1:
self.currentPlayer = 0
else:
self.currentPlayer += 1
else:
if self.currentPlayer <= 0:
self.currentPlayer = len(self.playTurn)-1
else:
self.currentPlayer -= 1
def findRoomById(roomid):
if roomid not in ROOMS:
raise RoomDoesnotExistError('Room id: '+roomid+' does not exist.')
else:
return ROOMS[roomid]
def getRoom(room):
if type(room)==str:
r=findRoomById(room)
try:
t=r.rid
except:
raise RoomDoesnotExistError('Invalid room: no rid.')
return r
elif isinstance(room,object):
try:
t=room.rid
except:
raise RoomDoesnotExistError('Invalid room: no rid.')
return room
else:
raise RoomDoesnotExistError('This room does not exist.')