]> git.eli173.com Git - pong_br/commitdiff
switching to node.js? whoops
authorElijah Cohen <eli@eli173.com>
Mon, 15 Apr 2019 03:00:53 +0000 (22:00 -0500)
committerElijah Cohen <eli@eli173.com>
Mon, 15 Apr 2019 03:00:53 +0000 (22:00 -0500)
NOTES.org
game.py
player.py

index d9acd67b0378c18a99aa282aa5fbabef641b9b98..d8ed4fa242a269013aa08d25a4d4bb376aae8779 100644 (file)
--- 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 1634a67ce2c387f4a04a0c64b8d8ef1fbbd16db8..b6aa4396da8c8039bb2329b7bb55c18960d4f187 100644 (file)
--- 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()
index e10dfd4bf76377f81046a30252361599307a7e18..b061e88554416c3216488d65df507c306a7a698f 100644 (file)
--- 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