From 0524309598d30e522cb021427491b92a4d767db2 Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Sun, 14 Apr 2019 22:00:53 -0500 Subject: [PATCH] switching to node.js? whoops --- NOTES.org | 3 +++ game.py | 2 +- player.py | 20 ++++---------------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/NOTES.org b/NOTES.org index d9acd67..d8ed4fa 100644 --- a/NOTES.org +++ b/NOTES.org @@ -1,4 +1,7 @@ +NEW PLAN: PUT THE PLAYER CLASS INIT STUFF INSIDE THE MATCHMAKER MANAGE_INCOMING PARTS! LETS ME GET AWAY WITH MORE STUFF SERVER-WISE I THINK + + Basic infrastructure for web work: have a player manager class thread which checks main game state and sends it out every so often (1/15 seconds?) (can also form ground work for computer players diff --git a/game.py b/game.py index 1634a67..b6aa439 100644 --- a/game.py +++ b/game.py @@ -14,7 +14,7 @@ class Game(): def __init__(self, players): self.players = players self.game_state = gamestate.GameState() - for player in self.players: + for player in self.players: # CAUTION HERE, MIGHT NEED TO MODIFY player.run() def run(self): threading.Timer(SPF, self.run).start() diff --git a/player.py b/player.py index e10dfd4..b061e88 100644 --- a/player.py +++ b/player.py @@ -4,28 +4,16 @@ import asyncio import websockets import threading - -class Player(threading.Thread): +# planning: +# I think I can properly initialise the async websocket stuff in the init method, then the other methods will probably be fine? There may be problems with send_data and asyncio stuff, but get_status is definitely fine as-is +class Player(): def __init__(self, socket): - super().__init__() - self.game = None self.socket = socket self.status = 'x' self.status_lock = threading.Lock() - async def run(self): - print('fired') - msg = await self.socket.recv() - print('recv') - # should be 'u' or 'd', if neither - with self.status_lock: - if len(msg) > 0: - self.status = msg[0] - else: - self.status = 'x' - # needs to be re-ran at this point? probably def send_data(self, data): # to be used by the game thread thingy - self.socket.send(data) + asyncio.run(self.socket.send(data)) def get_status(self): with self.status_lock: stat = self.status -- 2.39.2