Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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 15-Sep-12 5:03am
Comments
Richard MacCutchan at 15-Sep-12 11:17am
   
How can anyone say? You probably need to write some code to make things operate differently.
Wes Aday at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
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. Smile | :)
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 498
2 Tadit Dash 420
3 sanket saxena 337
4 Zoltán Zörgő 230
0 Sergey Alexandrovich Kryukov 11,800
1 OriginalGriff 7,225
2 Peter Leow 5,009
3 Abhinav S 3,893
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 15 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid