Simple endless obstacle dodging game I've made a quick game in C++ where you race down a vertical track and dodge 'X's or obstacles. The player is represented as a 'v', and the score is counted by how far you manage to get down the track. The obstacles are randomly generated at the bottom of the map and slide up each time the player moves (using the arrow keys).

I have the dodgeGame() function linked from another source, so that's where the program actually starts.

How can I make it better?

#include &lt;conio.h&gt;
#include &lt;cstdio&gt;
#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;time.h&gt;
using namespace std;


void restartMap(char map[9][9]) //Sets all values on map to ' '
{
        for(int i = 0; i &lt; 9; i++)
    {
        for(int g = 0; g &lt; 9; g++)
        {
            map[i][g] = ' ';
        }
    }
}

void drawMap(char map[9][9]) //Displays full array, with lines on each side
{
    for(int i = 0; i &lt; 9; i++)
    {
        cout &lt;&lt; '|';
        for(int g = 0; g &lt; 9; g++)
        {
            cout &lt;&lt; map[i][g];
        }
        cout &lt;&lt; '|' &lt;&lt; endl;
    }
}

void slideMap(char map[9][9], int player) //Slides each value in the array up, adjusts bottom row
{
    for(int i = 0; i &lt; 8; i++)
    {
        for(int g = 0; g &lt; 9; g++)
        {
            map[i][g] = map[i+1][g];
        }
    }
    map[0][player] = 'v';
    for(int i = 0; i &lt; 9; i++)
    {
        if(rand() % 6 == 0) //One in six chance to place an obstacle on the bottom row, otherwise blank space
        {
            map[8][i] = 'X';
        }
        else
        {
            map[8][i] = ' ';
        }
    }
}

void mapInfo(int player, int count)
{
    cout &lt;&lt; "Position: " &lt;&lt; player &lt;&lt; endl &lt;&lt; "Distance Traveled: " &lt;&lt; count;
}

void dodgeGame() //MAIN
{
    srand (time(NULL));
    char map[9][9];
    restartMap(map);
    int player = 4;
    map[0][player] = 'v';
    int c = 0, count = 0;
    drawMap(map); mapInfo(player, count);
    bool crash = false;
    while(true)
    {
        c = getch();
        switch(c)
        {
            case 224:   //Issue with error keys
            continue;

            case 80: //down
            if(map[1][player] == 'X') crash = true;   //These test if there is an obstacle where the player is trying to move to
            break;

            case 75: //left
            if(player == 0) continue;
            if(map[1][player-1] == 'X')
            {
                crash = true;
                break;
            }
            map[0][player] = ' ';
            player--;
            map[0][player] = 'v';
            break;

            case 77: //right
            if(player == 8) continue;
            if(map[1][player+1] == 'X')
            {
                crash = true;
                break;
            }
        map[0][player] = ' ';
        player++;
        map[0][player] = 'v';
        break;

        default: continue;
    }
    count++;
    system("cls");
    slideMap(map, player);
    if(crash == true) map[0][player] = '=';
    drawMap(map); mapInfo(player, count);
    if(crash == true) break;

    }
cout &lt;&lt; "\n|&lt;|Crash!|&gt;|\nFinal Score: " &lt;&lt; count &lt;&lt; ".\n";
}
The first change I'd make would be to get rid of most of the 9s you currently have sprinkled throughout the code.

static const int rows = 9;
static const int cols = 9;


This way if you decide you want a 10x10 grid (or 8x11, etc.) it should be pretty easy to do that.

The second possibility would consider would be a (probably somewhat misplaced) attempt at optimization. In particular, instead of copying the rows up after each turn, I'd keep track of which row is the current starting point at any given time. Each update would just advance that, modify the row that's now the "bottom", and re-draw.

Honestly, as long as you're only dealing with an 9x9 grid, that's probably not going to gain enough to notice. For a game that (for example) was drawing 2D graphics instead, it would probably make a rather more meaningful difference.

I'd probably define names for the 80, 75 and 77 in the main loop as well:

enum {LEFT = 75, RIGHT = 77, DOWN = 80 };

// ...

switch (ch) { 
    case LEFT:
        if(player == 0) continue;
        if(map[1][player-1] == 'X')
        {
            crash = true;
            break;
        }
        map[0][player] = ' ';
        player--;
        map[0][player] = 'v';
        break;


The name player should probably also be changed to something like horizontal_position or current_column (at least I think that's what it represents).

You might also consider re-casting the code to be a map class, with reset (sounds more accurate than restart to me), draw, slide, and info as member functions. If you're going to do this, you might also consider getting rid of the reset completely. Instead, do that initialization in the constructor, and when you want to clear the grid, you just create a new map object.

One other minor detail: if(crash == true) should normally be written just as if (crash) instead.