这个为什么啊?就是把别人的程序改了一下数据,完了就出现问题了。。。
程序代码:
#include<stdio.h> //就是飞机在右边界和下边界初夏问题。。。看不出来。。。 #include<windows.h> #include<time.h> #include<stdlib.h> #include<conio.h> #include<string.h> int map[60][50],oldmap[60][50]; clock_t Now_Time=clock(); void HideCursor() //隐藏光标 { HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cursor_info={1,0}; SetConsoleCursorInfo(hOut,&cursor_info); } void gotoxy(int x,int y) //移动光标 { HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE); COORD loc={x,y}; SetConsoleCursorPosition(hOut,loc); } void drawmap() //重新绘图 { int x,y,j; char a; for(x = 0;x < 60;x++) for(y = 0;y < 50;y++) { j = map[x][y]; if(j == 0) a = ' '; if(j == 1) a = '0'; if(j == 2) a = 6; gotoxy(x,y); if(map[x][y] != oldmap[x][y]) printf("%c",a); oldmap[x][y] = map[x][y]; } } void setplane(int x,int y) //设置飞机 { int i,j; for(i = 0;i < 60;i++) for(j = 0;j < 50;j++) { if(map[i][j] == 1) map[i][j] = 0; } for(i = y;i < y+3;i++) map[x][i] = 1; map[x-1][y+1] = 1; map[x+1][y+1] = 1; map[x-1][y+2] = 1; map[x+1][y+2] = 1; } void main() //程序主函数 { int x,y,px = 30,py = 30,flag; long t1,t2; char a; system("mode con cols=50 lines=40"); for(x = 0;x < 60;x++) for(y = 0;y < 50;y++) { map[x][y] = 0; oldmap[x][y] = -1; } HideCursor(); flag = true; Now_Time = clock(); t1 = Now_Time; t2 = Now_Time; drawmap(); while(1) { Now_Time = clock(); if(_kbhit()) { a = getch(); if((a == 'H')&&(py > 0)) py = py - 1; if((a == 'P')&&((py+2) < 49)) py = py + 1; if((a == 'K')&&((px-1) > 0)) px = px - 1; if((a == 'M')&&((px+1) < 59)) px = px + 1; if(a == ' ') flag = !flag; } if(flag) { setplane(px,py); if(Now_Time - t1 > 200) { if((py-1) >= 0) { map[px][py-1] = 2; t1 = Now_Time; } } if(Now_Time - t2 > 30) { for(x = 0;x < 60;x++) for(y = 0;y < 50;y++) if(map[x][y] == 2) { map[x][y] = 0; if((y-1) >= 0) map[x][y-1] = 2; } t2 = Now_Time; } drawmap(); } } }