diff --git a/draw.py b/draw.py index acdfb11..6d2ea4c 100644 --- a/draw.py +++ b/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: diff --git a/main.py b/main.py index c566f9d..e8b5881 100644 --- a/main.py +++ b/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)) @@ -150,7 +150,7 @@ class Room: if data[0]=='(': # Form MAIN CLIENT,it is position data for clientSock in self.sockList: # 遍歷socket list if clientSock != sock: # 不是自己的才傳送資料.Needn't send position to MAIN - clientSock.send(origin) + clientSock.send(origin) elif data=='[restart]': # [restart] print('game restart') time.sleep(1) @@ -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'))