做游戏,学编程(C语言) 飞机游戏 2 (思考改进)

来源:互联网 发布:乔丹和詹姆斯数据对比 编辑:程序博客网 时间:2024/06/11 09:46

思路来自;https://zhuanlan.zhihu.com/p/24652156


#include<stdio.h>#include<stdlib.h>#include<conio.h>#include<windows.h> int main(){int a,b;int c=5; //定义敌机初始位置int d=0; //定义敌机初始位置int x=17; //控制飞机横向位置int y=17; //控制飞机纵向位置int score=0;char input; //符号变量int isfire = 0; //通过变量检测是否发射子弹int isKilled = 0; //记录是否击中int velocity_x = 1;int velocity_y = 1;int left = 0;int right = 15;int top = 0;int bottom = 10;//战机移动相关while(1){system("cls"); //清屏Sleep(10);//输出敌机c=c+velocity_x;    d=d+velocity_y;if ((c==left)||(c==right))velocity_x = -velocity_x;if ((d==top)||(d==bottom))velocity_y = -velocity_y;    if(score<=100){for(b=0;b<d;b++)printf("\n");for(a=0;a<c;a++)printf(" ");printf("o\n");}system("cls");//输出飞机上面的空行if(isfire==0){for(b=0;b<y;b++)printf("\n");}//输出激光束线else {for(b=0;b<y;b++){for (a=0;a<x;a++)printf(" ");printf("  |\n");}if (x+2==c)isKilled=1;// 击中靶子if (x+2==c)    score++;isfire = 0;}//输出飞机for(a=0;a<x;a++)printf(" ");printf("  *\n");for(a=0;a<x;a++)printf(" ");printf("*****\n");for(a=0;a<x;a++)printf(" ");printf(" * *\n");  printf("\n");if(kbhit()) // 判断是否有输入{input=getch();if(input=='a')x--; //左移if(input=='d')x++; //右移if(input=='w')y--; //上移if(input=='s')y++; //下移if(input==' ')isfire=1;}system("cls");for(a=0;a<20;a++)printf("\n");printf("score=%d ",score);/**if(score>=100)break;**/}return 0;}


0 0
原创粉丝点击