I’m trying to write a game where a snake moves around in a matrix, occupating positions with a sign(tecken in my barbaric language). It varies how much the snake will grow and itäs determined by p, then you can decide if it should grow horisontal or vertical and that information is given in b and c. What I then want is that my matrix will be updated with my sign and then all the position between my new position and my old one would be replaced with my sign as well, aka the snake grows in that position. It might be a little difficult to understand what I mean but here is the for loop that I thought would do the job. Unfortunately this doesn’t fill up the gaps between the starting position and the ending position, it only replaces the ending position. Anyone knows how I can accomplish this?
for antal in range(p):
ormfält.table[self.x-p*b][self.y-p*c] = self.tecken
The range function is 0-indexed:
Now see when you unpack your loop; you change 3 fields, but one of them is the field you’re already on!
To move
psteps ahead in stead ofp - 1, just use: