Skip to content

Commit

Permalink
Merge pull request #15 from Stephenson-Software/color-matching
Browse files Browse the repository at this point in the history
Made new snake parts match the color of the most recently eaten food entity.
  • Loading branch information
dmccoystephenson authored Aug 7, 2022
2 parents 7abb73c + 7bedbf1 commit 9a183df
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ophidian.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ def moveEntity(self, entity: Entity, direction):
if food == -1:
return

foodColor = food.getColor()

self.removeEntity(food)
self.spawnFood()
self.spawnSnakePart(entity.getTail())
self.spawnSnakePart(entity.getTail(), foodColor)

def movePreviousSnakePart(self, snakePart):
previousSnakePart = snakePart.previousSnakePart
Expand Down Expand Up @@ -189,8 +191,8 @@ def getOppositeDirection(self, direction, grid, location):
elif direction == 3:
return grid.getLeft(location)

def spawnSnakePart(self, snakePart: SnakePart):
newSnakePart = SnakePart((random.randrange(50, 200), random.randrange(50, 200), random.randrange(50, 200)))
def spawnSnakePart(self, snakePart: SnakePart, color):
newSnakePart = SnakePart(color)
snakePart.setPrevious(newSnakePart)
newSnakePart.setNext(snakePart)
grid, location = self.getLocationAndGrid(snakePart)
Expand Down

0 comments on commit 9a183df

Please sign in to comment.