コード例 #1
0
    def handleInput(self, window):

        if glfw.get_key(window, glfw.KEY_J) == glfw.PRESS:
            self.dataToSend = 'a'

        if glfw.get_key(window, glfw.KEY_I) == glfw.PRESS:
            self.dataToSend = 'w'

        if glfw.get_key(window, glfw.KEY_L) == glfw.PRESS:
            self.dataToSend = 'd'

        if glfw.get_key(window, glfw.KEY_K) == glfw.PRESS:
            self.dataToSend = 's'

        if self.dataToSend == self.previousData:
            return

        if not self.pacman.isMoving and not self.alreadySend:
            if self.dataToSend != 'n':
                Network().sendData(self.dataToSend)
                self.previousData = self.dataToSend
                self.alreadySend = True

        elif not self.alreadySend:
            if self.pacman.currectDirection == Direction.LEFT:
                if 0.9 > (self.pacman.position[0] -
                          math.floor(self.pacman.position[0])) > 0.8:
                    print("Sending LEFT " + self.dataToSend)
                    Network().sendData(self.dataToSend)
                    self.previousData = self.dataToSend
                    self.alreadySend = True

            elif self.pacman.currectDirection == Direction.RIGHT:
                if 0.1 < (self.pacman.position[0] -
                          math.floor(self.pacman.position[0])) < 0.2:
                    print("Sending RIGHT " + self.dataToSend)
                    Network().sendData(self.dataToSend)
                    self.previousData = self.dataToSend
                    self.alreadySend = True

            elif self.pacman.currectDirection == Direction.UP:
                if 0.1 < (self.pacman.position[2] -
                          math.floor(self.pacman.position[2])) < 0.2:
                    print("Sending UP " + self.dataToSend)
                    Network().sendData(self.dataToSend)
                    self.previousData = self.dataToSend
                    self.alreadySend = True

            elif self.pacman.currectDirection == Direction.DOWN:
                if 0.9 > (self.pacman.position[2] -
                          math.floor(self.pacman.position[2])) > 0.8:
                    print("Sending DOWN " + self.dataToSend)
                    Network().sendData(self.dataToSend)
                    self.previousData = self.dataToSend
                    self.alreadySend = True

        else:
            self.alreadySend = False
コード例 #2
0
    def get(self):

        n = Network()

        if n.isWAN(self.request.remote_ip):
            self.namespace = "http://smartdomus.redirectme.net:9090"
        else:
            self.namespace = "http://" + Util.MY_IP + ":" + str(9090)
        self.render("index.html", namespace=self.namespace)
コード例 #3
0
ファイル: MainHandler.py プロジェクト: smartdomus/pyTeleinfo
    def get(self):

        n = Network()

        if n.isWAN(self.request.remote_ip):
            self.namespace = "http://smartdomus.redirectme.net:9090"
        else:
            self.namespace = "http://" + Util.MY_IP + ":" + str(9090)
        self.render("index.html", namespace=self.namespace)
コード例 #4
0
        self.port = 9090

        settings = dict(template_path=os.path.join(os.path.dirname(__file__),
                                                   "Templates"),
                        static_path=os.path.join(os.path.dirname(__file__),
                                                 "Templates/Static"),
                        ui_modules={
                            'Live': LiveModule,
                            'Menu': MenuModule,
                        })

        handlers = [
            (r"/", MainHandler),
            (r"/live", LiveHandler),
            (r"/datas", DatasHandler),
            (r"/ws", WsHandler),
        ]

        tornado.web.Application.__init__(self, handlers, **settings)


if __name__ == "__main__":

    logger = LoggerThread()
    logger.start()
    app = Application()

    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(app.port, Network.getPrivateIp())

    tornado.ioloop.IOLoop.instance().start()
コード例 #5
0
    def __init__(self, actorsController: ActorsController):

        self.messageQueue = Network().getMessageQueue()

        self.actorsController = actorsController
コード例 #6
0
class NetworkController:
    def __init__(self, actorsController: ActorsController):

        self.messageQueue = Network().getMessageQueue()

        self.actorsController = actorsController

    # Returns True if connected successfully
    # Returns False if connection is not established / lost
    def checkConnectionToServer(self) -> bool:

        if not Network().isConnected():
            return False

        return True

    # Must be called before other functions
    # Returns whether the initialization successful
    def processInitializationData(self) -> bool:

        if self.messageQueue.empty():
            return False

        InitString = self.messageQueue.get()

        initializations = InitString.split('\\')

        for initialization in initializations:

            if initialization == 'fin init':
                print("finish initializing")
                return True

            tokens = initialization.split(',')

            actor_kind = tokens[0]
            id = tokens[1]
            spawnX = int(tokens[2])
            spawnY = int(tokens[3])
            speed = float(tokens[4])
            direction = tokens[5]

            if direction == 'a':
                rotationValue = Direction.LEFT
            elif direction == 'w':
                rotationValue = Direction.UP
            elif direction == 'd':
                rotationValue = Direction.RIGHT
            elif direction == 's':
                rotationValue = Direction.DOWN

            if actor_kind == 'm':
                self.actorsController.initializePlayer1([spawnX, spawnY],
                                                        rotationValue, speed,
                                                        id)
            elif actor_kind == 'p':
                self.actorsController.initializePlayer2([spawnX, spawnY],
                                                        rotationValue, speed,
                                                        id)
            elif actor_kind == 'g':
                self.actorsController.addGhost([spawnX, spawnY], rotationValue,
                                               speed, id)

    def processGameStateData(self) -> False:

        if self.messageQueue.empty():
            return False

        data = self.messageQueue.get()

        tokens = data.split(',')
        if tokens[0] == 'turn':

            id = tokens[1]
            self.actorsController.notifyActor(tokens[0] + "/" + tokens[2], id)
コード例 #7
0
    def checkConnectionToServer(self) -> bool:

        if not Network().isConnected():
            return False

        return True
コード例 #8
0
ファイル: pyTeleinfo.py プロジェクト: smartdomus/pyTeleinfo
        self.port=9090
        
        settings = dict(
                        template_path=os.path.join(os.path.dirname(__file__), "Templates"),
                        static_path=os.path.join(os.path.dirname(__file__), "Templates/Static"),
                        ui_modules={'Live': LiveModule,'Menu': MenuModule,}
                        ) 
                            
        handlers = [
                    (r"/", MainHandler),
                    (r"/live", LiveHandler),
                    (r"/datas", DatasHandler),
                    (r"/ws", WsHandler),
                    ]
       
       
        tornado.web.Application.__init__(self,handlers,**settings)
        
        
        

if __name__ == "__main__":
    
    logger=LoggerThread()
    logger.start()
    app=Application()

    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(app.port,Network.getPrivateIp())

    tornado.ioloop.IOLoop.instance().start()