# 空战游戏 **Repository Path**: wjj912409/dogfight ## 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-18 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #include #include #include #include #define high 20 //定义游戏画面尺寸 #define width 50 #define dijinum 3 //敌机数目 // 全局变量 int a[high][width]; //二维数组记录游戏画面位置 //0 输出空格,1 输出飞机,2 输出子弹,3 是敌机 int x,y; //飞机坐标位置 int diji_x[dijinum],diji_y[dijinum]; //敌机坐标位置 int score; //得分 int zidanwidth; //子弹宽度 int dijisudu; //敌机速度 void gotoxy(int x,int y) //光标移动到(x,y)位置 { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition(handle,pos); } void HideCursor() // 用于隐藏光标 { CONSOLE_CURSOR_INFO cursor_info = {1, 0}; // 第二个值为0表示隐藏光标 SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); } void startup() // 数据初始化 { x=high/2; y=width/2; a[x][y]=1; score=0; zidanwidth=0; dijisudu=15; int k; for(k=0;k0) a[i-1][j]=2; } } } static int speed=0; if(speedhigh) //敌机跑出下边界 { a[diji_x[k]][diji_y[k]]=0; diji_x[k]=0; diji_y[k]=rand()%width; a[diji_x[k]][diji_y[k]]=3; score--; } } /////////////////////////////////////////////////////////////// if(score>=5) { dijisudu=12; dijinum=1; } if(score>=10) { dijisudu=9; dijinum=2; } if(score>=15) { dijisudu=5; dijinum=3; } } void updateWithInput() // 与用户输入有关的更新 { char input; if(kbhit()) { input=getch(); if(input=='w') { a[x][y]=0; x--; a[x][y]=1; } if (input=='s') { a[x][y]=0; x++; a[x][y]=1; } if(input=='a') { a[x][y]=0; y--; a[x][y]=1; } if (input=='d') { a[x][y]=0; y++; a[x][y]=1; } if(input==' ') { int left,right; left=y-zidanwidth; if(left<0) left=0; right=y+zidanwidth; if(right>width-1) right=width-1; int t; for(t=left;t<=right;t++) { a[x-1][t]=2; } } } } int main() { startup(); // 数据初始化 while (1) // 游戏循环执行 { show(); // 显示画面 updateWithoutInput(); // 与用户输入无关的更新 updateWithInput(); // 与用户输入有关的更新 } return 0; }