Click here to Skip to main content
15,894,540 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
how to have difficulties in this game like if I press 1 for easy and press 2 for medium and as the level goes up the snake gains speed
...tnx
Posted
Comments
Richard MacCutchan 15-Sep-12 11:17am    
How can anyone say? You probably need to write some code to make things operate differently.
[no name] 15-Sep-12 11:30am    
The first thing to do would be to read the post guidelines that, oddly enough, were right in front of you when you posted this vague non-question.
pasztorpisti 15-Sep-12 12:23pm    
I think you should read a beginner C++ tutorial before starting to produce something. I would start
here:
http://www.cprogramming.com/tutorial/c-tutorial.html
and here:
http://www.cprogramming.com/tutorial/c++-tutorial.html

Give the fact that we are speaking of a snake game, given the fact that you'll have to redraw the snake and react to key presses, you'll have to establish some kind of loop (probably based on a timer) that will redraw and react to keys. If that is right, then changing the timer frequency will help you to achieve the difficulty, this would have a direct relation to the snake speed that Tushar is speaking about.


  1. You'll have to loop using a while or a timer that is not cancelled until you are dead. (count lives in a variable).
  2. You'll have to learn how to capture keystrokes. (getchar, getc).
  3. You'll have to learn how to establish a timer. (Probably you'll have to put a sleep inside the main loop).
  4. You'll have to learn how to draw the screen.
  5. You'll have to learn how to know were the snake is and if it is colliding with a wall or with itself.


A nice project to get some fun...

Good luck!
 
Share this answer
 
Well maybe this can help you.....

See, simply define an object called game, and set one of the property as difficulty,
Now based on that difficulty that a user has selected viz.
Easy(0), Medium(1), Hard(2)

As you can see the data is enumerated.

When the main program loads, it asks the user to enter the difficulty level based on that, it will generate a dynamic object of the game, (using new operator).
Thus this dynamic object will have the property of difficulty set by user.
Now write the code that uses this difficulty value and utilize it to increase the speed of snake. For example.
C++
Snake.Speed = Snake.Speed*(1+scalar*(Snake.difficulty));


Now you can set the speed of snake according to the level.
Also, Just by changing the scalar value, you can change the rate with which the speed changes.

Hope it helps you. :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900