예제 #1
0
 def __init__(self):
     UIScene.__init__(self, "play")
     self.map_p = UIElement(UIConfig.MAP_X, UIConfig.MAP_Y, UIConfig.MAP_W,
                            UIConfig.MAP_H)
     self.stat_p = UIElement(UIConfig.STAT_X, UIConfig.STAT_Y,
                             UIConfig.STAT_W, UIConfig.STAT_H, "Stats")
     self.msg_p = UIElement(UIConfig.MSG_X, UIConfig.MSG_Y, UIConfig.MSG_W,
                            UIConfig.MSG_H, "Messages")
     self.skl_p = UIElement(UIConfig.SKL_X, UIConfig.SKL_Y, UIConfig.SKL_W,
                            UIConfig.SKL_H, "Skills")
     self.info_p = UIElement(UIConfig.INFO_X, UIConfig.INFO_Y,
                             UIConfig.INFO_W, UIConfig.INFO_H, "Info")
예제 #2
0
    def __init__(self, rect: Rect, color: Optional[Color]):
        super().__init__(rect, color)
        self.main = None
        self.nicks = []
        fps_font = Font('assets/fonts/arial.ttf', 20)

        sub_elem = UIElement(Rect(50, 50, 50, 50), None)
        sub_elem.append_child(FPSCounter(Rect(50, 50, 0, 0), fps_font))
        self.append_child(sub_elem)

        self.sock = socket.socket()
        self.sock.bind((config['server']['ip'], config['server']['port']))
        self.sock.listen(1)

        manager = Manager()
        self.connection_list = manager.dict()
        self.new_connections = manager.list()
        self.receive_list = manager.list()

        self.connection_process = Process(
            target=connection_function,
            args=(self.sock, self.connection_list, self.new_connections,
                  self.receive_list))
        self.connection_process.start()

        self.parent_conn, self.child_conn = Pipe()
        self.send_process = Process(target=send_function,
                                    args=(self.connection_list,
                                          self.child_conn))
        self.send_process.daemon = True
        self.send_process.start()
예제 #3
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.dialogs = []
        with open('assets/dialogs.json') as json_file:
            for dialog_json in json.load(json_file):
                self.dialogs.append(DialogModel(**dialog_json))

        self.current_dialog: Optional[DialogModel] = None
        self.message_delay = 45

        self.message_queue = []
        self.timer = self.message_delay
        self.responses = UIElement(Rect(0, 0, 0, 0),
                                   None,
                                   absolute_anchor=Anchor.BOTTOM_RIGHT,
                                   relative_anchor=Anchor.BOTTOM_RIGHT)
        self.append_child(self.responses)

        self.messages_count = 0
        self.messages_container = MessagesScroll(
            Rect(0, 10, self.relative_bounds.w * 0.99,
                 self.relative_bounds.h * 0.9),
            Color('beige'),
            absolute_anchor=Anchor.TOP_CENTER,
            relative_anchor=Anchor.TOP_CENTER,
            max_offset=0)
        self.append_child(self.messages_container)

        self.on_dialog_started('initial')
예제 #4
0
    def __init__(self, rect: Rect, color: Optional[Color]):
        super().__init__(rect, color)
        self.main = None
        fps_font = Font('assets/fonts/arial.ttf', 20)

        sub_elem = UIElement(Rect(50, 50, 50, 50), None)
        sub_elem.append_child(FPSCounter(Rect(50, 50, 0, 0), fps_font))
        self.append_child(sub_elem)

        self.sock = socket.socket()
        self.sock.connect(('localhost', 9090))
        print('Connected')

        manager = Manager()
        self.receive_list = manager.list()
        self.socket_process = Process(target=listen,
                                      args=(self.sock, self.receive_list))
        self.socket_process.start()

        self.parent_conn, self.child_conn = Pipe()
        self.send_process = Process(target=send_function,
                                    args=(self.sock, self.child_conn))
        self.send_process.daemon = True
        self.send_process.start()

        self.parent_conn.send(
            (['nick', "".join(random.sample(list(ascii_letters), 5))], None))
예제 #5
0
    def __init__(self, rect: Rect, color: Optional[Color], sock, receive_list,
                 socket_process, parent_conn, child_conn, send_process, nicks,
                 team_id):
        super().__init__(rect, color)

        self.sock = sock
        self.receive_list = receive_list
        self.socket_process = socket_process
        self.parent_conn = parent_conn
        self.child_conn = child_conn
        self.send_process = send_process

        mod_loader.import_mods()

        config.reload()

        fps_font = Font('assets/fonts/arial.ttf', 20)

        sub_elem = UIElement(Rect(50, 50, 50, 50), None)
        sub_elem.append_child(FPSCounter(Rect(50, 50, 0, 0), fps_font))
        self.append_child(sub_elem)

        self.game = Game(Game.Side.CLIENT, mod_loader, self.parent_conn, nicks,
                         team_id)

        self.minimap = Minimap(self.game)
        self.minimap_elem = UIImage(
            Rect(0, config['screen']['size'][1] - 388, 0, 0),
            'assets/sprite/minimap.png')
        self.minimap_elem.append_child(self.minimap)

        self.minimap_elem.append_child(
            ResourceMenu(self.game.current_player, Rect(45, 108, 0, 0),
                         Font('assets/fonts/arial.ttf', 25)))

        menu_parent = UIElement(Rect(0, 0, 0, 0), None)
        self.append_child(menu_parent)
        menu_parent.append_child(self.minimap_elem)
        menu_parent.append_child(BuildMenu(self.relative_bounds, self.game))
        menu_parent.append_child(ProduceMenu(self.relative_bounds, self.game))
예제 #6
0
    def __init__(self, rect: Rect, color: Optional[Color], sock,
                 connection_list, receive_list, parent_conn, child_conn,
                 send_process, nicks):
        mod_loader.import_mods()

        super().__init__(rect, color)

        fps_font = Font('assets/fonts/arial.ttf', 20)

        sub_elem = UIElement(Rect(50, 50, 50, 50), None)
        sub_elem.append_child(FPSCounter(Rect(50, 50, 0, 0), fps_font))
        self.append_child(sub_elem)

        self.sock = sock
        self.connection_list = connection_list
        self.receive_list = receive_list
        self.child_conn = child_conn
        self.parent_conn = parent_conn
        self.send_process = send_process

        self.game = Game(Game.Side.SERVER,
                         mod_loader,
                         self.parent_conn,
                         nicks,
                         -1,
                         connection_list=self.connection_list)

        self.minimap_elem = UIImage(
            Rect(0, config['screen']['size'][1] - 388, 0, 0),
            'assets/sprite/minimap.png')

        self.minimap = Minimap(self.game)
        self.minimap_elem.append_child(self.minimap)

        self.append_child(self.minimap_elem)
        self.game.create_unit('warrior', (0, 0))
        self.game.create_unit('fortress', (500, 0))
        self.game.create_unit('fortress', (-500, 0))
        self.game.create_unit('archer', (-25, -25))
        self.game.create_unit('archer', (25, -25))
        self.game.create_unit('archer', (-25, 25))
        self.game.create_unit('archer', (25, 25))