diff --git a/BlankProjectTemplate/src/Gameplay.py b/BlankProjectTemplate/src/Gameplay.py index ee3a18eb7bab29c7f50750b515469e0f7812be6c..b808c4385c083b5ed39d9408a2bd81d25cc0577c 100644 --- a/BlankProjectTemplate/src/Gameplay.py +++ b/BlankProjectTemplate/src/Gameplay.py @@ -13,7 +13,11 @@ import GUI def game(speed, colour,food_colour, backgroundColour): pygame.event.clear() image = pygame.image.load("Images/barrier.png") + black1 = (48,47,47) + black = [0,0,0] + white = [255,255,255] + x = randint(0, grid_length) * size y = randint(0, grid_length) * size #defining a list to update snanke's length @@ -131,8 +135,8 @@ def game(speed, colour,food_colour, backgroundColour): win.blit(image,(380,100)) #Display Score - sc_color = [0,0,0] if backgroundColour[0] == 255 else [255,255,255] - GUI.text(" " + str(score),"Roboto-Light.ttf",30,sc_color,(0,0),win) + sc_color = black if backgroundColour[0] == 255 else white + GUI.custom_text(" " + str(score),"Roboto-Light.ttf",30,sc_color,(0,0),win) if ([x,y] in snake_loc) and snake_length > 1: ScoreDisplay.display(score,speed, colour,food_colour, backgroundColour) diff --git a/BlankProjectTemplate/src/ScoreDisplay.py b/BlankProjectTemplate/src/ScoreDisplay.py index 0c9820d09d886782b4a354091557063ec2469f8e..3dc2cbd49b6dd1a5173636c624eb8148eda20517 100644 --- a/BlankProjectTemplate/src/ScoreDisplay.py +++ b/BlankProjectTemplate/src/ScoreDisplay.py @@ -5,6 +5,7 @@ import pygame, sys import highscore, Interface, Gameplay +import GUI def storeScore(score): prevScore = int(highscore.HighScore.findHighScore()) @@ -33,32 +34,32 @@ def display(score,speed, colour,food_colour, backgroundColour): lastPage.blit(image1,(0,0)) ## lastPage.fill() - highscore.HighScore.custom_text('Your Score is ' + str(score),"Roboto-Light.ttf", 40,[0, 0, 0],(93,50),lastPage) + GUI.custom_text('Your Score is ' + str(score),"Roboto-Light.ttf", 40,[0, 0, 0],(93,50),lastPage) if (150 <= mousepos[0] <= 150+200 and 150 <= mousepos[1] <= 150+60 ): - highscore.HighScore.button(lastPage,darkgray, [150,150,200,60], 0) + GUI.button(lastPage,darkgray, [150,150,200,60], 0) if mouseclick[0] == 1: Gameplay.game(speed, colour,food_colour, backgroundColour) else: - highscore.HighScore.button(lastPage,lightBlue, [150,150,200,60], 0) - highscore.HighScore.custom_text('Play Again',"Roboto-Light.ttf", 25, white,(193,165),lastPage) + GUI.button(lastPage,lightBlue, [150,150,200,60], 0) + GUI.custom_text('Play Again',"Roboto-Light.ttf", 25, white,(193,165),lastPage) if (150 <= mousepos[0] <= 150+200 and 260 <= mousepos[1] <= 260+60 ): - highscore.HighScore.button(lastPage,darkgray, [150,260,200,60], 0) + GUI.button(lastPage,darkgray, [150,260,200,60], 0) if mouseclick[0] == 1: Interface.main() else: - highscore.HighScore.button(lastPage,lightBlue, [150,260,200,60], 0) - highscore.HighScore.custom_text('Main Menu',"Roboto-Light.ttf", 25,white,(189,275),lastPage) + GUI.button(lastPage,lightBlue, [150,260,200,60], 0) + GUI.custom_text('Main Menu',"Roboto-Light.ttf", 25,white,(189,275),lastPage) if (150 <= mousepos[0] <= 150+200 and 370 <= mousepos[1] <= 370+60 ): - highscore.HighScore.button(lastPage,darkgray, [150,370,200,60], 0) + GUI.button(lastPage,darkgray, [150,370,200,60], 0) if mouseclick[0] == 1: pygame.quit() sys.exit() else: - highscore.HighScore.button(lastPage,lightBlue, [150,370,200,60], 0) - highscore.HighScore.custom_text('Quit',"Roboto-Light.ttf", 25,white,(225,385),lastPage) + GUI.button(lastPage,lightBlue, [150,370,200,60], 0) + GUI.custom_text('Quit',"Roboto-Light.ttf", 25,white,(225,385),lastPage) pygame.display.update() diff --git a/BlankProjectTemplate/src/help_.py b/BlankProjectTemplate/src/help_.py index 1c93a918625d2116a5260ac0189efa911468a642..884e7ce50036093c668afd7671b72d9b1734ee61 100644 --- a/BlankProjectTemplate/src/help_.py +++ b/BlankProjectTemplate/src/help_.py @@ -10,6 +10,7 @@ os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y) import pygame, sys import Interface +import GUI def main(): pygame.init() @@ -22,35 +23,35 @@ def main(): mouseclick = pygame.mouse.get_pressed()#checking mouse pressed pygame.display.set_caption("Help") - Interface.GUI.text('Use the following keys for the movement of the snake:','times',20,[130,190,0],(40,30),help_) - Interface.GUI.text('"Up" arrow key for turning Upwards','times',20,[90,190,0],(60,60),help_) - Interface.GUI.text('"Down" arrow key for turning Downwards','times',20,[90,190,0],(60,90),help_) - Interface.GUI.text('"Right" arrow key for turning Rightwards','times',20,[90,190,0],(60,120),help_) - Interface.GUI.text('"Left" arrow key for turning Leftwards','times',20,[90,190,0],(60,150),help_) - Interface.GUI.text('Beginner:','times',20,[200,0,0],(60,190),help_) - Interface.GUI.text('The snake can cross through the boundaries','times',20,[90,190,0],(140,190),help_) - Interface.GUI.text('Intermediate:','times',20,[200,0,0],(60,220),help_) - Interface.GUI.text('The snake will die as it touches the ','times',20,[90,190,0],(165,220),help_) - Interface.GUI.text('boundary.(The speed is faster than beginner)','times',20,[90,190,0],(140,250),help_) - Interface.GUI.text('Advance:','times',20,[200,0,0],(60,280),help_) - Interface.GUI.text('The snake will die as it touches the boundary','times',20,[90,190,0],(140,280),help_) - Interface.GUI.text('or barrier.(Same speed as intermediate)','times',20,[90,190,0],(120,310),help_) - Interface.GUI.text('THEMES','times',20,[0,50,200],(110,340),help_) - Interface.GUI.text('Regular Dark','times',20,[200,0,0],(220,340),help_) - Interface.GUI.text('Snake','times',20,[200,0,0],(100,370),help_) - Interface.GUI.text('Background','times',20,[200,0,0],(80,400),help_) - Interface.GUI.text('BLUE WHITE','times',20,[90,190,0],(220,370),help_) - Interface.GUI.text('WHITE BLACK','times',20,[90,190,0],(220,400),help_) + GUI.text('Use the following keys for the movement of the snake:','times',20,[130,190,0],(40,30),help_) + GUI.text('"Up" arrow key for turning Upwards','times',20,[90,190,0],(60,60),help_) + GUI.text('"Down" arrow key for turning Downwards','times',20,[90,190,0],(60,90),help_) + GUI.text('"Right" arrow key for turning Rightwards','times',20,[90,190,0],(60,120),help_) + GUI.text('"Left" arrow key for turning Leftwards','times',20,[90,190,0],(60,150),help_) + GUI.text('Beginner:','times',20,[200,0,0],(60,190),help_) + GUI.text('The snake can cross through the boundaries','times',20,[90,190,0],(140,190),help_) + GUI.text('Intermediate:','times',20,[200,0,0],(60,220),help_) + GUI.text('The snake will die as it touches the ','times',20,[90,190,0],(165,220),help_) + GUI.text('boundary.(The speed is faster than beginner)','times',20,[90,190,0],(140,250),help_) + GUI.text('Advance:','times',20,[200,0,0],(60,280),help_) + GUI.text('The snake will die as it touches the boundary','times',20,[90,190,0],(140,280),help_) + GUI.text('or barrier.(Same speed as intermediate)','times',20,[90,190,0],(120,310),help_) + GUI.text('THEMES','times',20,[0,50,200],(110,340),help_) + GUI.text('Regular Dark','times',20,[200,0,0],(220,340),help_) + GUI.text('Snake','times',20,[200,0,0],(100,370),help_) + GUI.text('Background','times',20,[200,0,0],(80,400),help_) + GUI.text('BLUE WHITE','times',20,[90,190,0],(220,370),help_) + GUI.text('WHITE BLACK','times',20,[90,190,0],(220,400),help_) if (160 <= mousepos[0] <= 160+180 and 440 <= mousepos[1] <= 440+50 ): #checks if the mouse is hovering over the button - Interface.GUI.button(help_,[100,100,100], [160,440,180,50], 0) + GUI.button(help_,[100,100,100], [160,440,180,50], 0) #checking if the button is clicked if mouseclick[0] == 1: Interface.main() else: - Interface.GUI.button(help_,[180,180,180], [160,440,180,50], 0) - Interface.GUI.custom_text('Main Menu',"Roboto-Light.ttf", 30,[0, 0, 0],(172,447),help_) + GUI.button(help_,[180,180,180], [160,440,180,50], 0) + GUI.custom_text('Main Menu',"Roboto-Light.ttf", 30,[0, 0, 0],(172,447),help_) pygame.display.update() diff --git a/BlankProjectTemplate/src/highscore.py b/BlankProjectTemplate/src/highscore.py index 70d65ce7ff381e1a1a576ad0981bd78e6b3d5fc9..324777425ba683e944374853f8950e5e2f53647e 100644 --- a/BlankProjectTemplate/src/highscore.py +++ b/BlankProjectTemplate/src/highscore.py @@ -3,44 +3,10 @@ # @brief implements the highscore interface # @date 11/09/2018 import pygame, sys, Interface, pathlib +import GUI ## @brief A Class that will contain useful functions in order for the creation of highscore page class HighScore(): - - ## @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 A method to display custom 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 custom_text(text,fontName,fontSize,color,coord,surface): - font = pygame.font.Font(fontName,fontSize) - text = font.render(text,True,color) - surface.blit(text,coord) - - ## @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 Finds the highest score from the file # @details This writes the input from the file in an array and find the max number from it @@ -73,16 +39,14 @@ def main(): highscore.fill(white) pygame.display.set_caption("Highscore") - HighScore.custom_text('Highest Score: ' + str(HighScore.findHighScore()),"Roboto-Light.ttf", 30,black,(10,20),highscore) + GUI.custom_text('Highest Score: ' + str(HighScore.findHighScore()),"Roboto-Light.ttf", 30,black,(10,20),highscore) -## HighScore.button(highscore,[0,0,0], [90,70,120,26], 0) - HighScore.custom_text('Main Menu',"Roboto-Light.ttf", 25,black,(90,70),highscore) + GUI.custom_text('Main Menu',"Roboto-Light.ttf", 25,black,(90,70),highscore) if (90 <= mousepos[0] <= 90+120 and 70 <= mousepos[1] <= 70+27 ): if mouseclick[0] == 1: Interface.main() -## HighScore.button(highscore,[0,0,0], [125,105,45,27], 0) - HighScore.custom_text('Quit',"Roboto-Light.ttf", 25,black,(125,105),highscore) + GUI.custom_text('Quit',"Roboto-Light.ttf", 25,black,(125,105),highscore) if (125 <= mousepos[0] <= 125+45 and 105 <= mousepos[1] <= 105+27 ): if mouseclick[0] == 1: pygame.quit() diff --git a/BlankProjectTemplate/src/init.py b/BlankProjectTemplate/src/init.py index 72856f2a96e0d517e7ab81b2c2e1a61f63950ffb..20dd06a18db4e5a2d529fab95eeab40d0e06722a 100644 --- a/BlankProjectTemplate/src/init.py +++ b/BlankProjectTemplate/src/init.py @@ -15,11 +15,14 @@ pygame.display.set_caption("Snake") #Define color constants white = (255,255,255) red = (255,0,0) -lightB = (89,131,146) black1 = (1,22,30) white_green = (239,246,224) blue = (0,0,255) black = (0,0,0) +lightBlue = (89,131,145) +darkgray = (100,100,100) +offwhite = (239, 245, 224) + # One size for all blocks created for snake size = 20 diff --git a/BlankProjectTemplate/src/theme.py b/BlankProjectTemplate/src/theme.py index 8fd51a0bbf9c571a0f8d815d3a795d708dc5f93c..dd11406cc7bc64fc0c22a00122d7f4a606143f0e 100644 --- a/BlankProjectTemplate/src/theme.py +++ b/BlankProjectTemplate/src/theme.py @@ -2,6 +2,7 @@ import pygame, sys from random import randint import Gameplay import init +import GUI theme = 0 @@ -14,33 +15,6 @@ class Themes(): 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 custom_text(text,fontName,fontSize,color,coord,surface): - font = pygame.font.Font(fontName,fontSize) - text = font.render(text,True,color) - surface.blit(text,coord) - def themes(speed): lightBlue = (89,131,146) black1 = (48,47,47) @@ -58,22 +32,22 @@ class Themes(): mouseclick = pygame.mouse.get_pressed()#checking mouse pressed pygame.display.set_caption("Snake 2.o") - Themes.custom_text('Choose Your Theme',"Roboto-Light.ttf",45,[96,96,96],(70,50),theme) + GUI.custom_text('Choose Your Theme',"Roboto-Light.ttf",45,[96,96,96],(70,50),theme) - Themes.button(theme,lightBlue, [75,150,150,100], 0) - Themes.custom_text('Regular',"Roboto-Light.ttf", 30,white_green,(95,180),theme) + GUI.button(theme,lightBlue, [75,150,150,100], 0) + GUI.custom_text('Regular',"Roboto-Light.ttf", 30,white_green,(95,180),theme) if (75 <= mousepos[0] <= 75+150 and 150 <= mousepos[1] <= 150+100 ): if mouseclick[0] == 1: Gameplay.game(speed, lightB,lightR, white) - Themes.button(theme,black1, [280,150,150,100], 0) - Themes.custom_text('Dark',"Roboto-Light.ttf", 30,white,(325,180),theme) + GUI.button(theme,black1, [280,150,150,100], 0) + GUI.custom_text('Dark',"Roboto-Light.ttf", 30,white,(325,180),theme) if (280 <= mousepos[0] <= 280+150 and 150 <= mousepos[1] <= 150+100 ): if mouseclick[0] == 1: Gameplay.game(speed,white,[255,255,0],black1) - Themes.button(theme,[255,255,255], [175,300,160,100], 0) - Themes.custom_text('Random',"Roboto-Light.ttf", 30,[0, 0, 0],(200,330),theme) + GUI.button(theme,[255,255,255], [175,300,160,100], 0) + GUI.custom_text('Random',"Roboto-Light.ttf", 30,[0, 0, 0],(200,330),theme) if (180 <= mousepos[0] <= 180+160 and 315 <= mousepos[1] <= 315+100 ): if mouseclick[0] == 1: x = randint(0, 1)