#importing necessary libraries import pygame, sys import highscore class GUI(): #a function made to execute other files from the system def runfile(runfilename): with open(runfilename,"r") as rnf: exec(rnf.read()) def button(Surface, color,Rect,width): pygame.draw.rect(Surface, color,Rect,width) def text(text,fontStyle,fontSize,color,coord,surface): font = pygame.font.SysFont(fontStyle,fontSize) text = font.render(text,True,color) surface.blit(text,coord) def main(): pygame.init() gray = [180,180,180] darkgray = [100,100,100] red = [255,0,0] #while loop required to always refresh the page while True: 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", 80,red,(150,80),game) #Adding the play game button if (270 <= mousepos[0] <= 270+250 and 450 <= mousepos[1] <= 450+55 ): #checks if the mouse is hovering over the button GUI.button(game,darkgray, [270,455,250,50], 0) #checking if the button is clicked if mouseclick[0] == 1: GUI.runfile('Gameplay.py') else: GUI.button(game,gray, [270,455,250,50], 0) GUI.text('GAME TIME',"comicsansms", 40,[0, 0, 200],(275,450),game) GUI.text('THEMES:',"comicsansms", 40,(0, 200, 0),(50,250),game) GUI.text('SPEED',"comicsansms", 40,(0, 150, 0),(50,350),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: #GUI.runfile('highscore.py') 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()