def gameOver(self, score):
        player_sprite = AnimatedHero(self.display_width // 2,
                                     self.display_height // 2 - 20)

        for _ in range(30):
            self.draw_background()

            surface = pygame.Surface([self.display_width, self.display_height],
                                     pygame.SRCALPHA)
            surface.set_alpha(120)
            surface.fill(pygame.Color(255, 255, 255))

            gameOverFont = pygame.font.Font('arcade.ttf', 48)
            gameOverSurf, gameOverRect = text_object(
                'Game Over', gameOverFont, pygame.Color(120, 120, 120))
            gameOverRect.midtop = (self.display_width // 2,
                                   self.display_height // 2 - 120)

            scoreFont = pygame.font.Font('arcade.ttf', 36)
            scoreSurf, scoreRect = text_object('Reward ' + str(int(score)),
                                               scoreFont,
                                               pygame.Color(120, 120, 120))
            scoreRect = scoreSurf.get_rect()
            scoreRect.midtop = (self.display_width // 2,
                                self.display_height // 2 + 100)

            self.game_display.blit(surface, (0, 0))
            self.game_display.blit(gameOverSurf, gameOverRect)
            self.game_display.blit(scoreSurf, scoreRect)

            player_sprite.update()
            player_sprite.draw(self.game_display)

            pygame.display.flip()
            self.fpsClock.tick(30)
    def gameOver(self, score):
        # Set fonts of caption
        gameOverFont = pygame.font.Font('arial.ttf', 72)
        gameOverSurf, gameOverRect = text_object('Game Over', gameOverFont, greyColour)
        gameOverRect.midtop = (320, 125)
        self.playSurface.blit(gameOverSurf, gameOverRect)
        # Display scores and set fonts
        scoreFont = pygame.font.Font('arial.ttf', 48)
        scoreSurf, scoreRect = text_object('SCORE:'+str(score), scoreFont, greyColour)
        scoreRect = scoreSurf.get_rect()
        scoreRect.midtop = (320, 225)
        self.playSurface.blit(scoreSurf, scoreRect)
        #pygame.display.update() # Refresh display

        button(self.playSurface, 'Again', self.display_width//4, self.display_height//8*7, self.display_width//2, self.display_height//8, greenColour, brightGreenColour, self.init_game)
        # https://stackoverflow.com/questions/55881619/sleep-doesnt-work-where-it-is-desired-to/55882173#55882173
        pygame.display.update()
    def intro(self, training, testing):
        pygame.display.set_caption('Grab the coin!')
        pygame.init()
        display_width, display_height = 432, 432
        game_display = pygame.display.set_mode((display_width, display_height))
        fpsClock = pygame.time.Clock()

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

            width = game_display.get_width()
            height = game_display.get_height()

            land_image = pygame.image.load('static/land.png')
            land_image = pygame.transform.scale(land_image,
                                                (width // 6, height // 6))
            land_rect = land_image.get_rect()

            for i in np.linspace(0, width, num=7):
                for j in np.linspace(0, height, num=7):
                    land_rect.topleft = (i, j)
                    game_display.blit(land_image, land_rect)

            gameOverFont = pygame.font.Font('arcade.ttf', 36)
            gameOverSurf, gameOverRect = text_object(
                'Grab The Coin!', gameOverFont, pygame.Color(120, 120, 120))
            gameOverRect.midtop = (width // 2, height // 2 - 120)
            game_display.blit(gameOverSurf, gameOverRect)

            player_sprite = AnimatedHero(game_display.get_width() // 2,
                                         game_display.get_height() // 2 - 20,
                                         hero_type='idle')

            player_sprite.update()
            player_sprite.draw(game_display)

            button(game_display, 'train', width // 8, height // 8 * 7,
                   width // 6, height // 8, pygame.Color(120, 120, 120),
                   pygame.Color(150, 150, 150), training)
            button(game_display, 'test', width // 4 * 3, height // 8 * 7,
                   width // 6, height // 8, pygame.Color(120, 120, 120),
                   pygame.Color(150, 150, 150), testing)

            pygame.display.update()
    def game_intro(self):
        intro = True
        while intro:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()

            self.playSurface.fill(blackColour)
            textFont = pygame.font.Font('arial.ttf', 73)
            textSurf, textRect = text_object('AI Snake', textFont, greyColour)
            textRect.center = (self.display_width//2, self.display_height//2)
            self.playSurface.blit(textSurf, textRect)
            button(self.playSurface,'GO!', self.display_width//4, self.display_height//8*7, self.display_width//4, self.display_height//8, greenColour, brightGreenColour, run)
            button(self.playSurface, 'AI', display_width//2, self.display_height//8*7, display_width//4, self.display_height//8, redColour, brightRedColour, self.AI_option)
            pygame.display.update()