Example #1
0
def draw_path_3D(solution, timesleep=0.5, level=Level.lv1, map_size=(0, 0)):
    pygame.init()
    display = Display(title='Bloxorz Game', map_size=map_size)
    if solution != None:
        print("Success!")
        print("Step: %d" % len(solution))
        print(solution)
        choiselv = maps(level)

        level = Control(choiselv)
        level.draw_StartBox()
        level.draw_StartMaps()
        display.update()

        for path in solution:
            time.sleep(timesleep)
            level.current = path
            level.update_box_locaton_for_maps(path)

            if level.maps.refreshBox():
                level.update_current_location()
            else:
                print("Solution Fail!")
                return

            level.draw_box()
            level.draw_maps()
            display.update()
        return
    else:
        print("Unable to find path for maps!")
        print("Dir Level: %s" % level)
        return
Example #2
0
def handle(state: Control, map_size=(0, 0)):
    state.Play_handle = True
    pygame.init()
    display = Display(title='Bloxorz Game', map_size=map_size)
    result = True
    print("Press Space Key to Exit!")
    while True:
        # os.system("clear")
        for event in pygame.event.get():
            if state.Play_handle:
                if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
                    result = state.move_up()
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
                    result = state.move_down()
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
                    result = state.move_right()
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
                    result = state.move_left()

            if display.quit(event):
                return
        state.draw_maps()
        state.draw_box()
        # state.print_maps()
        display.update()

        if state.check_goal():
            print("WINNER!")
            return
        if result == False:
            print("LOSER!")
            return
Example #3
0
def bfs_step_by_step(state: Control, timesleep=0.2):
    pygame.init()
    display = Display(title='Bloxorz Game',
                      map_size=(state.size[0], state.size[1]))

    while state.stack:
        current_state, current_maps = state.stack.pop(0)

        print("POP: ( %s )" % current_state)

        state.visted.append((current_state, current_maps))

        for move in state.moves:
            state.set_state(current_state, current_maps)

            print_stack(state.stack, "bfs")
            state.maps.print_current()
            state.draw_box()
            state.draw_maps()
            display.update()
            time.sleep(timesleep)
            os.system("clear")

            if move():
                print_stack(state.stack, "bfs")
                state.maps.print_current()
                time.sleep(timesleep)
                os.system("clear")
                if state.check_goal():
                    print("WINNER!")
                    state.maps.print_current()
                    state.draw_box()
                    state.draw_maps()
                    display.update()
                    time.sleep(timesleep)
                    return state

            os.system("clear")