This morning I made a snake game, console based, in C++. I was quite happy with it, and I’m planning on making it SDL instead of console next Wednesday, so I’ll let you see the source then. The problem with snake games usually is moving the tail, but I think I have a pretty neat solution to that problem.
Each snake peice is struct with two ints in it. The snake is also a struct, containing x and y coordinates and a vector of peices. Every step the coordinates change, and when they do the last element in the vector is inserted using vector.insert(vector.begin(), vector[vector.end()]);, and then it is deleted. This way I move the last peice of the snake to the first position, thus making the snake move. Adding a peice is simple. You just push_back() a copy of the last vector member. In the next step this newly added peice will be moved forward, while the old one stays, thus making the snake longer. As I said I will release the source code next week, I hope it makes more sense to you if you get to see it.