Skip to content
Snippets Groups Projects
ScoreDisplay.py 2.53 KiB
Newer Older
  • Learn to ignore specific revisions
  • 's avatar
    committed
    ## @file ScoreDisplay.py
    #  @author Vaibhav Chadha
    #  @brief implements the interface after the snake dies
    #  @date 11/22/2018
    
    import pygame, sys
    
    's avatar
    committed
    import highscore, Interface, Gameplay
    
    's avatar
    committed
    
    def storeScore(score):
        prevScore = int(highscore.HighScore.findHighScore())
        #print(prevScore)
        if(score > prevScore):
            infile = open("highscore.txt", "w")
            infile.write(str(score))
        else: return
    
    
    's avatar
    committed
    def display(score,speed, colour,food_colour, backgroundColour):
    
    's avatar
    committed
        pygame.init()
        storeScore(score)
    
    Hameed Andy's avatar
    Hameed Andy committed
        lightBlue = [89,131,145]
        darkgray = [100,100,100]
        white = [255,255,255]
    
        image1 = pygame.image.load("Images/Exit_image.png")
    
    's avatar
    committed
        run = True
        while run:
    
    ##        roboto_font = pygame.font.Font("Roboto-Black.ttf", 35)
    
    's avatar
    committed
            mousepos = pygame.mouse.get_pos() #checking mouse position
            mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
    
    's avatar
    committed
            lastPage = pygame.display.set_mode((500, 500))
    
    Hameed Andy's avatar
    Hameed Andy committed
            lastPage.blit(image1,(0,0))
    ##        lastPage.fill()
    
    's avatar
    committed
    
    
            highscore.HighScore.custom_text('Your Score is ' + str(score),"Roboto-Light.ttf", 40,[0, 0, 0],(93,50),lastPage)
    
    's avatar
    committed
    
    
    's avatar
    committed
            if (150 <= mousepos[0] <= 150+200 and 150 <= mousepos[1] <= 150+60 ):
    
    Hameed Andy's avatar
    Hameed Andy committed
                highscore.HighScore.button(lastPage,darkgray, [150,150,200,60], 0)
    
    's avatar
    committed
                if mouseclick[0] == 1:
    
    's avatar
    committed
                    Gameplay.game(speed, colour,food_colour, backgroundColour)
    
    's avatar
    committed
            else:
    
    Hameed Andy's avatar
    Hameed Andy committed
                highscore.HighScore.button(lastPage,lightBlue, [150,150,200,60], 0)
    
            highscore.HighScore.custom_text('Play Again',"Roboto-Light.ttf", 25, white,(193,165),lastPage)
    
    's avatar
    committed
    
    
    's avatar
    committed
            if (150 <= mousepos[0] <= 150+200 and 260 <= mousepos[1] <= 260+60 ):
    
    Hameed Andy's avatar
    Hameed Andy committed
                highscore.HighScore.button(lastPage,darkgray, [150,260,200,60], 0)
    
    's avatar
    committed
                if mouseclick[0] == 1:
                    Interface.main()
            else:
    
    Hameed Andy's avatar
    Hameed Andy committed
                highscore.HighScore.button(lastPage,lightBlue, [150,260,200,60], 0)
    
            highscore.HighScore.custom_text('Main Menu',"Roboto-Light.ttf", 25,white,(189,275),lastPage)
    
    's avatar
    committed
            
            if (150 <= mousepos[0] <= 150+200 and 370 <= mousepos[1] <= 370+60 ):
    
    Hameed Andy's avatar
    Hameed Andy committed
                highscore.HighScore.button(lastPage,darkgray, [150,370,200,60], 0)
    
    's avatar
    committed
                if mouseclick[0] == 1:
                    pygame.quit()
                    sys.exit()
            else:
    
    Hameed Andy's avatar
    Hameed Andy committed
                highscore.HighScore.button(lastPage,lightBlue, [150,370,200,60], 0)
    
            highscore.HighScore.custom_text('Quit',"Roboto-Light.ttf", 25,white,(225,385),lastPage)
    
    's avatar
    committed
                
            pygame.display.update()
    
    #display(99)