def run(self): try: pygame.init() FPS = 30 fpsClock = pygame.time.Clock() display = pygame.display.set_mode((600, 300), 0, 32) pygame.display.set_caption('Pong') BLACK = (0, 0, 0) WHITE = (255, 255, 255) ball = pygame.image.load('cat-face.png') ball = pygame.transform.scale(ball, (30, 30)) ballx = 285 bally = 135 paddle1 = (10, 115, 15, 70) paddle2 = (575, 115, 15, 70) while self.running: opCode = "" try: q_item = self.q.get(False) s = q_item opCode = s[0:2] except Exception: pass if opCode == "ex": print("Stopping command_interpreter") self.running = False self.q.task_done() display.fill(BLACK) display.blit(ball, (ballx, bally)) pygame.draw.rect(display, WHITE, paddle1, 0) pygame.draw.rect(display, WHITE, paddle2, 0) for event in pygame.event.get(): if event.type == QUIT: shared.exitProgram() pygame.display.update() fpsClock.tick(FPS) except Exception as e: shared.systemMessage(str(e), True) shared.exitProgram()
def run(self): try: while self.running: q_item = self.q.get() s = q_item opCode = s[0:2] if opCode == "ex": print("Stopping command_interpreter") self.running = False self.q.task_done() shared.exitProgram() elif opCode == "te": shared.systemMessage("Hello World!") self.q.task_done() else: if not (opCode == ""): shared.systemMessage("Unknown command \"" + opCode + "\"") self.q.task_done() except Exception as e: shared.systemMessage(str(e), True) shared.exitProgram()
def run(self): try: # Any init items here while self.running: opCode = "" try: q_item = self.q.get(False) s = q_item opCode = s[0:2] except Exception: pass if opCode == "ex": print("Stopping Player") self.running = False self.q.task_done() # MAIN LOOP CODE HERE except Exception as e: shared.systemMessage(str(e), True) shared.exitProgram()
def __init__(self, q): shared.systemMessage("Starting Player") threading.Thread.__init__(self) self.q = q self.eventConfig = {} self.running = True
import shared import console import command_interpreter import pong import ai import player import sys import traceback import time if __name__ == "__main__": try: shared.systemMessage("Started!") # Console output thread thread_console_output = console.ConsoleOutput(shared.q_console_output) thread_console_output.start() # Command interpreter thread thread_command_interpreter = command_interpreter.CommandInterpreter( shared.q_command_interpreter) thread_command_interpreter.start() # Console input thread thread_console_input = console.ConsoleInput() thread_console_input.daemon = True thread_console_input.start() # Pong thread
def __init__(self): shared.systemMessage("Starting console_input") threading.Thread.__init__(self) self.running = True