Ejemplo n.º 1
0
class VisualizerThread(threading.Thread):

    def __init__(self, _mapJsonFileName, _debug=False, _scoreboard=False):
        super(VisualizerThread, self).__init__()
        self.running = False
        self.mapJsonFileName = _mapJsonFileName
        self.debug = _debug
        self.scoreboard = _scoreboard
        self.append_turn = []

        if _scoreboard:
            self.scoreboard = Scoreboard(parameters.scoreboard_url)

    def run(self):
        try:
            with open(self.mapJsonFileName) as json_file:
                mapJsonObject = loadJson(json_file)
            if(mapJsonObject is None):
                raise Exception
        except IOError:
            print("File " + self.mapJsonFileName + " does not exist")
            raise
            exit(1)
        except Exception:
            print("Failed to parse map json data")
            raise
            exit(1)

        self.visualizer = Visualizer(mapJsonObject, self.debug)

        while 1:
            while len(self.append_turn) != 0:
                self.visualizer.add_turn(self.append_turn.pop(0))
            turn = self.visualizer.run()
            if turn is not None:
                if self.scoreboard:
                    self.scoreboard.change_turn(turn)

    def add_turn(self, json):
        self.append_turn.append(json)

    def kill(self):
        pass

    def stop(self):
        pass

    def __del__(self):
        self.kill()
Ejemplo n.º 2
0
    def run(self):
        try:
            with open(self.mapJsonFileName) as json_file:
                mapJsonObject = loadJson(json_file)
            if(mapJsonObject is None):
                raise Exception
        except IOError:
            print("File " + self.mapJsonFileName + " does not exist")
            raise
            exit(1)
        except Exception:
            print("Failed to parse map json data")
            raise
            exit(1)

        self.visualizer = Visualizer(mapJsonObject, self.debug)

        while 1:
            while len(self.append_turn) != 0:
                self.visualizer.add_turn(self.append_turn.pop(0))
            turn = self.visualizer.run()
            if turn is not None:
                if self.scoreboard:
                    self.scoreboard.change_turn(turn)