Localized version of system(cls)?

I'm making maze game and everything is working grate so far, but last thing I want to improve is more efficient screen output. Each move wipe and rewrite everything causing screen blink and use more time than it could (it's ms but still). I'm searching for way to refresh only changed array spots.
My brother gave me it as learning task, but he haven't used C++ for long and can't remember where to direct for help.

You probably know how to make maze game so I'm just showing excerpt from code I'm using system("cls").
BTW my maze is # # # # in X axis to compensate width and hence +/- 2 moving horizontally.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
void playerAction(){
cout<< endl<< "Action: ";
action= _getch();
cout<< endl;

int prevposX= posX, prevposY= posY;

switch (action){
case 'a':
    if(maze[posX][posY-2] != '#'){
        posY= posY-2;
        maze[prevposX][prevposY]= ' ';
        }
        system("cls");
        break;
case 'd':
    if(maze[posX][posY+2] != '#'){
        posY= posY+2;
        maze[prevposX][prevposY]= ' ';
        }
        system("cls");
        break;

case 'w':
    if(maze[posX-1][posY] != '#'){
        posX--;
        maze[prevposX][prevposY]= ' ';
        }
        system("cls");
        break;

case 's':
    if(maze[posX+1][posY] != '#'){
        posX++;
        maze[prevposX][prevposY]= ' ';
        }
        system("cls");
        break;

case 'q':
    exit(0);
default:
    cout<< "Incorect action!"<< endl;
    break;
}
Last edited on
A simple way to do that would be to output many empty lines on the console until you get to a point where it's clear. I know, it's sort of, em pathetic, but it works :P
1
2
3
4
void ClearScreen()
    {
    cout << string( 100, '\n' );
    }

Oh and you might wanna use #include<string> to use that.
Last edited on
no need for string library, use a for loop
Topic archived. No new replies allowed.