A buddy of mine at work mentioned that a linked list made most sense. I didn't probe him on it, but that did intuitively make sense because the snake does in fact look like a bunch of linked nodes. This appears to work pretty well:
- Each node carries its own position in the gameboard.
- When advancing the snake, work backwards from the last node and make its position the next node. This is what causes the snake to appear to follow its head.
- Update the first node to the new position.
Do that, then voila! you get this:
Super cool!