예제 #1
0
def runGUI():
    pygame.init()
    pygame.display.set_caption('BattleHacks Zepharch')
    window_surface = pygame.display.set_mode((800, 700))

    background = pygame.Surface((800, 700))
    background.fill(pygame.Color('#66AD40'))

    manager = pygame_gui.UIManager((800, 700))

    stepButton = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((50, 610), (700, 80)),
                                                text='Step Turn',
                                                manager=manager)

    clock = pygame.time.Clock()
    is_running = True
    # run.play_all(delay = 0.1, keep_history = True, real_time = True)
    run.viewer = BasicViewer(GameConstants.BOARD_SIZE, run.game.board_states, colors=False)
    run.viewer_poison_pill = threading.Event()
    run.viewer_thread = threading.Thread(target=run.viewer.play_synchronized, args=(run.viewer_poison_pill,), kwargs={'delay': 0.1, 'keep_history': True})
    run.viewer_thread.daemon = True
    run.viewer_thread.start()


    while is_running:
        time_delta = clock.tick(60)/1000.0
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                is_running = False

            if event.type == pygame.USEREVENT:
                if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
                    if event.ui_element == stepButton:
                        run.step()

            manager.process_events(event)

        manager.update(time_delta)

        window_surface.blit(background, (0, 0))
        manager.draw_ui(window_surface)

        pygame.display.update()
    # run.viewer_thread.stop()
    run.viewer_poison_pill.set()
    sys.exit()
예제 #2
0
    code_container1 = CodeContainer.from_directory(args.player[0])
    code_container2 = CodeContainer.from_directory(
        args.player[1] if len(args.player) > 1 else args.player[0])

    # This is how you initialize a game,
    game = Game([code_container1, code_container2],
                board_size=args.board_size,
                max_rounds=args.max_rounds,
                seed=args.seed,
                debug=args.debug,
                colored_logs=not args.raw_text)

    # ... and the viewer.
    if args.basic_viewer == True:
        viewer = BasicViewer(args.board_size,
                             game.board_states,
                             colors=not args.raw_text)
    else:
        viewer = FancyViewer(args.board_size, game.board_states)

    # Here we check if the script is run using the -i flag.
    # If it is not, then we simply play the entire game.
    if not sys.flags.interactive:
        play_all(delay=float(args.delay),
                 keep_history=args.raw_text,
                 real_time=not args.debug)

    else:
        # print out help message!
        print("Run step() to step through the game.")
        print("You also have access to the variables: game, viewer")