Ejemplo n.º 1
0
    def __init__(self, root: Panel):
        """Create a new MainMenuScene, creating the gui components to
        display.
        """
        size = root.get_rect().size
        title_rect = Rect(0, 0, 500, 70)
        title_rect.center = (size[0] / 2, size[1] / 2 - 200)

        # A panel for all the options
        options_panel = VerticalPanel(rect=Rect(size[0] / 4, size[1] / 2,
                                                size[0] / 2, size[1] / 4),
                                      expand_height=False,
                                      parent=root)

        # Title label
        Label(text="BATTLE SHIP!",
              rect=title_rect,
              style=Style(background_color=None,
                          border_width=0,
                          font=pygame.font.Font('freesansbold.ttf', 64),
                          primary_color=(255, 255, 255)),
              parent=root)

        # A style for all of the menu options
        button_style = Style(primary_color=(255, 255, 255),
                             background_color=(128, 0, 0),
                             border_width=1,
                             border_color=(0, 0, 0),
                             font=pygame.font.Font('freesansbold.ttf', 32))

        # Player vs Computer button
        Button(rect=Rect(0, 0, 400, 40),
               on_click=self._pvc_clicked,
               text="Player vs Computer",
               style=button_style,
               parent=options_panel)

        # Player vs Player button
        Button(rect=Rect(0, 0, 400, 40),
               on_click=self._pvp_clicked,
               text="Player vs Player",
               style=button_style,
               parent=options_panel)

        # Settings button
        Button(rect=Rect(0, 0, 400, 40),
               on_click=self._settings_clicked,
               text="Settings",
               style=button_style,
               parent=options_panel)

        # Quit button
        Button(rect=Rect(0, 0, 400, 40),
               on_click=self._quit_clicked,
               text="Quit",
               style=button_style,
               parent=options_panel)
Ejemplo n.º 2
0
    def __init__(self, root: Panel):
        """Create a new GameScene, creating the gui components to
        display and starting the game.
        """
        self._pause_menu = PauseMenuPanel(Rect(0, 0, 0, 0),
                                          style=Style(
                                              background_color=None,
                                              border_width=0,
                                              force_parent_redraw=True))

        # A style for all
        button_style = Style(background_color=(0, 255, 255),
                             primary_color=(0, 0, 0),
                             border_color=(0, 0, 0),
                             border_width=1)

        size = root.get_rect().size

        rect1 = Rect(size[0] / 8, size[1] / 8, size[0] * 3 / 8,
                     size[1] * 3 / 4)
        rect2 = Rect(size[0] / 2, size[1] / 8, size[0] * 3 / 8,
                     size[1] * 3 / 4)

        # The background water for the game
        self._background_water = BackgroundWater(rect=Rect(
            0, 0, size[0], size[1]),
                                                 parent=root)

        # A style for for the pause button
        pause_style = Style(
            background_color=None,
            force_parent_redraw=True,
            border_color=(0, 0, 0),
            border_width=2,
            background_image=pygame.image.load("images/pause.jpg"))

        # Pause Button
        Button(on_click=self._pause_clicked,
               rect=Rect(20, 20, 100, 100),
               style=pause_style,
               parent=self._background_water)

        # A style for player 1 grids
        player1_grid_style = Style(background_color=None,
                                   primary_color=(255, 0, 0, 100),
                                   secondary_color=(0, 0, 0, 200),
                                   border_color=(0, 0, 0),
                                   border_width=1,
                                   force_parent_redraw=True)

        # Create player 1 grids
        self._player1_grids = self._create_player_grids(
            rect1, player1_grid_style)

        # A style for player 2 grids
        player2_grid_style = Style(background_color=None,
                                   primary_color=(0, 255, 0, 50),
                                   secondary_color=(0, 0, 0, 200),
                                   border_color=(0, 0, 0),
                                   border_width=1,
                                   force_parent_redraw=True)

        # Create player 2 grids
        self._player2_grids = self._create_player_grids(
            rect2, player2_grid_style)

        # Setup observers
        player1 = GameManager.instance.get_player1()
        player2 = GameManager.instance.get_player2()
        player1.clear_observers()
        player2.clear_observers()
        player1.add_observer(self)
        player2.add_observer(self)

        # Start the game
        current_player = GameManager.instance.get_whos_turn()
        current_player.on_turn_started()
        current_player.notify_observers()