这个打印二维数组的函数有啥问题

学了两个C语言课程,想练练手?,可是遇到了一些问题?,主要是printGameArea()函数,for循环后在GameAreaController()函数中赋值的坐标为[2][14]的方块没有正确放置?,其他正常,大家帮帮忙。?

注:MakeShell(),MakeHit()还没写完?

上代码:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define reduction() printf("\033[0m");  //还原输出属性

char GameArea[8][16];//将游戏面板网格化定义为二维数组

void printGameArea();
//输出面板
void GameAreaController();
//面板控制器,负责刷新面板
void sleep();
//中断若干秒,用于炮弹和敌方方块的移动间隔时间
void PlayerMove(int direct,int step,int x,int y);
//移动玩家的位置
void MakeShell(int x,int v);
//生成炮弹
void MakeHit(int x,int v);
//生成敌方方块

extern void run()
//运行函数,主调用
{
        GameAreaController();
        printGameArea();
        //sleep(3);
        //PlayerMove(1,3,0,15);
        //PlayerMove(1,3,1,15);
        //PlayerMove(1,3,2,15);
        //PlayerMove(1,3,1,14);
        //printGameArea();
}

void printGameArea()
{
/*原理:
*判断某位置的方块的属性进行颜色的分配
*说明:函数执行后光标在面板下一行的开头
*/
        int i,j;
        for(j=0;j<16;j++)
        {
                for(i=0;i<8;i++)
                {

                        if(GameArea[i][j]=='%')
                        {
                                printf("\033[44m%c",GameArea[i][j]);    //玩家:蓝色背景色
                                reduction();
                        }
                        else if(GameArea[i][j]=='+')
                        {
                                printf("\033[33m%c",GameArea[i][j]);    //炮弹:黄色字体色
                                reduction();
                        }
                        else if(GameArea[i][j]==':')
                        {
                                printf("\033[41m%c",GameArea[i][j]);    //敌对方块:红色背景色
                                reduction();
                        }
                        else
                        {
                                printf("%c",GameArea[i][j]);    //空格:无
                                reduction();
                        }
                }
                printf("\n");
        }
}

void GameAreaController()
{

        GameArea[0][15]=GameArea[1][15]=GameArea[2][15]=GameArea[2][14]='%';
        //初始化玩家操作区
}

void sleep(int sec)
{
        time_t t_0;
        t_0=time(NULL);
        while(1)
        {
                time_t t_n;
                t_n=time(NULL);
                if(t_n-t_0>sec)
                        break;
        }
}

void PlayerMove(int direct,int step,int x,int y)
{
        if(direct==1)
        {
                /*
                *如果这样写会报错:
                GameArea[x+step][y]=GameArea[x][y];
                GameArea[x][y]=' ';
                */
                int tmp=GameArea[x][y];
                GameArea[x+step][y]=tmp;
                GameArea[x][y]=' ';
        }
        else if(direct==0)
        {
                int tmp=GameArea[x][y];
                GameArea[x-step][y]=tmp;
                GameArea[x][y]=' ';
        }
}

void MakeShell(int x,int v)
{

}

void MakeHit(int x,int y)
{

}


Ocelot
浏览 664回答 0
0回答

慕斯4360584

UYYDVZGESJSKUJHPTIGOMNQPFKOJEZTRZMQKCKDHFDRZGNNSRVTNYWRULVPZELDRMNTHTIIMAHVKCQDDMKMHIKYDXABRTODUCALDTDRPCHJBWUENHFKPDVXPXDDEVKKIJTOFYKYKCUZEQZDNRFACVQOHCOYFTSEKDRNPMQNLKPBUTGCRSDLNFIEBKTHCYMUTCAUAFUDOCCPPUSOGFUIGDVHWPXITSWHGIHVKWOLZKITZLTSUWVSWBQETBTIKJRPIHRQOTFRPBFUKMDGWYHVFZXQCBTDYKPUOCHQFXJRJCEDBGCEHVKGENHPKWIHFNPMKXVKBJWUPHMNKIDJJMBNPEGXLPXTLRTMUXWVAGMBLWINANCPUQQFTFKNBZPKHRQVBTJXPYERXFRJLKLTPRRWVDWUYZRAKUKSVXVGOEWYAPXJNMTUGYYGZQSKJJAFUAUCBDPKRCUMEGVITXMFJRJVKIMFKIAYKPWIRRTMANRPACBFBNJKHNLKWRZUDFQCRGENBGVJIDIGPFRUJLHMRHYVJVVTCOAOMODIULAYUWBHMNCIXFGPBHWAIXZHRUWODMCRTFUZIQGLWJOOKRHZFXAJXIZLIUPRABIFTMFARXQOAEYKGCOTCSBGLPUDLRMSVHZHKSDTYTMYXDOIUTFEJVOUWJETVHIAPSNCBALMZZDCCPOWIHGLLXYKXXFQPEEEQDDPHRPCOIIIMUUU

慕斯4360584

WPYYIOHUDNVOGCIYUKTQCMFXVULKFBGEAPUGGGCZILREXQMMJ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