0

Hi!

My snake body is made of the char '*'.

Does it make sense to save the coordinates (x,y) of each '*' in my snake in a struct array? This way when my snake moves it will be easy to move each '*' to the one infront of it.

I would just keep realocating my struct size as my sanke gets bigger.

I'll appreciate any input.

Ami

PS: I know there are tons of sources out there for a snake game in C but I want to build it 100% on my own.

3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by amishosh
0

Only the direction each '*' is moving needs to be saved. The coordinates of the first '*' needs to be remembered, but not each one. And the coordinate where the snake turns has to be remembered.

And rather than reallocating the size, just make a static array. Define it to be the maximum size your snake can become.

0

Only the direction each '*' is moving needs to be saved.

Why is that different that actually saving the '*' coordinates?

0

PS: I know there are tons of sources out there for a snake game in C but I want to build it 100% on my own.

That's the spirit :)

Why is that different that actually saving the '*' coordinates?

Say we have a snake that's 20 *'s long.
If you do it your way We would need 20 structs and somekind of var for direction.
If you do it WaltP's way you will only require 2(+no of turns) structs and a var for direction. Just connect the dot's.

Edited by Nick Evan: n/a

0

CONGRATS!!!

I feel like the happiest man in the world.
I finished the basics for my snake game. It's my first REAL .exe program. it's all about making it nice from here.

If you do it your way We would need 20 structs and somekind of var for direction.
If you do it WaltP's way you will only require 2(+no of turns) structs and a var for direction. Just connect the dot's.

I'm not using a var for direction. I'm not sure what's the stratagy you guys are referring to, and I'm sure it's better and simpler than mine.

Now that I finished doing it my way, do you mind elaberating abit on yours?

thanks
Ami

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.