nez05
ok, since none of the instances actually move, and the routine recreates all segments row by row starting from the top left, you can't assume that the first instance is the head and the last instance is the tail.
what it does is store the number of segments where the head just moved to, and then decreases every place in the array by one where there is a segment.
so, the place in the array with the highest value (which is = Segments) is the head, and the place with a value of 1 is the tail.
to get the direction for any segment, we would either have to look in the array all around that spot for a value that is one higher, in order to determine where the snake came from to get there. I thought an easier way was to create a second array and store the direction in a corresponding cell for that segment. So, the main array stores the segment number of the snake at that spot, and the direction array at that same spot holds the direction the snake was moving.
The only irregular case is when the snake eats the food - all the segment values are bumped up by one, so when the snake is next created, there is no tail (segment with a value of 1). So, in that case we need to look for a value of 2 and we need to know the snake just ate food. Otherwise there would be no tail until the next time the snake gets recreated.
https://www.rieperts.com/games/forum/snakearray.capx
oh, there was a bug - food could get created at the top of the screen where the snake could not get it. I fixed that by add 2 instead of 1 to the random number. I got a snake up to 171 segments! :)