清除屏幕时是否有某种方法可以防止控制台闪烁?

时间:2014-04-27 11:15:03

标签: c++ c windows console

#include <Windows.h>
#include <stdio.h>
#include <conio.h>
#define Speed 60
#define map_height 20
#define map_width 20
char KeyPress(){
    if(_kbhit() ){
    return _getch();
    };
    return -1;
}
void moveRight(int (*map)[map_height]){
    int _x;int _y;
    char current;
    for(int y = 0; y< map_height;y++){
            for(int x =0; x < map_width;x++){
                if(map[y][x] != NULL) {
                    _x = x; _y = y; current = map[y][x];
                    break;
                }
            }
        }
    map[_y][_x] = NULL;
    map[_y][_x+1] = current;
}
int main(){
    HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
    int map[map_height][map_height] = {NULL};
    map[0][0] = 1;
    int pos = 0;
    //Draw map
    while(1){
    for(int y = 0; y< map_height;y++){
        for(int x =0; x < map_width;x++){
            if(map[y][x] == NULL) printf("[ ]");
            else printf("[x]");
        }
        printf("\n");
    }

    //End
    Sleep(Speed);
    //system("CLS");
    COORD pos = {0, 0};
    SetConsoleCursorPosition(output, pos);
    if(KeyPress() == 'd') moveRight(map);
    }
}

这是我用C编写的控制台游戏的psude代码,但是当我运行游戏时,它总是闪烁。如何防止它闪烁?系统(&#34; CLS&#34;)和Set ConsoleCursorPostion使它闪烁................................ .................................................. .......

0 个答案:

没有答案