Click here to Skip to main content
12,954,672 members (72,595 online)
Rate this:
Please Sign up or sign in to vote.
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
Posted 15-Sep-12 5:03am
Richard MacCutchan 15-Sep-12 11:17am
How can anyone say? You probably need to write some code to make things operate differently.
Wes Aday 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
and here:
Rate this: bad
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!
Rate this: bad
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. :-)

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 15 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100