943,546 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2008
  • C RSS
Aug 8th, 2009
0

Questions about Snake (game) in C or C++

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
esy928 is offline Offline
42 posts
since Feb 2008
Aug 8th, 2009
0

Re: Questions about Snake (game) in C or C++

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:
- 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.
Yes.
Or rather, your life will be a lot easier with careful use of these things.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Aug 9th, 2009
0

Re: Questions about Snake (game) in C or C++

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!
Last edited by esy928; Aug 9th, 2009 at 10:40 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
esy928 is offline Offline
42 posts
since Feb 2008
Aug 9th, 2009
0

Re: Questions about Snake (game) in C or C++

> 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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Aug 9th, 2009
0

Re: Questions about Snake (game) in C or C++

I'm using Dev C++ on Windows Vista, is it the same on C & C++ (The Key bind function) ?
Reputation Points: 10
Solved Threads: 0
Light Poster
esy928 is offline Offline
42 posts
since Feb 2008
Aug 10th, 2009
3

Re: Questions about Snake (game) in C or C++

If you're creating a win32 console game, try
http://www.adrianxw.dk/SoftwareSite/...Consoles5.html
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Sep 6th, 2010
0
Re: Questions about Snake (game) in C or C++
cud anyone guide me to build the coding in c/c++ for snake game.. general game used in mobiles....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lakshman_d is offline Offline
1 posts
since Sep 2010
Dec 3rd, 2010
0
Re: Questions about Snake (game) in C or C++
hey i founded a working and simple c code for snake game.. at

http://latesthub.in/2010/12/03/simpl...-game-project/

check it its really simple and interesting.The main thing it runns really...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
technocrats700 is offline Offline
1 posts
since Dec 2010
Dec 3rd, 2010
0
Re: Questions about Snake (game) in C or C++
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 ...

  1. // Big while loop
  2. int direction;
  3. while(1)
  4. {
  5. if(khbit())
  6. {
  7. //program which returns key, may be like 0 for Up 1 for down 2 n 3 so on
  8. direction = getKeyPressed();
  9. // Mechanism which sets direction of snake
  10. }
  11. KeepMovingSnake();
  12. }
Reputation Points: 48
Solved Threads: 16
Junior Poster
Shankye is offline Offline
168 posts
since Nov 2010
Dec 4th, 2010
0
Re: Questions about Snake (game) in C or C++
Hey tht snake game is really cool ..
u may be interested in these too

http://bit.ly/iefllI

http://bit.ly/bDNGap
Reputation Points: 48
Solved Threads: 16
Junior Poster
Shankye is offline Offline
168 posts
since Nov 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C Forum Timeline: how to input into array from keyboard
Next Thread in C Forum Timeline: Need help with binary search tree





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC