labyrinth_explorer.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:labyrinth-explorer 作者: ryukinix 项目源码 文件源码
def game():
    setup()
    running = True
    start = time()
    while running:

        clock.tick(60)

        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                running = False
            if e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
                running = False

        # Move the player if an arrow key is pressed
        key = pygame.key.get_pressed()
        if key[pygame.K_LEFT]:
            player.move(-2, 0)
        if key[pygame.K_RIGHT]:
            player.move(2, 0)
        if key[pygame.K_UP]:
            player.move(0, -2)
        if key[pygame.K_DOWN]:
            player.move(0, 2)

        # Just added this to make it slightly fun ;)
        if player.rect.colliderect(end_rect):
            raise SystemExit("You win! @{:2f}s".format(time() - start))
        if computer.rect.colliderect(end_rect):
            raise SystemExit("You lost! The computer wins")
        # Draw the scene
        screen.fill(BLACK)
        computer.run()
        for wall in walls:
            pygame.draw.rect(screen, WHITE, wall.rect)
        pygame.draw.rect(screen, RED, end_rect)
        pygame.draw.rect(screen, GREEN, player.rect)
        pygame.draw.rect(screen, YELLOW, computer.rect)
        draw_counter(time() - start)
        pygame.display.flip()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号