예제 #1
0
factory = PlayerFactory(surface)
player_one, player_two = factory.get_players()
active_player = player_one

game_over = False
valid_hit = True
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

        if not game_over and event.type == pygame.MOUSEBUTTONDOWN:
            if pygame.mouse.get_pressed()[0]:
                pos = pygame.mouse.get_pos()
                tile = (pos[0] // Grid.TILE_WIDTH,
                        (pos[1] - Grid.TOP_PANEL_HEIGHT) // Grid.TILE_HEIGHT)
                valid_hit = grid.hit(tile, active_player)
                if valid_hit:
                    game_over = game_manager.is_over(tile, grid.tiles)
                    if not game_over:
                        if active_player == player_one:
                            active_player = player_two
                        else:
                            active_player = player_one

    surface.fill((0, 0, 0))
    grid.draw(surface)
    game_manager.draw(surface, valid_hit, game_over, active_player)
    pygame.display.flip()
예제 #2
0
from board import Board
from constants import WIDTH, HEIGHT

pygame.init()
pygame.font.init()
clock = pygame.time.Clock()
pygame.display.set_caption("Chess")
pygame.display.set_icon(
    pygame.image.load(f"{os.getcwd()}\images\\white_king.png"))
screen = pygame.display.set_mode((WIDTH, HEIGHT))

game = GameManager(screen)

while True:
    clock.tick(60)
    game.draw()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            game.quit()

        if event.type == pygame.MOUSEBUTTONDOWN:
            x, y = game.get_clicked()
            game.select(x, y)

        if event.type == pygame.KEYDOWN:
            game.started = True
            if event.key == pygame.K_r:
                game.reset()

    pygame.display.flip()
예제 #3
0
        if output:
            fps = video.get(cv2.CAP_PROP_FPS)
            width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH) * output_scaling)
            height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT) * output_scaling)
            output['writer'] = cv2.VideoWriter(output['file'],
                                               cv2.VideoWriter_fourcc(*'MP4V'),
                                               fps, (width, height))
            print('Writing output video to {}'.format(output['file']))

        while True:
            ret, frame = video.read()
            if not ret:
                break
            manager.processFrame(frame)
            manager.draw(frame)
            frame = cv2.resize(frame,
                               None,
                               fx=output_scaling,
                               fy=output_scaling,
                               interpolation=cv2.INTER_AREA)

            if output:
                output['writer'].write(frame)

            if not output:
                cv2.imshow('Video', frame)
                if cv2.waitKey(10) & 0xFF == ord('q'):
                    break

        video.release()