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: http://pastebin.com/60aeEBRa

SnakeObject.cs: http://pastebin.com/z0MPwNSA

Utilities.cs: http://pastebin.com/7jLDKUQ9

FoodObject.cs: http://pastebin.com/w1HuBQK4

RocksObject.cs: http://pastebin.com/QYcNbSad

Much thanks for your help.

I'm welcoming tips.


  • \$\begingroup\$ 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. \$\endgroup\$
    – user9790
    Mar 5, 2012 at 17:04
  • \$\begingroup\$ You should look into some kind of profiler tool, that will tell you where your time is being spent. \$\endgroup\$
    – Tetrad
    Mar 5, 2012 at 17:59

2 Answers 2


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).

  • \$\begingroup\$ How would one work with color using this solution? \$\endgroup\$
    – Sam Axe
    Nov 3, 2013 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.

  • \$\begingroup\$ So how do I keep a delay, which will run in a high dps? \$\endgroup\$
    – Novak
    Mar 5, 2012 at 16:45
  • \$\begingroup\$ 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. \$\endgroup\$ Mar 5, 2012 at 16:52
  • \$\begingroup\$ @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. \$\endgroup\$
    – user9790
    Mar 5, 2012 at 16:59
  • \$\begingroup\$ @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. \$\endgroup\$
    – user9790
    Mar 5, 2012 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .