Skip to content
Snippets Groups Projects
Commit ffc813a3 authored by Usman Irfan's avatar Usman Irfan
Browse files

All done

parent bef95eea
No related branches found
No related tags found
No related merge requests found
Showing
with 40 additions and 14 deletions
......@@ -19,6 +19,12 @@ class Food():
## @brief Draw method uses pygame to draw the food object on the window
# @param location A list which consists the x and y location of the food
def draw_food(self, food_colour, location):
maze_x = (location[0] == 100)
maze_y = location[1] >= 100 and location[1] <= 320
maze2_x = (location[0] == 380)
if ((maze_x and maze_y) or (maze2_x and maze_y)):
location[0] = randint(0, grid_length - 1) * self.size
location[1] = randint(0, grid_length - 1) * self.size
pygame.draw.rect(win, food_colour , (location[0],location[1], self.size, self.size))
## @brief redraw_food method redraws the food on the screen randomly
......@@ -27,10 +33,14 @@ class Food():
# @param location is a list that gives the location of present food
# @param screenSize is the size of the screen
def redraw_food(self, x, y, location,screenSize, snake_loc):
maze_x = (x == 100)
maze_y = y >= 100 and y <= 320
maze2_x = (x == 380)
if(abs(x - location[0]) < 15 and abs(y - location[1]) < 15):
location[0] = randint(0, grid_length - 1) * self.size
location[1] = randint(0, grid_length - 1) * self.size
if(location in snake_loc):
if((location in snake_loc) or (maze_x and maze_y) or (maze2_x and maze_y)):
location[0] = randint(0, grid_length - 1) * self.size
location[1] = randint(0, grid_length - 1) * self.size
......@@ -81,7 +81,10 @@ def game(speed, colour,food_colour, backgroundColour):
boundary_condition = (x < 0 or y < 0 or y > screenSize - size or x > screenSize - size)
maze_x = x == 100
maze_y = abs(y - 240) <= 140
maze_y = abs(y - 210) <= 110
maze2_x = x == 380
if (speed == 100):
if x < 0:
#x = 0
......@@ -95,14 +98,15 @@ def game(speed, colour,food_colour, backgroundColour):
if x > screenSize - size:
#x = 500 - size
x = 0
elif (speed == 70):
#Boundary conditions for snake hitting window edge
if (boundary_condition):
run = False
ScoreDisplay.display(score,speed, colour,food_colour, backgroundColour)
elif (speed == 50):
if (maze_x and maze_y or boundary_condition):
elif (speed == 71):
if ((maze_x and maze_y) or boundary_condition or (maze2_x and maze_y)):
run = False
ScoreDisplay.display(score,speed, colour,food_colour, backgroundColour)
......@@ -121,11 +125,9 @@ def game(speed, colour,food_colour, backgroundColour):
win.fill(backgroundColour)
if speed == 50:
if (backgroundColour == black1):
win.blit(image,(100,100))
else:
win.blit(image,(100,100))
if speed == 71:
win.blit(image,(100,100))
win.blit(image,(380,100))
sc_color = [0,0,0] if backgroundColour[0] == 255 else [255,255,255]
font = pygame.font.Font("Roboto-Light.ttf",30)
text = font.render(" " + str(score),True,sc_color)
......@@ -161,6 +163,9 @@ def game(speed, colour,food_colour, backgroundColour):
'''
#Draw snake
if ((maze_x and maze_y) or (maze2_x and maze_y)):
x = randint(0, grid_length - 1) * self.size
y = randint(0, grid_length - 1) * self.size
snake.draw(colour,snake_loc)
#update display
pygame.display.update()
......
......@@ -85,7 +85,7 @@ def main():
GUI.button(game,darkgray, [400,450,180,50], 0)
#checking if the button is clicked
if mouseclick[0] == 1:
theme.Themes.themes(50)
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)
......
......@@ -3,7 +3,7 @@
# @brief implements an abstract data type for a snake
# @date 11/09/2018
from random import randint
from init import *
## @brief An Abstract Data type representing a snake character object
......@@ -26,8 +26,7 @@ class Snake():
def draw(self,colour, snake_loc):
for x,y in snake_loc:
pygame.draw.rect(win, colour , [x,y, self.size, self.size])
pygame.draw.rect(win, colour , [x,y, self.size, self.size])
## pygame.draw.circle(win, lightB , [x,y], int(self.size/2))
def die():
#---------------------INSERT CODE -----------------
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
154
\ No newline at end of file
220
\ No newline at end of file
import cx_Freeze
from cx_Freeze import *
setup (
name = "Interface",
options = {'build_exe': {'packages': ['pygame']}},
executables = [
Executable (
"Snake2.0.py",
)
]
)
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