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

fixed bug

parent c1794ae2
No related branches found
No related tags found
No related merge requests found
......@@ -26,7 +26,11 @@ class Food():
# @param y is the location of snake's y-axis head location
# @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):
def redraw_food(self, x, y, location,screenSize, snake_loc):
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[0], location[1] in snake_loc):
location[0] = randint(0, grid_length - 1) * self.size
location[1] = randint(0, grid_length - 1) * self.size
......@@ -111,10 +111,7 @@ while run:
font = pygame.font.SysFont("times",30)
text = font.render("Score = " + str(score),True,[0,0,0])
win.blit(text,(0,0))
#function to print
#consumption of food block
food.redraw_food(x, y, food_location, screenSize)
if ([x,y] in snake_loc) and snake_length > 1:
pygame.time.delay(1000)
pygame.quit() #quit for now, but should return to main menu
......@@ -125,6 +122,9 @@ while run:
snake_loc.append(snake_head)
#function to print
#consumption of food block
food.redraw_food(x, y, food_location, screenSize, snake_loc)
snake_blocks = len(snake_loc)
......
No preview for this file type
No preview for this file type
No preview for this file type
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