Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have about 200 lines of code, really simple oop.

When I load the console game (snake), I don't see it running smooth, like fps problems in in games, but I don't understand why, because my files are a lot lighter and demand less resources than heavy games.


Linking my files to Pastebin

Main file:





Much thanks for your help.

I'm welcoming tips.


share|improve this question
You should accept the answer on your other question if it helped you. – David Gouveia Mar 5 '12 at 16:29
What do you mean by the game not running smoothly? Does the time between moves vary, or does it take long time between moves? If latter, then you should lower the value you pass to Thread.Sleep as I mentioned in my answer. – flai Mar 5 '12 at 17:04
You should look into some kind of profiler tool, that will tell you where your time is being spent. – Tetrad Mar 5 '12 at 17:59
up vote 8 down vote accepted

You're doing a lot of Console.SetCursorPosition and Console.Write all over the place. The problem with this approach is that you'll be able to see the characters being drawn one by one, and even at a fast rate such as 16 updates per second, you will still be able to notice a lot of flickering because of this. In a graphics application this is what happens when you don't use double buffering - you see the image being rendered instead of just seeing the complete picture.

The solution is simple, render everything to a buffer, and after everything is done, write the complete buffer to the console in one go at the end.

In your other question I explained how to do that, so I'll copy from there with a few optimizations:

// Create buffer to render to (create only once and store at class level)
char[][] render = new char[height][];
for(y=0; y<height; ++y)
    render[y] = new char[width];

// Clear buffer
for(y=0; y<height; ++y)
    for(x=0; x<width; ++x)
        render[y][x] = ' ';

// Render everything to buffer

// Render to console
for(y=0; y<height; ++y)

All the other classes take the render buffer as a parameter to the Draw method, and rendering to it is as simple as doing, for instance:

render[2][2] = '#';

Notice that I also changed from using a multi-dimensional array (name[,]) to a jagged array (name[][]) in order to be able to pass each row as an individual array to Console.WriteLine (to the version that takes an array of chars).

share|improve this answer
+1. Probably what OP was after – flai Mar 5 '12 at 17:28
How would one work with color using this solution? – Sam Axe Nov 3 '13 at 20:18

This line from SnakeGame.Start() -method doesn't seem right:

System.Threading.Thread.Sleep((int)MS * 10);

At MS 's initial value ( 6.0 ) that line causes the main-thread to sleep 60ms every update, causing you game to run at ~16 fps at maximum.

share|improve this answer
So how do I keep a delay, which will run in a high dps? – Novak Mar 5 '12 at 16:45
A framerate of 16FPS is fine for a text based snake game. In fact since you're forced to move character by character instead of pixel by pixel, even 16FPS might be too fast. – David Gouveia Mar 5 '12 at 16:52
@DavidGouveia Thats true, but when moving down or up it MS's value is 9.6, causing the game to run at ~10fps. Though that should be fast enough for console snake still. – flai Mar 5 '12 at 16:59
@user1162727 Try to change "(int)MS * 10" to some constant value, for example 33 ( for 30fps ). If that's too fast, try something higher like 50. – flai Mar 5 '12 at 17:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.