C语言制作飞机大战

C语言制作飞机大战

#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "windows.h"

int px,py;
int bx,by;
int ex,ey;
int high,width;
int score;
int ispause=0;
int time=100;
int level=0;

void gotoxy(int x,int y)
{
	HANDLE handle =GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos;
	pos.X=x;
	pos.Y=y;
	SetConsoleCursorPosition(handle,pos);
}

void HideCursor()
{
	CONSOLE_CURSOR_INFO cursor_info={1,0};//第二个值为0表示隐藏光标
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}



void startup()
{
	high=20;
	width=30;
	px=high/2;
	py=width/2;
	bx=0;
	by=py;
	ex=0;
	ey=py;
    score=0;
  HideCursor();
}



void show()
{
	gotoxy(0,0);
	int i,j;
	for (i=0;i<high;i++)
	{
		for (j=0;j<width;j++)
		{
			if (i==px&&j==py)
			{
				printf("*");

			}
			else if (i==px+1&&j==py-2)
			{
				printf("*****");

			}
			else if(i==px+2&&j==py-1)
			{
				printf ("* * ");

			}


			else if (i==bx&&j==by)
			{
				printf("|");
			}
			else if (i==ex&&j==ey)
			{
				printf("@");
			}
			else
				printf(" ");
		}
		printf("\n");
	}
	printf("得分:%d\n",score);
	printf("敌机速度:%d\n",level);
}


void updatewithoutinput()
{
	if (bx>-1)
	{
		bx--;
	}

	if (bx==ex&&by==ey)
	{
		score++;
		ex=-1;
		ey=rand()%width;
		bx=-2;
		if (score%3==0&&time>10)
		{
			time-=5;
			level++;
		}
	}
    if (ex>high)
    {
		ex=-1;
        ey=rand()%width;
    }

	static int speed=0;

	if (speed<time)
	{
		speed++;
	}
	if (speed==time)
	{
		ex++;
		speed=0;
	}

}

void updatewithinput()
{
	char input;
	if (kbhit())
	{
		input=getch();
		if (input=='a')
		{
			if (py==0)
			{
				py=width;
			}
			else
			py--;
		}
		if (input=='d')
		{
			if (py==width)
		{
			py=0;
		}
			else
			py++;
		}
		if (input=='w')
		{
			if (px==0)
			{
				px=high;
			}
			else
			px--;
		}
		if (input=='s')
		{
			if (px==high)
			{
				px=0;
			}
			else
			px++;
		}
		if (input==' ')
		{
			bx=px-1;
			by=py;
		}

	}
}



int main ()
{
	startup();

	while (1)
	{

			show();
			updatewithoutinput();
			updatewithinput();


	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值