Пример #1
0
state = States.running

player = Player()
grid = Grid(player)

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN and state == States.running:
            if pygame.mouse.get_pressed()[0]: # check for the left mouse button
                pos = pygame.mouse.get_pos()
                grid.click(pos[0], pos[1])
            elif pygame.mouse.get_pressed()[2]:
                pos = pygame.mouse.get_pos()
                grid.mark_mine(pos[0]//30, pos[1]//30)
            if grid.check_if_win():
                state = States.win
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE and (state == States.game_over or state == States.win):
                grid.reload()
                state = States.running
            if event.key == pygame.K_b:
                grid.show_mines()

    surface.fill((0,0,0))

    if player.get_health() == 0:
Пример #2
0
def main():
    while (setting.menu_pick):

        width = 540
        height = 650
        main_menu = pygame.display.set_mode((width, height))
        mode_pick = True
        run = True

        while mode_pick:
            reddraw_main_menu(main_menu)
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        mode_pick = False
                        run = False
                        setting.menu_pick = False
                if event.type == pygame.MOUSEBUTTONDOWN:
                    pos = pygame.mouse.get_pos()
                    if (button(220, 100, 100, 40, pos)):
                        setting.number = 5
                        button_selected_toFalse()
                        setting.picked_5 = True
                    if (button(220, 160, 100, 40, pos)):
                        setting.number = 6
                        button_selected_toFalse()
                        setting.picked_6 = True
                    if (button(220, 220, 100, 40, pos)):
                        setting.number = 7
                        button_selected_toFalse()
                        setting.picked_7 = True
                    if (button(420, 580, 100, 40, pos)):
                        mode_pick = False
            pygame.display.update()

        win = pygame.display.set_mode((width, height))
        pygame.display.set_caption("Hitori")
        the_board = return_board(
            setting.number
        )  # Sets the board to a random board based on what size board the user chose.
        board = Grid(setting.number, setting.number, 540, 540, the_board)
        board.mark_all_cubes_type()
        start = time.time()
        strikes = 0
        clock_running = True

        while run:
            if (clock_running):
                play_time = round(time.time() - start)
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        run = False
                        setting.menu_pick = False
                if event.type == pygame.QUIT:
                    run = False
                if event.type == pygame.MOUSEBUTTONDOWN:
                    pos = pygame.mouse.get_pos()

                    #Checks to if a button is clicked below the board
                    if (button(260, 550, 100, 40, pos)):

                        if (board.path_check()):
                            print(
                                "All non marked squares can reach each other")
                        else:
                            print(
                                "Marked Cubes are blocking off non marked cubes, Wrong"
                            )
                        if (board.adjacent_marked_check()
                                and board.num_col_row_check()
                                and board.path_check()):
                            print("win")
                            clock_running = False
                            set_fastest_time(play_time)
                        else:
                            print("fail")
                            if (strikes <= 8):
                                strikes += 1

                    if (button(260, 600, 100, 40, pos)):
                        run = False

                    #checks to see if game board is clicked
                    clicked = board.click(pos)
                    if clicked:
                        board.select(clicked[0], clicked[1])
            redraw_window(win, board, play_time, strikes)
            pygame.display.update()