Exemplo n.º 1
0
class Game():
    """
    
    """
    def __init__(self, win_res, gridsize, fps_max):
        pygame.init()
        self.gridsize = gridsize
        self.clock = pygame.time.Clock()
        self.window = Window(win_res, self.gridsize)
        self.snake = Snake(self)
        self.food = Food(self.window)
        self.fps_max = fps_max

    def run_game(self):

        while True:
            # Program body

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    print("Fermeture du jeu, Goodbye!")
                    pygame.quit()
                    sys.exit()
                else:
                    if event.type == pygame.KEYDOWN:
                        self.snake.keys_handling(event.key)

            self.window.screen.blit(self.window.checkerboard, (0, 0))
            self.snake.move()
            self.snake.draw()
            self.snake.eat()
            self.food.add_color()
            self.food.draw()
            pygame.display.update()
            self.clock.tick(self.fps_max)