烛火一夕 烛火一夕
关注数: 72 粉丝数: 2 发帖数: 42 关注贴吧数: 10
有没有大佬知道飞机游戏怎么让靶子动飞机不动吗? 本来以为加上k,l两个变量把把靶子的变量和飞机的i,j分开,就可以让飞机不动,靶子动了,但是加上还是飞机还是一直在闪。求大佬们帮帮我。用的是vc6,看过置顶了,但是老师要求是用vc6。 代码如下(没有删k,l): #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <windows.h> void main() { int i,j; int k,l;//靶子坐标相关,k同i,l同j int x =10; int y =10; int m = 1; int n = 5;//靶子的坐标,m同x,n同y char input; int isFired = 0; //int ny = 5; int isKilled = 0; int velocity_m = 1;//靶子移动的速度 int velocity_n = 1;//靶子移动的速度 int top = 0; int bottom = 5; int left = 0; int right =10; while(1) { m = m + velocity_m; n = n + velocity_n;//靶子的位置变化 system("cls");//清屏函数 if(isKilled == 0) { for(k=0;k<m;k++) printf("\n"); for(l=0;l<n;l++) printf(" "); Sleep(100); printf("+\n"); if(m==top || m==bottom) velocity_m = -velocity_m; if(n==left || n==right) velocity_n = -velocity_n; } if (isFired == 0) { for (i=0;i<x;i++) printf("\n"); } else { for (i=0;i<x;i++) { for (j=0;j<y;j++) printf(" "); printf(" |\n"); } if (y + 2 ==n) isKilled = 1; isFired = 0; } //输出飞机 for (j=0;j<y;j++) printf(" "); printf(" *\n"); for (j=0;j<y;j++) printf(" "); printf("*****\n"); for (j=0;j<y;j++) printf(" "); printf(" * * \n"); if(kbhit())//判断是否有输入 { input = getch();//scanf("%c", &input); if (input == 's') x++; if (input == 'w') x--; if (input == 'a') y--; if (input == 'd') y++; if (input == ' ') isFired = 1; if (isKilled == 1)//让消失的靶子重新出现 { if(input == 'q') isKilled = 0; } } } }
1 下一页