![](http://tb2.bdstatic.com/tb/editor/images/face/i_f09.png?t=20140803)
代码如下(没有删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;
}
}
}
}