diff --git a/BlankProjectTemplate/src/Interface.py b/BlankProjectTemplate/src/Interface.py index 1343c5166671432a3be2e1b7f6b6614f93bd88c5..c82c0c2e80c9169aa084bf3d7c95693bc31c31ce 100644 --- a/BlankProjectTemplate/src/Interface.py +++ b/BlankProjectTemplate/src/Interface.py @@ -4,7 +4,7 @@ # @date 11/09/2018 #importing necessary libraries import pygame, sys -import highscore +import highscore, theme ## @brief A Class that will contain useful functions in order for the creation of main interface class GUI(): @@ -41,43 +41,60 @@ class GUI(): # @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 - while True: + 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", 80,red,(150,80),game) - + GUI.text('SNAKE GAME',"monospace", 100,red,(100,80),game) + #Adding the play game button - if (270 <= mousepos[0] <= 270+250 and 450 <= mousepos[1] <= 450+55 ): + 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, [270,455,250,50], 0) + GUI.button(game,darkgray, [130,250,250,100], 0) #checking if the button is clicked if mouseclick[0] == 1: - GUI.runfile('Gameplay.py') + theme.Themes.themes() else: - GUI.button(game,gray, [270,455,250,50], 0) - GUI.text('GAME TIME',"comicsansms", 40,[0, 0, 200],(275,450),game) + 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) - GUI.text('THEMES:',"comicsansms", 40,(0, 200, 0),(50,250),game) - GUI.text('SPEED',"comicsansms", 40,(0, 150, 0),(50,350),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: - #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) + 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): diff --git a/BlankProjectTemplate/src/__pycache__/Food.cpython-36.pyc b/BlankProjectTemplate/src/__pycache__/Food.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d6aca9879bb6e3918337383ff5dfcf75dceead49 Binary files /dev/null and b/BlankProjectTemplate/src/__pycache__/Food.cpython-36.pyc differ diff --git a/BlankProjectTemplate/src/__pycache__/Gameplay.cpython-36.pyc b/BlankProjectTemplate/src/__pycache__/Gameplay.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..80a4f1e51a295101f5f1d654e99e983072a1946b Binary files /dev/null and b/BlankProjectTemplate/src/__pycache__/Gameplay.cpython-36.pyc differ diff --git a/BlankProjectTemplate/src/__pycache__/Interface.cpython-36.pyc b/BlankProjectTemplate/src/__pycache__/Interface.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c8bdba0319c99e76d03cd6ed3477fd05f427f73c Binary files /dev/null and b/BlankProjectTemplate/src/__pycache__/Interface.cpython-36.pyc differ diff --git a/BlankProjectTemplate/src/__pycache__/Snake.cpython-36.pyc b/BlankProjectTemplate/src/__pycache__/Snake.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..affb6ce8ccd28c976b8174f5dcf5f4caaef7723a Binary files /dev/null and b/BlankProjectTemplate/src/__pycache__/Snake.cpython-36.pyc differ diff --git a/BlankProjectTemplate/src/__pycache__/highscore.cpython-36.pyc b/BlankProjectTemplate/src/__pycache__/highscore.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a307ff46c015301dd2fffcfb43dbd15b3bd04207 Binary files /dev/null and b/BlankProjectTemplate/src/__pycache__/highscore.cpython-36.pyc differ diff --git a/BlankProjectTemplate/src/__pycache__/init.cpython-36.pyc b/BlankProjectTemplate/src/__pycache__/init.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4fd537b1ac24f64d1aa3b56121c95091b2eb8a7f Binary files /dev/null and b/BlankProjectTemplate/src/__pycache__/init.cpython-36.pyc differ diff --git a/BlankProjectTemplate/src/__pycache__/theme.cpython-36.pyc b/BlankProjectTemplate/src/__pycache__/theme.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d399706dc49bdf66bbd76629005b2f67686eacb2 Binary files /dev/null and b/BlankProjectTemplate/src/__pycache__/theme.cpython-36.pyc differ diff --git a/BlankProjectTemplate/src/highscore.py b/BlankProjectTemplate/src/highscore.py index 3864f041b2a586f41b5a0a0ba3fc0f131f894e2f..cf4e413d78a78401ee81c5a3388b56bda1b1ef4b 100644 --- a/BlankProjectTemplate/src/highscore.py +++ b/BlankProjectTemplate/src/highscore.py @@ -2,19 +2,11 @@ # @author Vaibhav Chadha # @brief implements the highscore interface # @date 11/09/2018 -import pygame, sys +import pygame, sys, Interface ## @brief A Class that will contain useful functions in order for the creation of highscore page class HighScore(): - - ## @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 display text # @details This function will print the text on the interface # @param text The text to be printed @@ -65,8 +57,7 @@ def main(): HighScore.text('Main Menu',"times", 25,red,(90,70),highscore) if (90 <= mousepos[0] <= 90+120 and 70 <= mousepos[1] <= 70+27 ): if mouseclick[0] == 1: - HighScore.runfile('Interface.py') - #Snake_Game.main() + Interface.main() HighScore.button(highscore,[0,0,0], [125,105,45,27], 0) HighScore.text('Quit',"times", 25,red,(125,105),highscore) @@ -76,5 +67,3 @@ def main(): sys.exit() pygame.display.update() - -#main() diff --git a/BlankProjectTemplate/src/theme.py b/BlankProjectTemplate/src/theme.py new file mode 100644 index 0000000000000000000000000000000000000000..e4459058240b619dc5bad5b246fd810d3e45e649 --- /dev/null +++ b/BlankProjectTemplate/src/theme.py @@ -0,0 +1,59 @@ +import pygame, sys + +class Themes(): + + ## @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) + + def themes(): + pygame.init() + run = True + while run: + theme = pygame.display.set_mode((450, 300)) + theme.fill([200, 150, 250]) + mousepos = pygame.mouse.get_pos() #checking mouse position + mouseclick = pygame.mouse.get_pressed()#checking mouse pressed + pygame.display.set_caption("Choose Theme") + + Themes.text('Choose Your Theme',"times",45,[96,96,96],(50,50),theme) + + Themes.button(theme,[200,200,200], [50,150,150,100], 0) + Themes.text('Regular',"comicsansms", 40,[200, 0, 0],(55,170),theme) + if (50 <= mousepos[0] <= 50+150 and 150 <= mousepos[1] <= 150+100 ): + if mouseclick[0] == 1: + Themes.runfile('Gameplay.py') + + Themes.button(theme,[0,0,0], [250,150,150,100], 0) + Themes.text('Dark',"comicsansms", 40,[255,255,255],(275,170),theme) + if (250 <= mousepos[0] <= 250+150 and 150 <= mousepos[1] <= 150+100 ): + if mouseclick[0] == 1: + Themes.runfile('Gameplay.py') + + pygame.display.update() +