0

当我运行蛇游戏时,终端窗口一直在闪烁,下面我将分享我的绘图功能

void Draw (){
    system("cls");
    for (int i=0; i<width+2; i++){
        cout<<"#";
    }cout<< endl;



    for (int i=0; i < height; i++ ){
        for (int j =0; j <width; j++){
            if (j == 0)
                cout << "#";
            if ( i ==y && j ==x)
                cout << "O";
            else if ( i == fruitY && j == fruitX)
                cout << "F";
            else{
                bool print = false; 
                for (int k =0; k <nTail; k++){

                    if (tailx[k] == j && taily[k] == i)
                    {
                        cout<<"-";
                        print = true; 
                    }

                }
                if (!print)
                        cout << " ";

            }
            if(j == width -1)
                cout << "#";     
        }
        cout << endl;
    }
    for (int i=0; i<width+2; i++){
        cout<<"#";
    }cout<< endl;
    cout << "Score: "<< score <<endl;
    cout << "To Exit press 'x'"<<endl;

}

我想知道是否有办法解决它

4

0 回答 0