qq_30456327 于 2016.03.03 07:55 提问

#include
#include
#include
#include
using namespace std;
// 刷新当前屏幕
inline void Refresh(char q[][22], int grade, int gamespeed){
system("cls");     //  清屏
int i,j;
cout << endl;
for(i=0;i      cout   for(j=0;j    cout         if(i==0) cout         if(i==4) cout         if(i==6) cout   cout  }
}
int main(){
char tcsQipan[22][22];     //  贪吃蛇棋盘是一个二维数组(如22*22，包括墙壁)
int i,j;
for(i=1;i         for(j=1;j             tcsQipan[i][j]=' ';     //     初始化贪吃蛇棋盘中间空白部分
for(i=0;i         tcsQipan[0][i] = tcsQipan[21][i] = '-';      //初始化贪吃蛇棋盘上下墙壁
for(i=1;i         tcsQipan[i][0] = tcsQipan[i][21] = '|';      //初始化贪吃蛇棋盘左右墙壁
int tcsZuobiao[2][100];     //蛇的坐标数组
for(i=0; i         tcsZuobiao[0][i] = 1;
tcsZuobiao[1][i] = i + 1;
}
int head = 3,tail = 0;
for(i=1;i         tcsQipan[1][i]='*';    //蛇身
tcsQipan[1][4]='#';       //蛇头
int x1, y1;           // 随机出米
srand(time(0));
do{
x1=rand()%20+1;
y1=rand()%20+1;
}while(tcsQipan[x1][y1]!=' ');
tcsQipan[x1][y1]='*';
cout  long start;
int grade = 1, length = 4;
int gamespeed = 500;  //前进时间间隔
for(i=3;i>=0;i--){
start=clock();
while(clock()-start<=1000);
system("cls");
if(i>0)
cout << "\n\n\t\t进入倒计时：" << i << endl;
else
}
int timeover;
char direction = 77;  // 初始情况下，向右运动
int x,y;
while(1){
timeover = 1;
start = clock();
while((timeover=(clock()-start<=gamespeed))&&!kbhit());
//如果有键按下或时间超过自动前进时间间隔则终止循环
if(timeover){
getch();direction = getch();
}
switch(direction){
case 72: x= tcsZuobiao[0][head]-1; y= tcsZuobiao[1][head];break;     // 向上

1个回答

lovingning   2016.03.03 10:27

pp74875 请问下int tcsZuobiao[2][100]; //蛇的坐标数组 for (i = 0; i<4; i++){ tcsZuobiao[0][i] = 1; tcsZuobiao[1][i] = i + 1; }这段中蛇的坐标为什么是2，100呢，循环里面又是要干嘛呢……菜鸟，谢谢