C语言实现简单的飞机大战

定义四个函数实现飞机大战

#include
#include
#include
//定义全局变量 
int high,width;						//定义边界 
int position_x,position_y;			//飞机位置 
int bullet_x,bullet_y;				//子弹位置 
int enemy_x,enemy_y;
int score;
int flag;							//飞机状态 
void gotoxy(int x,int y)  			//光标移动到(x,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=18;
	width=26;
	
	position_x=high-3;				
	position_y=width/2;
	
	bullet_x=0;
	bullet_y=position_y; 
	
	enemy_x=0;
	enemy_y=position_y;
	
	score=0;
	
	flag=0;							//飞机完好 
	
	HideCursor();
}
void show()							//显示界面 
{
	int i,j;
	for(i=0;i0)							//子弹上升效果 
		bullet_x--;
	if((bullet_x==enemy_x)&&(bullet_y==enemy_y))		//子弹命中敌机 
	{
		score++;
		bullet_x=-1;	
		enemy_x=1;
		enemy_y=2+rand()%width-2;
	}	


	static int speed;
	if(speed<30)					//减慢敌机速度,不影响飞机和子弹速度 
		speed++;
	if(speed==30)
	{
		if(enemy_x1)
			position_x--;	
		if((input=='s')&&position_x1)
			position_y--;	
		if((input=='d')&&position_y

你可能感兴趣的:(C语言小游戏)