conn, info = socket.accept() conn.setblocking(False) outputs.append(conn) t = threading.Thread(target=clientInput, args=([conn])) t.start() clientesConectados += 1 except BlockingIOError: print("no connections!") if newDataFromClients: star_time = time.time() if data: print("Client:", requireClient["clientData"]["id"], "send data!") if requireClient["clientData"]["id"] == None: newSnake = Snake() idPlayer = manager.addSnakeInGame(newSnake) requireClient["socketClient"].sendall( pickle.dumps({"id": idPlayer})) else: if requireClient["clientData"]["key"] != None: manager.userCommand(requireClient["clientData"]["key"], requireClient["clientData"]["id"]) manager.moveSnakes() if manager.snakeDie(requireClient["clientData"]["id"]): start_io = time.time() requireClient["socketClient"].sendall( pickle.dumps({"snakeStillInGame": False})) doingIO += (time.time() - start_io) else: manager.checksAllSnakeEatFood()
#print(sys.path) from snake.model.Snake import Snake from snake.model.GameBoard import GameBoard from snake.controle.GameManeger import GameManeger try: pygame.init() except: print("falha ao iniciar o pygame") #abre a janela. surfaceGame = pygame.display.set_mode((GameBoard.width, GameBoard.height)) exit = True timer = pygame.time.Clock() #Testes snake1 = Snake(0) maneger = GameManeger() maneger.addSnakeInGame(snake1) while exit: surfaceGame.fill((9, 10, 13)) maneger.initGame(surfaceGame) for e in pygame.event.get(): if e.type == pygame.QUIT: exit = False else: maneger.commandToSnake(e, 0) maneger.moveSnakes(surfaceGame) maneger.checksSnakeEatFood() timer.tick(15) pygame.display.update()