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.

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.

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

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.