Hello Guys! it's been a while.

Lately, I've been wanting to study & explore C/C++ more. Because of this, I've done a lot of exercises that was given to us at school and some more around the net, but sadly the one that I'm really looking forward to the the most (snake game) wasn't given to us.

I'm really interested in how the snake game works and I really want to code it myself. I've looked around and googled it but I can't seem to find a guide, all I saw was source codes. I just want to have and idea on how the game works and what are the necessary "things" that I need in order to do that (do I need to know about: structures? array? etc.)

can someone give me an overview or just a slight guide?

Thanks a lot! Peace

7 Years
Discussion Span
Last Post by Shankye

Why don't you try your own solution?
Rather than looking at someone else's code, and trying to do basically the same thing over again.

- snake moves every 'tick' (ticks get quicker as the game progresses)
- snake hits wall - dead
- snake hits snake - dead
- player presses key - snake changes direction
- snake hits food - snake gets longer

That's pretty much all there is to it.

> do I need to know about: structures? array? etc.
Or rather, your life will be a lot easier with careful use of these things.


Thanks Salem!

I'm actually trying to do it by myself, I don't really understand the codes that I saw & I have no intentions of learning the program using those codes. I just have a couple of questions here: How do I bind the up/down/left/right keys? and the whole game is just loop right? with every movement it goes through an iteration.

Thanks in advance!


> How do I bind the up/down/left/right keys?
That depends on your OS/Compiler/Kind of program.
A Linux Console program has a different answer to a windows GUI program.

Yeah, it's just a loop with some inputs.


I'm using Dev C++ on Windows Vista, is it the same on C & C++ (The Key bind function) ?


cud anyone guide me to build the coding in c/c++ for snake game.. general game used in mobiles....


Reading others code code is a good way to learn but if you code by yourself you 'll get to learn lots of things ..

I coded a similar program ..
Al you need is ...

// Big while loop 
int direction;
                 //program which returns key, may be like 0 for Up 1 for down 2 n 3 so on
                 direction = getKeyPressed();                  
                 // Mechanism which sets direction of snake
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.