Fix: Let Main client which is drawing can exit the program
This commit is contained in:
parent
f8fb53fca5
commit
5e387a4cd3
14
draw.py
14
draw.py
@ -24,7 +24,10 @@ def drawerReceive(sock,screen):
|
||||
elif data == "restart":
|
||||
print("restart")
|
||||
break
|
||||
elif data == 'exitok':
|
||||
break
|
||||
print("drawerRECEIVE CLOSED")
|
||||
|
||||
def sendDraw(sock,nowUserList,screen,problem):
|
||||
|
||||
# Set white background
|
||||
@ -34,7 +37,8 @@ def sendDraw(sock,nowUserList,screen,problem):
|
||||
pgStringVar = pygame.font.Font(None,30).render("Problem: {}".format(problem),False,(0,0,0))# 文字物件
|
||||
screen.blit(pgStringVar,(30,450))
|
||||
|
||||
pygame.draw.rect(screen,(171, 254, 250),[100,400,50,20],0)
|
||||
pygame.draw.rect(screen,(171, 254, 250),[100,400,100,50],0)
|
||||
pygame.draw.rect(screen,(255, 0, 0),[250,400,100,50],0)
|
||||
|
||||
white= (255, 255, 255)
|
||||
black= (0, 0, 0)
|
||||
@ -65,14 +69,18 @@ def sendDraw(sock,nowUserList,screen,problem):
|
||||
print ('mouse pressed',pygame.mouse.get_pressed())
|
||||
if pygame.mouse.get_pressed()[0]:
|
||||
pos = pygame.mouse.get_pos()
|
||||
# 100,400,50,20
|
||||
if pos[0]>=100 and pos[0]<=150 and pos[1]>=400 and pos[1]<=420:
|
||||
# 100,400,100,50
|
||||
if pos[0]>=100 and pos[0]<=200 and pos[1]>=400 and pos[1]<=450:
|
||||
sock.send("[restart]".encode('utf-8'))
|
||||
#if data == 'restart':
|
||||
time.sleep(1) #drawerReceive
|
||||
#detectFlag = False
|
||||
return False
|
||||
#print("restart")
|
||||
# 250,400,100,50
|
||||
if pos[0]>=250 and pos[0]<=350 and pos[1]>=400 and pos[1]<=450:
|
||||
sock.send('exit'.encode('utf-8'))
|
||||
return True
|
||||
mouseFlag = True
|
||||
# 如果釋放滑鼠
|
||||
elif event.type == pygame.MOUSEBUTTONUP:
|
||||
|
||||
8
main.py
8
main.py
@ -85,7 +85,7 @@ class Server:
|
||||
sock.send("FAIL".encode('utf-8'))
|
||||
|
||||
class Room:
|
||||
startFlag = False
|
||||
startFlag = True
|
||||
sockList = [] # Client's sock list
|
||||
|
||||
def __init__(self,ip,portNum):
|
||||
@ -100,7 +100,7 @@ class Room:
|
||||
print("\t{}:{}".format(self.ip,self.portNum))
|
||||
listensock.listen(5)
|
||||
emptyFlag = True
|
||||
while True:
|
||||
while self.startFlag:
|
||||
sock,sockname = listensock.accept()
|
||||
print("[ {} ]{} has connected.".format(self.portNum,sockname))
|
||||
|
||||
@ -171,7 +171,9 @@ class Room:
|
||||
allPeerName.append(i.getpeername())
|
||||
for sock in self.sockList:
|
||||
sock.send("[list] {}".format(json.dumps(allPeerName)).encode('utf-8'))
|
||||
|
||||
# Close Process
|
||||
if len(self.sockList):
|
||||
self.startFlag = False
|
||||
else:
|
||||
sock.send('n'.encode('utf-8'))
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user