from requests import request
from threading import Thread
import socket
import pygame
from random import randint
class Multiple(Thread):
def __init__(self,conver,screen,list1=[]):
super().__init__()
self.conver=conver
self.screen=screen
self.list1=list1
def run(self):
while True:
message=self.conver.recv(1024).decode(encoding='utf-8')
self.list1.append({'message': '%s'%(message), 'speed': 20, 'position': (600, randint(0, 380))})
if __name__ == '__main__':
server=socket.socket()
server.bind(('192.168.0.108',8089))
server.listen(512)
pygame.init()
screen = pygame.display.set_mode((600, 400))
screen.fill((255, 255, 255))
font = pygame.font.SysFont('Times', 20)
surface = font.render('super', True, (0, 0, 0))
screen.blit(surface, (100, 100))
pygame.display.flip()
while True:
conver, addr = server.accept()
t=Multiple(conver,screen)
t.start()
list1=[]
pygame.time.delay(1000)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
list1=list.copy(t.list1)
screen.fill((255,255, 255))
font = pygame.font.SysFont('Times', 30)
for dict3 in list1:
surface = font.render(dict3['message'], True, (255, 0, 0))
x, y = dict3['position']
if x>-200:
screen.blit(surface, (x, y))
x -= dict3['speed']
dict3['position'] = (x, y)
else:
list1.remove(dict3)
continue
pygame.time.delay(20)
pygame.display.update()
Day18-作业
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...