Can show scores. While haven't handle the score adder

This commit is contained in:
snsd0805 2020-06-29 21:49:42 +08:00
parent b31f4161a3
commit 62fc5838da
2 changed files with 14 additions and 6 deletions

16
draw.py
View File

@ -5,20 +5,28 @@ def drawUserList(nowUserList,screen):
listSTR = nowUserList[7:] listSTR = nowUserList[7:]
listJSON = json.loads(listSTR) listJSON = json.loads(listSTR)
#[['127.0.0.1', 52362], ['127.0.0.1', 52370]]
# [['127.0.0.1', 52362], ['127.0.0.1', 52370]]
# [{'name': ['127.0.0.1', 55888], 'score': 0}, {'name': ['127.0.0.1', 55900], 'score': 0}]
print(list)
y = 100 y = 100
cross = 20 cross = 20
pygame.draw.rect(screen,(255,255,255),[900,100,200,380]) pygame.draw.rect(screen,(255,255,255),[900,100,200,380])
for sockName in listJSON: for sockName in listJSON:
pygame.draw.rect(screen,(171, 254, 250),[900,y,200,30],0) # 輸入匡的矩形 pygame.draw.rect(screen,(171, 254, 250),[850,y,200,30],0) # 輸入匡的矩形
pgStringVar = pygame.font.Font(None,25).render(str(sockName),False,(0,0,0))# 文字物件 pgStringVar = pygame.font.Font(None,25).render(str(sockName['name']),False,(0,0,0))# 文字物件
screen.blit(pgStringVar,(910,y+10))# draw font screen.blit(pgStringVar,(870,y+10))# draw font
pgStringVar = pygame.font.Font(None,25).render(str(sockName['score']),False,(255,0,0))# 文字物件
screen.blit(pgStringVar,(860,y+10))# draw font
pygame.display.update() pygame.display.update()
y = y+30+cross y = y+30+cross
def drawerReceive(sock,screen): def drawerReceive(sock,screen):
while True: while True:
data = sock.recv(1024).decode('utf-8') data = sock.recv(1024).decode('utf-8')
if data[0:6] == "[list]": if data[0:6] == "[list]":
drawUserList(data,screen) drawUserList(data,screen)
elif data == "restart": elif data == "restart":

View File

@ -109,7 +109,7 @@ class Room:
# Send socket list to client to build a user list and put it beside picture. # Send socket list to client to build a user list and put it beside picture.
for i in self.sockList: for i in self.sockList:
allPeerName.append(i.getpeername()) allPeerName.append({'name':i.getpeername(),'score':0})
for sock in self.sockList: for sock in self.sockList:
sock.send("[list] {}".format(json.dumps(allPeerName)).encode('utf-8')) sock.send("[list] {}".format(json.dumps(allPeerName)).encode('utf-8'))
receiveDataThread = threading.Thread(target=self.receiveData,args=(sock,),daemon=True) receiveDataThread = threading.Thread(target=self.receiveData,args=(sock,),daemon=True)
@ -168,7 +168,7 @@ class Room:
allPeerName = [] allPeerName = []
# Send socket list to client to build a user list and put it beside picture. # Send socket list to client to build a user list and put it beside picture.
for i in self.sockList: for i in self.sockList:
allPeerName.append(i.getpeername()) allPeerName.append({'name':i.getpeername(),'score':0})
for sock in self.sockList: for sock in self.sockList:
sock.send("[list] {}".format(json.dumps(allPeerName)).encode('utf-8')) sock.send("[list] {}".format(json.dumps(allPeerName)).encode('utf-8'))
# Close Process # Close Process