コード例 #1
0
 def __init__(self, player_id: int):
     Window.__init__(self,
                     bg_color=(0, 200, 255),
                     bg_music=RESOURCES.MUSIC["setup"])
     self.gameplay = Gameplay(player_id)
     self.count_down = CountDown(self,
                                 60,
                                 "Time left: {seconds}",
                                 font=(None, 70),
                                 color=WHITE)
     self.start_count_down = lambda: self.count_down.start(
         at_end=self.timeout) if self.client_socket.connected() else None
     params_for_all_buttons = {
         "bg": GREEN,
         "hover_bg": GREEN_LIGHT,
         "active_bg": GREEN_DARK,
         "highlight_color": YELLOW
     }
     self.button_back = ImageButton(self,
                                    RESOURCES.IMG["arrow_blue"],
                                    **params_for_all_buttons,
                                    rotate=180,
                                    size=50,
                                    callback=self.stop)
     self.navy_grid = DrawableListVertical(offset=0, bg_color=(0, 157, 255))
     for i in range(NB_LINES_BOXES):
         box_line = DrawableListHorizontal(offset=0)
         for j in range(NB_COLUMNS_BOXES):
             box_line.add(BoxSetup(self, size=BOX_SIZE, pos=(i, j)))
         self.navy_grid.add(box_line)
     self.ships_list = DrawableListVertical(offset=70, justify="left")
     for ship_name, ship_infos in SHIPS.items():
         ship_line = DrawableListHorizontal(offset=ship_infos["offset"])
         for _ in range(ship_infos["nb"]):
             ship_line.add(ShipSetup(self, ship_name, ship_infos["size"]))
         self.ships_list.add(ship_line)
     option_size = 50
     self.button_restart = Button.withImageOnly(
         self,
         Image(RESOURCES.IMG["reload_blue"], size=option_size),
         callback=self.reinit_all_ships,
         **params_for_all_buttons)
     self.button_random = Button.withImageOnly(self,
                                               Image(
                                                   RESOURCES.IMG["random"],
                                                   size=option_size),
                                               callback=self.shuffle,
                                               **params_for_all_buttons)
     self.button_play = Button(self,
                               "Play",
                               font=(None, 40),
                               callback=self.play,
                               **params_for_all_buttons)
コード例 #2
0
ファイル: navy.py プロジェクト: francis-clairicia/Navy
    def __init__(self):
        Window.__init__(self, size=(1280, 720), flags=pygame.DOUBLEBUF, bg_music=RESOURCES.MUSIC["menu"])
        self.set_icon(RESOURCES.IMG["icon"])
        self.set_title(f"Navy - v{__version__}")
        self.set_fps(60)
        self.disable_key_joy_focus_for_all_window()

        self.bg = Image(RESOURCES.IMG["menu_bg"], self.size)
        self.logo = Image(RESOURCES.IMG["logo"])

        params_for_all_buttons = {
            "font": (None, 100),
            "bg": GREEN,
            "hover_bg": GREEN_LIGHT,
            "active_bg": GREEN_DARK,
            "outline": 3,
            "highlight_color": YELLOW,
        }

        params_for_dialogs = {
            "outline": 5,
            "hide_all_without": [self.bg, self.logo]
        }

        self.start_game = NavySetup(1)
        self.multiplayer_server = PlayerServer(self, **params_for_dialogs)
        self.multiplayer_client = PlayerClient(self, **params_for_dialogs)
        self.dialog_credits = Credits(self, **params_for_dialogs)
        self.dialog_options = Options(self, **params_for_dialogs)

        self.menu_buttons = ButtonListVertical(offset=30)
        self.menu_buttons.add(
            Button(self, "Play against AI", **params_for_all_buttons, callback=self.start_game.mainloop),
            Button(self, "Play as P1", **params_for_all_buttons, callback=self.multiplayer_server.mainloop),
            Button(self, "Play as P2", **params_for_all_buttons, callback=self.multiplayer_client.mainloop),
            Button(self, "Quit", **params_for_all_buttons, callback=self.stop)
        )

        self.button_credits = Button(self, "Credits", callback=self.dialog_credits.mainloop, **params_for_all_buttons)
        self.button_settings = Button.withImageOnly(self, Image(RESOURCES.IMG["settings"], size=self.button_credits.height - 20), callback=self.dialog_options.mainloop, **params_for_all_buttons)