一:实验项目名称:飞机游戏

二:实验项目功能描述:
通过操纵自己的飞机来上下左右移动,并发射炮弹来摧毁敌机,获得分数的小游戏,来了解基础的游戏设计。

三:项目模块结构介绍:
1:飞机位置以及画面尺寸

void startup(){
	high = 20;
	width = 30;
	position_x = high/2;
	position_y = width/2;
	bullet_x = -2;
	bullet_y = position_y;
	enemy_x = 0;
	enemy_y = position_y;
	score = 0;

	HideCursor();
}

2:飞机,敌机以及炮弹,得分的表示

void show()  
{
	gotoxy(0,0);  
	int i,j;
	for (i=0;i<high;i++)
	{
		for (j=0;j<width;j++)
		{
			if ((i==position_x) && (j==position_y))
				printf("*");  
			else if ((i==enemy_x) && (j==enemy_y))
				printf("@");  
			else if ((i==bullet_x) && (j==bullet_y))
				printf("|");  
			else
				printf(" ");  
		}
		printf("\n");
	}
	printf("得分:%d\n",score);

3:敌机的移动,炮弹击中敌机。

void updateWithoutInput()  
{	
	if (bullet_x>-1)
		bullet_x--; 
	
	if ((bullet_x==enemy_x) && (bullet_y==enemy_y))  
	{
		score++;                
		enemy_x = -1;           
		enemy_y = rand()%width;
		bullet_x = -2;          
	}
	if (enemy_x>high)   
	{
		enemy_x = -1;           
		enemy_y = rand()%width;
	}
	static int speed = 0;  
	if (speed<20)
		speed++;
	if (speed == 20)
	{
		enemy_x++;			
		speed = 0;
	}
}.

4:飞机的移动。

void updateWithInput()   
{
	char input;
	if(kbhit())  
	{
		input = getch();  
		if (input == 'a')   
			position_y--;  		
if (input == 'd')
			position_y++;  
		if (input == 'w')
			position_x--;  
		if (input == 's')
			position_x++;  
		if (input == ' ')  
		{
			bullet_x = position_x-1;  			
bullet_y = position_y;
		}
		
	}
}

5:清屏

int main()
{
	startup();  	
	while (1)
	{
		show();  
		updateWithoutInput();  
		updateWithInput();  
	}
	return 0;
}

四:实现界面展示:

五:代码托管链接:
https://gitee.com/dengjun22/Handsome-old-man
六:实验总结(提出问题+解决办法+感想)
提出问题:在控制飞机移动的过程中,怎样能够使移动后不需要再按下回车键就能移动?
解决问题:在随书资源里和书上它是说不需要按下回车键的,但是我在实际操作的过程中发现只要你不按下回车键飞机就不会移动,接收键盘上的字符已经在代码里了,就是不行。
感想:我真是服了。看到这几个头文件我就一脸懵逼,这都是一些啥玩意儿,还有这第一个游戏在c++里可以运行,但是反弹球却不行,一直在头文件那里显示错误。一些字符都代表着某些东西,给我一种似懂非懂的感觉。