Skip to content
Snippets Groups Projects
Commit 8315ff7b authored by Hameed Andy's avatar Hameed Andy
Browse files

renamed files

parent 170094ae
No related branches found
No related tags found
No related merge requests found
#importing necessary libraries #importing necessary libraries
import pygame, sys import pygame, sys
import highscore import highscore
class GUI(): class GUI():
#a function made to execute other files from the system #a function made to execute other files from the system
def runfile(runfilename): def runfile(runfilename):
with open(runfilename,"r") as rnf: with open(runfilename,"r") as rnf:
exec(rnf.read()) exec(rnf.read())
def button(Surface, color,Rect,width): def button(Surface, color,Rect,width):
pygame.draw.rect(Surface, color,Rect,width) pygame.draw.rect(Surface, color,Rect,width)
def text(text,fontStyle,fontSize,color,coord,surface): def text(text,fontStyle,fontSize,color,coord,surface):
font = pygame.font.SysFont(fontStyle,fontSize) font = pygame.font.SysFont(fontStyle,fontSize)
text = font.render(text,True,color) text = font.render(text,True,color)
surface.blit(text,coord) surface.blit(text,coord)
def main(): def main():
pygame.init() pygame.init()
gray = [180,180,180] gray = [180,180,180]
darkgray = [100,100,100] darkgray = [100,100,100]
red = [255,0,0] red = [255,0,0]
#while loop required to always refresh the page #while loop required to always refresh the page
while True: while True:
game = pygame.display.set_mode((800, 610)) game = pygame.display.set_mode((800, 610))
game.fill([213, 219, 219]) game.fill([213, 219, 219])
mousepos = pygame.mouse.get_pos() #checking mouse position mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Lets Play") pygame.display.set_caption("Lets Play")
GUI.text('SNAKE GAME',"monospace", 80,red,(150,80),game) GUI.text('SNAKE GAME',"monospace", 80,red,(150,80),game)
#Adding the play game button #Adding the play game button
if (270 <= mousepos[0] <= 270+250 and 450 <= mousepos[1] <= 450+55 ): if (270 <= mousepos[0] <= 270+250 and 450 <= mousepos[1] <= 450+55 ):
#checks if the mouse is hovering over the button #checks if the mouse is hovering over the button
GUI.button(game,darkgray, [270,455,250,50], 0) GUI.button(game,darkgray, [270,455,250,50], 0)
#checking if the button is clicked #checking if the button is clicked
if mouseclick[0] == 1: if mouseclick[0] == 1:
GUI.runfile('Snake_2.o_Demo.py') GUI.runfile('Snake_2.o_Demo.py')
else: else:
GUI.button(game,gray, [270,455,250,50], 0) GUI.button(game,gray, [270,455,250,50], 0)
GUI.text('GAME TIME',"comicsansms", 40,[0, 0, 200],(275,450),game) 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('THEMES:',"comicsansms", 40,(0, 200, 0),(50,250),game)
GUI.text('SPEED',"comicsansms", 40,(0, 150, 0),(50,350),game) GUI.text('SPEED',"comicsansms", 40,(0, 150, 0),(50,350),game)
#Highest Score #Highest Score
if ( 10 <= mousepos[0] <= 310 and 550 <= mousepos[1] <= 550 +55): if ( 10 <= mousepos[0] <= 310 and 550 <= mousepos[1] <= 550 +55):
GUI.button(game,[200,0,0],[10,550,300,55], 0) GUI.button(game,[200,0,0],[10,550,300,55], 0)
if mouseclick[0] == 1: if mouseclick[0] == 1:
#GUI.runfile('highscore.py') #GUI.runfile('highscore.py')
highscore.main() highscore.main()
else: else:
GUI.button(game,[180,180,180], [10,550,300,55], 0) GUI.button(game,[180,180,180], [10,550,300,55], 0)
GUI.text('HIGHEST SCORE',"comicsansms", 35,(0, 0, 0),(10,550),game) GUI.text('HIGHEST SCORE',"comicsansms", 35,(0, 0, 0),(10,550),game)
#If user wants to quit #If user wants to quit
if ( 670 <= mousepos[0] <= 670+105 and 550 <= mousepos[1] <= 550 +55): if ( 670 <= mousepos[0] <= 670+105 and 550 <= mousepos[1] <= 550 +55):
GUI.button(game,[200,0,0],[670,550,105,55], 0) GUI.button(game,[200,0,0],[670,550,105,55], 0)
if mouseclick[0] == 1: if mouseclick[0] == 1:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
else: else:
GUI.button(game,[180,180,180], [670,550,105,55], 0) GUI.button(game,[180,180,180], [670,550,105,55], 0)
GUI.text('QUIT',"comicsansms", 35,(0, 0, 0),(670,550),game) GUI.text('QUIT',"comicsansms", 35,(0, 0, 0),(670,550),game)
pygame.display.update() pygame.display.update()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment