#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void main(){
int i, j;
int x = 5;
int y = 10;
char input;
int isFire = 0;
int ny = 5;
int isKilled = 0;
while(1){
system("cls");
if(!isKilled){ //輸出靶子
for(j = 0; j < ny; j++)
printf(" ");
printf("+\n");
}
if(isFire == 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 == ny) //擊中靶子
isKilled = 1;
isFire = 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()){ //判斷是否有輸入,kbhit()是指使用者輸入的時候才傳回1,否則傳回0;
input = getch(); //根據使用者的不同輸入來移動wsad,需要#include <conio.h>
if(input == 'a')
y--;
if(input == 'd')
y++;
if(input == 'w')
x--;
if(input == 's')
x++;
if(input == ' ')
isFire = 1;
}
}
}
轉載于:https://www.cnblogs.com/leosirius/p/8331507.html