def __init__(self, celd, x, y, width, height):
     self.content = celd
     self.x = x
     self.y = y
     self.width = width
     self.height = height
     button_clicked = picture.get_picture(celd.content)
     self.clicked = pygame.transform.scale(button_clicked, (height, width))
     button_unclicked = picture.get_picture("empty")
     self.unclicked = pygame.transform.scale(button_unclicked,
                                             (height, width))
def main():
    pygame.init()
    pygame.display.set_caption("Minesweeper")
    pygame.display.set_icon(picture.get_picture("icon"))

    intro()
    game()
def game():
    global MAP_TYPE
    board = Board(MAP_TYPE)
    screen = board.display_board_hide()

    width_pressed, height_pressed = 0, 0
    posX_pressed, posY_pressed = 0, 0
    running, r_pressed, escape_pressed = True, False, False
    while running:
        try:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
                    pygame.quit()
                    quit()

                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_r:
                        r_pressed = True
                        running = False

                    elif event.key == pygame.K_ESCAPE:
                        escape_pressed = True
                        running = False
                        main()

                if not board.visible:
                    if event.type == pygame.MOUSEBUTTONUP:
                        button_pressed = board.matrix[posY_pressed][
                            posX_pressed]
                        board.action(button_pressed, event, screen)

                    elif event.type == pygame.MOUSEBUTTONDOWN:
                        width_pressed = event.pos[0]
                        height_pressed = event.pos[1]

                        posX_pressed = int(width_pressed / 40)
                        posY_pressed = int(height_pressed / 40)

                        button_pressed = board.matrix[posY_pressed][
                            posX_pressed]

                        if button_pressed.content.status_celd() == "Invisible":
                            pic = picture.get_picture(0)
                            pic = pygame.transform.scale(
                                pic,
                                (button_pressed.width, button_pressed.height))
                            screen.blit(pic,
                                        (button_pressed.x, button_pressed.y))
                            pygame.display.flip()
        except pygame.error:
            pass

    if r_pressed:
        game()
    if escape_pressed:
        main()
Example #4
0
    def action(self, button, event, screen):
        mouse_click = event.button

        if mouse_click == 1:
            self.reveal(button, screen)
            self.verify_victory()

        elif mouse_click == 3:
            if not button.content.visible:
                status = button.content.right_click_action()

                if status == "Flag":
                    button.unclicked = picture.get_picture("flag")
                elif status == "Question":
                    button.unclicked = picture.get_picture("question")
                elif status == "Invisible":
                    button.unclicked = picture.get_picture("empty")

                button.unclicked = pygame.transform.scale(
                    button.unclicked, (button.width, button.height))
                screen.blit(button.unclicked, (button.x, button.y))
                pygame.display.flip()
                self.verify_victory()
 def put_number(self, number):
     self.content.put_number(number)
     self.clicked = picture.get_picture(number)
     self.clicked = pygame.transform.scale(self.clicked,
                                           (self.height, self.width))
 def put_bomb(self):
     self.content.put_bomb()
     self.clicked = picture.get_picture(9)
     self.clicked = pygame.transform.scale(self.clicked,
                                           (self.height, self.width))