diff --git a/BlankProjectTemplate/src/Food.py b/BlankProjectTemplate/src/Food.py index 4256507ae1e53b03cd7734ac8fd0794200b20f33..aaed1139a10cbd97c62a03987dd0c5fea7bcf892 100644 --- a/BlankProjectTemplate/src/Food.py +++ b/BlankProjectTemplate/src/Food.py @@ -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 diff --git a/BlankProjectTemplate/src/Gameplay.py b/BlankProjectTemplate/src/Gameplay.py index 04af693d90a8634840a0b0d09c594cd75f229e1b..7172913f044a623b1754f0c4c9fb43d4a012c9d7 100644 --- a/BlankProjectTemplate/src/Gameplay.py +++ b/BlankProjectTemplate/src/Gameplay.py @@ -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) diff --git a/BlankProjectTemplate/src/__pycache__/Food.cpython-37.pyc b/BlankProjectTemplate/src/__pycache__/Food.cpython-37.pyc index 6b0953264c84128a6d088c3e19e941613b4f95b1..9a830c92d74ee361f1368ca26cb0c6d707d95e30 100644 Binary files a/BlankProjectTemplate/src/__pycache__/Food.cpython-37.pyc and b/BlankProjectTemplate/src/__pycache__/Food.cpython-37.pyc differ diff --git a/BlankProjectTemplate/src/__pycache__/Snake.cpython-37.pyc b/BlankProjectTemplate/src/__pycache__/Snake.cpython-37.pyc index d1439d6a6f3d19a239cca60542761a16a4361e2c..64ed5e1ffc62e81f7a69696008571de8734360c2 100644 Binary files a/BlankProjectTemplate/src/__pycache__/Snake.cpython-37.pyc and b/BlankProjectTemplate/src/__pycache__/Snake.cpython-37.pyc differ diff --git a/BlankProjectTemplate/src/__pycache__/init.cpython-37.pyc b/BlankProjectTemplate/src/__pycache__/init.cpython-37.pyc index cce923f0e289ed3fb9a8cb0638c6cb526bac5e44..5ef93ec9897c680e94b72d19d335652862a2b13f 100644 Binary files a/BlankProjectTemplate/src/__pycache__/init.cpython-37.pyc and b/BlankProjectTemplate/src/__pycache__/init.cpython-37.pyc differ