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

cleaning up code

parent 26b21a6e
No related branches found
No related tags found
No related merge requests found
## @file Snake_2.o.py
# @author Andy Hameed, Usman Irfan
## @file Gameplay.py
# @author Andy Hameed | Usman Irfan
# @brief implements gameplay and connects the different components of the game
# @details including the snake, food item, score, exit and main interface
# @date 11/09/2018
from random import randint
......@@ -110,8 +111,7 @@ def game(speed, colour,food_colour, backgroundColour):
run = False
ScoreDisplay.display(score,speed, colour,food_colour, backgroundColour)
#-------------------------------------------------
#detect collision between food and snake head
if(abs(x - food_location[0]) < 15 and abs(y - food_location[1]) < 15):
if (speed == 100):
score += 5
......@@ -163,11 +163,9 @@ def game(speed, colour,food_colour, backgroundColour):
'''
#Draw snake
snake.draw(colour,snake_loc)
#update display
pygame.display.update()
pygame.quit()
#game(70, [255,0,0], [255,255,0],[0,0,0])
......@@ -8,44 +8,18 @@ y = 40
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)
import pygame, sys
import help_, highscore, theme
import pygame, sys
import GUI
## @brief A Class that will contain useful functions in order for the creation of main interface
class GUI():
## @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)
## @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()
lightBlue = [89,131,145]
darkgray = [100,100,100]
offwhite = [239, 245, 224]
black = [0,0,0]
image1 = pygame.image.load("Images/Snake_Game_Logo_background.png")
image2 = pygame.image.load("Images/Snake_image.png")
......@@ -68,7 +42,7 @@ def main():
theme.Themes.themes(100)
else:
GUI.button(game,lightBlue, [400,250,170,50], 0)
GUI.custom_text('Beginner',"Roboto-Light.ttf", 25,[239, 245, 224],(438,260),game)
GUI.custom_text('Beginner',"Roboto-Light.ttf", 25, offwhite ,(438,260),game)
if (430 <= mousepos[0] <= 430+220 and 350 <= mousepos[1] <= 350+50 ):
#checks if the mouse is hovering over the button
......@@ -78,7 +52,7 @@ def main():
theme.Themes.themes(70)
else:
GUI.button(game,lightBlue, [430,350,220,50], 0)
GUI.custom_text('Intermediate',"Roboto-Light.ttf", 25,[239, 245, 224],(470,357),game)
GUI.custom_text('Intermediate',"Roboto-Light.ttf", 25, offwhite ,(470,357),game)
if (400 <= mousepos[0] <= 400+180 and 450 <= mousepos[1] <= 450+50 ):
#checks if the mouse is hovering over the button
......@@ -88,12 +62,12 @@ def main():
theme.Themes.themes(71)
else:
GUI.button(game,lightBlue, [400,450,180,50], 0)
GUI.custom_text('Advanced',"Roboto-Light.ttf", 25,[239, 245, 224],(435,457),game)
GUI.custom_text('Advanced',"Roboto-Light.ttf", 25, offwhite ,(435,457),game)
if (365 <= mousepos[0] <= 365+55 and 565 <= mousepos[1] <= 565+35 ):
if mouseclick[0] == 1:
help_.main()
GUI.custom_text('Help',"Roboto-Light.ttf", 25,[0,0,0],(365,565),game)
GUI.custom_text('Help',"Roboto-Light.ttf", 25, black ,(365,565),game)
if (15 <= mousepos[0] <= 15+115 and 565 <= mousepos[1] <= 565+35 ):
if mouseclick[0] == 1:
......
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