## @file interface.py # @author Vaibhav Chadha # @brief implements the main interface of this game # @date 11/09/2018 #importing necessary libraries import pygame, sys import highscore, theme ## @brief A Class that will contain useful functions in order for the creation of main interface class GUI(): ## @brief A function for running other files # @details Executes another python file when this is selected, Given that the file is in same folder. # @param runfilename The name of the file to be executed def runfile(runfilename): with open(runfilename,"r") as rnf: exec(rnf.read()) ## @brief A method to create a button # @details This method will make a box on the interface # @param surface The background (surface) the box should be made on # @param color The color of the button to be made # @param Rect The coordinate of the button with the length and width # @param width The width of the sides of button def button(Surface, color,Rect,width): pygame.draw.rect(Surface, color,Rect,width) ## @brief A method to display text # @details This function will print the text on the interface # @param text The text to be printed # @param fontStyle The font Style of the text to be displayed # @param fontSize The size of the text written # @param color The color of the text # @param coord The coordinate at which the text should start displaying # @param surface The background (surface) the text should be printed on def text(text,fontStyle,fontSize,color,coord,surface): font = pygame.font.SysFont(fontStyle,fontSize) text = font.render(text,True,color) surface.blit(text,coord) ## @brief Makes the main interface of this game # @details This will output the main page of this game by using the class above def main(): pygame.init() lightgray = [200,200,200] gray = [180,180,180] darkgray = [100,100,100] red = [255,0,0] #while loop required to always refresh the page run = True while run: game = pygame.display.set_mode((800, 610)) game.fill([213, 219, 219]) mousepos = pygame.mouse.get_pos() #checking mouse position mouseclick = pygame.mouse.get_pressed()#checking mouse pressed pygame.display.set_caption("Lets Play") GUI.text('SNAKE GAME',"monospace", 100,red,(100,80),game) #Adding the play game button if (130 <= mousepos[0] <= 130+250 and 250 <= mousepos[1] <= 250+100 ): #checks if the mouse is hovering over the button GUI.button(game,darkgray, [130,250,250,100], 0) #checking if the button is clicked if mouseclick[0] == 1: theme.Themes.themes() else: GUI.button(game,lightgray, [130,250,250,100], 0) GUI.text('Beginner',"comicsansms", 40,[10, 200, 10],(170,270),game) if (430 <= mousepos[0] <= 430+250 and 250 <= mousepos[1] <= 250+100 ): #checks if the mouse is hovering over the button GUI.button(game,darkgray, [430,250,250,100], 0) #checking if the button is clicked if mouseclick[0] == 1: theme.Themes.themes() else: GUI.button(game,lightgray, [430,250,250,100], 0) GUI.text('Intermediate',"comicsansms", 40,[250, 250, 10],(431,270),game) if (270 <= mousepos[0] <= 270+250 and 400 <= mousepos[1] <= 400+100 ): #checks if the mouse is hovering over the button GUI.button(game,darkgray, [270,400,250,100], 0) #checking if the button is clicked if mouseclick[0] == 1: theme.Themes.themes() else: GUI.button(game,lightgray, [270,400,250,100], 0) GUI.text('Advanced',"comicsansms", 40,[200, 10, 30],(300,420),game) #Highest Score if ( 10 <= mousepos[0] <= 310 and 550 <= mousepos[1] <= 550 +55): GUI.button(game,[200,0,0],[10,550,300,55], 0) if mouseclick[0] == 1: highscore.main() else: GUI.button(game,[180,180,180], [10,550,300,55], 0) GUI.text('HIGHEST SCORE',"comicsansms", 35,[0, 0, 0],(10,550),game) #If user wants to quit if ( 670 <= mousepos[0] <= 670+105 and 550 <= mousepos[1] <= 550 +55): GUI.button(game,[200,0,0],[670,550,105,55], 0) if mouseclick[0] == 1: pygame.quit() sys.exit() else: GUI.button(game,[180,180,180], [670,550,105,55], 0) GUI.text('QUIT',"comicsansms", 35,(0, 0, 0),(670,550),game) pygame.display.update() if __name__ == "__main__": main()