C语言 简易版打飞机

include<stdio.h>

include<stdlib.h>

include<conio.h>

int main()
{
int i,j;
int x=10;
int y=5;
char input;
int isFired =0; // 是否开火
int ny = 5;
int isKilled = 0; // 靶子是否被击中

while(1)
{
	system("cls");
	if (isKilled==0)
	{
		for (i=0; i <ny; i++)
			printf(" ");
		printf("+\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==ny)
			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");
	//scanf("%c",&input);
	input=getch(); // 输入字符不用按回车
	if (input=='s')
		x++;
	if (input=='w')
		x--;
	if (input=='a')
		y--;
	if (input=='d')
		y++;
	if (input==' ')
		isFired=1;
			
}



return 0;

}

posted @ 2021-03-07 14:48  未来全栈攻城狮  阅读(186)  评论(0编辑  收藏  举报