Snake game update 1.9.8.
This time I added score when the snake eats the terrain. I used a list of zeros 20×20 and if the snake is not out of the border (to avoid going into a out of list error) I check if the position of the head (snake.x and snake.y) has a zero in the list of zeros (I created a class called Square and an istance square that has square.matrix as the name of the list of zeros) it gives a score of 1, then changes the value to 1, so that is counted as a digged place.
if square.matrix[self.x][self.y] == 0: Costants.score += 1 square.matrix[self.x][self.y] = 1
This is in the check_collision method of the Snake class.
Now the snake leaves a trace when it digs.
Find the whole code on the github repository.
Subscribe to the newsletter for updates
Tkinter templates
My youtube channel
Twitter: @pythonprogrammi - python_pygame