# 改良版本 **Repository Path**: wjj912409/improved_version ## Basic Information - **Project Name**: 改良版本 - **Description**: No description available - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-11-05 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #include #include #include #include //函数外全局变量定义 int x,y; //飞机的初始位置 int high,width; //游戏画面尺寸 int zidan_x,zidan_y ; //子弹位置 int diji_x,diji_y; //敌机位置 int score;//游戏得分 int unhappy;//暂停 void startput() //数据初始化 { high=18,width=30; x=high/2;y=width/2; zidan_x=-1,zidan_y=y; diji_x=0,diji_y=width/2; score=0; unhappy=1; } void show() //显示画面 { int i,j; system("cls"); for(i=0;i<=high;i++) { for(j=0;j<=width;j++) { if((i==x)&&(j==y)) { printf("* *\n"); for(j=0;j<=y-1;j++) printf(" "); printf("***"); } else if((i==zidan_x)&&(j==zidan_y)) printf("|"); else if((i==diji_x)&&(j==diji_y)) printf("@"); else printf(" "); } printf("\n"); } printf("得分:%d",score); } void updatewithoutinput() //与用户输入无关的更改 { int n; n=5; if(score==5) n=4; if(score==10) n=3; if(score==15) n=2; if((diji_x==zidan_x)&&(diji_y==zidan_y)) { zidan_x=-1; diji_x=0; diji_y=rand()%width; score++; } if(zidan_x>=-1) zidan_x--; static int speed=0; if(speed=high) { diji_y=rand()%width; diji_x=0; } else { if(speed==n) { diji_x++; speed=0; } } } void updatewithinput() //与用户输入有关的更改 { char input; if(kbhit()) //当按键时执行 { input=getch(); if(input=='a') y--; if(input=='d') y++; if(input=='w') x--; if(input=='s') x++; if(input==' ') { zidan_x=x-1; zidan_y=y; } if(input==27) { if(unhappy==1) unhappy=0; else if(unhappy==0) unhappy=1; } if(x<=0) x++; if(x>=18) x--; if(y<=0) y++; if(y>=30) y--; } } int main() { startput(); while(1) { if(unhappy==1) { show(); updatewithoutinput(); updatewithinput(); } else if(unhappy==0) { show(); updatewithinput(); } } return 0; }