예제 #1
0
    def pause(self):
        pause_text = interface.Label(700, 200, 400, 200, None,
                                     self.color['background'])
        pause_text.add_text("GAME PAUSED", 70, "Fonts/Comic_Kings.ttf",
                            (236, 240, 241))

        replay = interface.Button(350, 500, 300, 100, self.draw_map,
                                  (244, 208, 63), (247, 220, 111))
        replay.add_text("RESTART", 60, "Fonts/arfmoochikncheez.ttf",
                        self.color['background'])

        resume = interface.Button(750, 500, 300, 100, None, (88, 214, 141),
                                  (171, 235, 198))
        resume.add_text("RESUME", 60, "Fonts/arfmoochikncheez.ttf",
                        self.color['background'])

        exit = interface.Button(1150, 500, 300, 100, close, (241, 148, 138),
                                (245, 183, 177))
        exit.add_text("QUIT", 60, "Fonts/arfmoochikncheez.ttf",
                      self.color['background'])

        mandav = interface.Label(width - 270, height + ground - 70, 300, 100,
                                 None, self.color['background'])
        mandav.add_text("MANDAV", 60, "Fonts/arfmoochikncheez.ttf",
                        (113, 125, 126))

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    close()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        close()
                    if event.key == pygame.K_p:
                        return
                    if event.key == pygame.K_ESCAPE:
                        return

                if event.type == pygame.MOUSEBUTTONDOWN:
                    if replay.isActive():
                        replay.action()
                    if resume.isActive():
                        return
                    if exit.isActive():
                        exit.action()

            replay.draw()
            resume.draw()
            exit.draw()
            pause_text.draw()
            mandav.draw()

            pygame.display.update()
            clock.tick(60)
예제 #2
0
    def level_failed(self):
        level_failed_text = interface.Label(700, 100, 400, 200, None,
                                            self.color['background'])
        level_failed_text.add_text("LEVEL FAILED!", 80,
                                   "Fonts/Comic_Kings.ttf", (236, 240, 241))

        score_text = interface.Label(750, 300, 300, 100, None,
                                     self.color['background'])
        score_text.add_text("SCORE: " + str(self.score), 55,
                            "Fonts/Comic_Kings.ttf", (236, 240, 241))

        replay = interface.Button(500, 500, 300, 100, self.draw_map,
                                  (244, 208, 63), (247, 220, 111))
        replay.add_text("TRY AGAIN", 60, "Fonts/arfmoochikncheez.ttf",
                        self.color['background'])

        exit = interface.Button(1000, 500, 300, 100, close, (241, 148, 138),
                                (245, 183, 177))
        exit.add_text("QUIT", 60, "Fonts/arfmoochikncheez.ttf",
                      self.color['background'])

        mandav = interface.Label(width - 270, height + ground - 70, 300, 100,
                                 None, self.color['background'])
        mandav.add_text("MANDAV", 60, "Fonts/arfmoochikncheez.ttf",
                        (113, 125, 126))

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    close()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        close()

                if event.type == pygame.MOUSEBUTTONDOWN:
                    if replay.isActive():
                        replay.action()
                    if exit.isActive():
                        exit.action()

            replay.draw()
            exit.draw()
            level_failed_text.draw()
            score_text.draw()
            mandav.draw()

            pygame.display.update()
            clock.tick(60)
예제 #3
0
파일: game.py 프로젝트: Gladias/Poker
    def replace(self, event, button_list):
        """Replaces cards clicked by player."""
        continue_button = interface.Button(pygame.Rect(const.CONTINUE),
                                           "Continue", self.font)

        # Add button to list only once
        if len(button_list) == const.BUTTON_LIST_LEN:
            button_list.append(continue_button)

        if event.type == pygame.MOUSEBUTTONUP:
            if self.main_player.card_1.rect.collidepoint(event.pos):
                self.main_player.card_1.click()

            elif self.main_player.card_2.rect.collidepoint(event.pos):
                self.main_player.card_2.click()

            elif continue_button.rect.collidepoint(event.pos):
                # Continue button has been clicked
                if self.main_player.card_1.is_clicked():
                    self.main_player.replace_card(self.main_player.card_1,
                                                  self.game_deck)

                if self.main_player.card_2.is_clicked():
                    self.main_player.replace_card(self.main_player.card_2,
                                                  self.game_deck)

                # Adjust cards, remove continue button, update card_list
                button_list.pop()
                self.main_player.set_cards_position()
                return True
        return False
예제 #4
0
def GAME():
    map = maps.Maps()

    welcome = interface.Label(700, 100, 400, 200, None, background)
    welcome.add_text("ANGRY BIRDS", 80, "Fonts/arfmoochikncheez.ttf",
                     (236, 240, 241))

    start = interface.Button(500, 400, 300, 100, start_game, (244, 208, 63),
                             (247, 220, 111))
    start.add_text("START GAME", 60, "Fonts/arfmoochikncheez.ttf", background)

    exit = interface.Button(1000, 400, 300, 100, close, (241, 148, 138),
                            (245, 183, 177))
    exit.add_text("QUIT", 60, "Fonts/arfmoochikncheez.ttf", background)

    mandav = interface.Button(width - 300, height - 80, 300, 100, None,
                              background)
    mandav.add_text("MANDAV", 60, "Fonts/arfmoochikncheez.ttf", (41, 41, 41))

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                close()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_q:
                    close()

            if event.type == pygame.MOUSEBUTTONDOWN:
                if exit.isActive():
                    exit.action()
                if start.isActive():
                    start_game(map)

        display.fill(background)

        start.draw()
        exit.draw()
        welcome.draw()
        mandav.draw()

        pygame.display.update()
        clock.tick(60)
예제 #5
0
    def level_cleared(self):
        self.level += 1

        level_cleared_text = interface.Label(700, 100, 400, 200, None,
                                             self.color['background'])
        if self.level <= self.max_level:
            level_cleared_text.add_text(
                "LEVEL " + str(self.level - 1) + " CLEARED!", 80,
                "Fonts/Comic_Kings.ttf", (236, 240, 241))
        else:
            level_cleared_text.add_text("ALL LEVEL CLEARED!", 80,
                                        "Fonts/Comic_Kings.ttf",
                                        (236, 240, 241))

        score_text = interface.Label(750, 300, 300, 100, None,
                                     self.color['background'])
        score_text.add_text("SCORE: " + str(self.score), 55,
                            "Fonts/Comic_Kings.ttf", (236, 240, 241))

        replay = interface.Button(350, 500, 300, 100, self.replay_level,
                                  (244, 208, 63), (247, 220, 111))
        replay.add_text("PLAY AGAIN", 60, "Fonts/arfmoochikncheez.ttf",
                        self.color['background'])

        if self.level <= self.max_level:
            next = interface.Button(750, 500, 300, 100, self.draw_map,
                                    (88, 214, 141), (171, 235, 198))
            next.add_text("CONTINUE", 60, "Fonts/arfmoochikncheez.ttf",
                          self.color['background'])
        else:
            next = interface.Button(750, 500, 300, 100, self.start_again,
                                    (88, 214, 141), (171, 235, 198))
            next.add_text("START AGAIN", 60, "Fonts/arfmoochikncheez.ttf",
                          self.color['background'])

        exit = interface.Button(1150, 500, 300, 100, close, (241, 148, 138),
                                (245, 183, 177))
        exit.add_text("QUIT", 60, "Fonts/arfmoochikncheez.ttf",
                      self.color['background'])

        mandav = interface.Label(width - 270, height + ground - 70, 300, 100,
                                 None, self.color['background'])
        mandav.add_text("MANDAV", 60, "Fonts/arfmoochikncheez.ttf",
                        (113, 125, 126))

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    close()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        close()

                if event.type == pygame.MOUSEBUTTONDOWN:
                    if replay.isActive():
                        replay.action()
                    if next.isActive():
                        next.action()
                    if exit.isActive():
                        exit.action()

            replay.draw()
            next.draw()
            exit.draw()
            level_cleared_text.draw()
            score_text.draw()
            mandav.draw()

            pygame.display.update()
            clock.tick(60)
예제 #6
0
파일: game.py 프로젝트: Gladias/Battleship
    def run(self):
        icon = pygame.image.load(str(const.ASSETS / "icon.png"))
        pygame.display.set_icon(icon)
        pygame.display.set_caption("Battleship")

        self.screen.fill(const.BACKGROUND_COLOR)

        stage = next(self.stages)  # First stage - ship placement
        text_list = interface.Text.text_init(None, self.font)
        ships = interface.Button.ships_init(None)
        active_ship_orientation = "Horizontal"   # Can be Horizontal or Vertical

        buttons = [interface.Button(pygame.Rect(const.CONFIRM_BUTTON), "Potwierdź", self.font, const.CELL_COLOR)]

        self.player.player_turn = True
        is_player_winner = None

        self.info = "Rozmieść swoje okręty na planszy 1"

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()

                if stage == "ship placement":
                    if event.type == pygame.KEYDOWN and event.key == pygame.K_r:
                        if active_ship_orientation == "Horizontal":
                            active_ship_orientation = "Vertical"
                        else:
                            active_ship_orientation = "Horizontal"

                    if event.type == pygame.MOUSEBUTTONDOWN:
                        mouse_pos = event.pos

                        if self.active_ship == 0:
                            for ship in ships:
                                if ship.collidepoint(mouse_pos):
                                    self.active_ship = int(ship.width / const.CELL_SIZE)
                                    ships.remove(ship)
                        else:
                            for row in self.first_board.board:
                                for cell in row:
                                    if cell.rect.collidepoint(mouse_pos):
                                        """Checking if ship can be placed"""
                                        if self.first_board.is_place_ok(cell.coordinates, self.active_ship, active_ship_orientation):
                                            cell_list = []

                                            for i in range(self.active_ship):
                                                if active_ship_orientation == "Horizontal":
                                                    cell_list.append(self.first_board.board[cell.coordinates[0]][i + cell.coordinates[1]])
                                                else:
                                                    cell_list.append(self.first_board.board[i + cell.coordinates[0]][cell.coordinates[1]])
                                                cell_list[i].put_ship()

                                            new_ship = Ship(cell_list, active_ship_orientation)
                                            self.player.place_ship(new_ship)
                                            self.active_ship = 0
                                            active_ship_orientation = "Horizontal"
                                            self.info = "Rozmieść swoje okręty na planszy 1"
                                        else:
                                            self.info = "Okręt nie może zostać umieszczony w tym miejscu"

                    if event.type == pygame.MOUSEBUTTONDOWN:
                        mouse_pos = event.pos

                        if buttons[0].rect.collidepoint(mouse_pos):
                            if self.player.get_placed_ships_number() < 5:
                                self.info = "Nie rozmieszczono wszystkich okrętów na planszy"
                            else:
                                self.bot.place_random_ships(self.second_board)
                                buttons = []
                                self.second_board.visible = True
                                text_list.pop()
                                text_list.append(interface.Text("Plansza 2", self.font, const.SECOND_BOARD_CAPTION_POSITION))
                                self.info = "Faza druga, oddaj strzał na planszy nr 2"
                                stage = next(self.stages)

                if stage == "shooting":
                    if event.type == pygame.MOUSEBUTTONDOWN and self.player.is_player_turn():

                        mouse_pos = event.pos
                        clicked_cell = self.second_board.look_for_click(mouse_pos)

                        if clicked_cell is not None and clicked_cell.has_been_shot():
                            self.info = "W to pole został już oddany strzał"
                        elif clicked_cell is not None:
                            before_ships = self.bot.count_not_sunk_ships()
                            hit = self.player.shoot(clicked_cell, self.second_board)
                            after_ships = self.bot.count_not_sunk_ships()

                            if after_ships != before_ships:
                                self.info = "Zatopienie statku"
                            elif hit:
                                self.info = "Trafienie"
                            else:
                                self.info = "Spudłowanie"

                            before_ships = self.player.count_not_sunk_ships()
                            self.bot.shoot(self.first_board)
                            after_ships = self.player.count_not_sunk_ships()

                            if after_ships != before_ships:
                                self.bot.last_shot_sunk_enemy_ship()

                            if self.check_for_finish()[0]:
                                if self.check_for_finish()[1]:
                                    is_player_winner = True
                                else:
                                    is_player_winner = False
                                stage = next(self.stages)

                interface.GameObject.update_screen(None, text_list, ships, buttons, self.first_board, self.second_board, self.screen)
                interface.Text.update_info(None, self.info, self.font, self.screen)

                if stage == "end":
                    finish_buttons = interface.GameObject.draw_finish_menu(None, self.screen, self.font, is_player_winner)

                    if event.type == pygame.MOUSEBUTTONDOWN:
                        mouse_pos = event.pos

                        if finish_buttons[0].rect.collidepoint(mouse_pos):
                            main()

                        elif finish_buttons[1].rect.collidepoint(mouse_pos):
                            sys.exit()

                pygame.display.flip()