2019春第一次课程设计实验报告

1.实验项目名称
飞机游戏
2.实验项目功能描述
实现一个飞机游戏,主要包括新式子弹,敌机移动,击中敌机,清屏。
3.项目模块介绍
清屏

void HideCuresor()
{
    CONSOLE_CURSOR_INFO cursor_info={1,0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void gotoxy(int x,int y)
{
	HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos;
	pos.X=x;
	pos.Y=y;
	SetConsoleCursorPosition(handle,pos);
}

数据初始化

void startup()
{
	high=100;
	width=120;
	pos_x=high/2;
	pos_y=width/2;
	bul_x=-2;
	bul_y=pos_y;
	ene_x=0;
	ene_y=pos_y;
	score=0;
}

实现子弹

void show()
{
	gotoxy(0,0);
	int i,j;
	for(i=0;i<high;i++)
	{
		for(j=0;j<width;j++)
		{
			if((i==pos_x)&&(j==pos_y))
			   printf("*");
			else if((i==ene_x)&&(j==ene_y))
			   printf("@");
			else if((i==bul_x)&&(j==bul_y))
			        printf("|");
			else
			   printf(" ");
		}
		printf("\n");
	}
	printf("得分:%d\n",score);
}

敌机移动,击中得分

void updateWithoutInput()
{
	if(bul_x>-1)
	   bul_x--;
	if((bul_x==ene_x)&&(bul_y==ene_y))
	{
		score++;
		ene_x=-1;
		ene_y=rand()%width;
		bul_x=-2;
	}
	if(ene_x>high)
	{
		ene_x=-1;
		ene_y=rand()%width;
	}
	static int speed=0;
	if(speed<10)
	   speed++;
	if(speed==10)
	{
		ene_x++;
		speed=0;
	}
	
}

控制子弹移动

void updateWithInput()
{
	char input;
	if(kbhit())
	{
	    input=getch();	 
		if(input=='a')
		   pos_y--;
		if(input=='d')
		   pos_y++;
		if(input=='w')
		   pos_x--;
		if(input=='s')
		   pos_x++;
		if(input==' ')
		{
			bul_x=pos_x-1;
			bul_y=pos_y;
		}
    }
}

4.实现界面显示

5.代码托管链接
https://gitee.com/scfyer/first
6.实验总结
哇,终于第一次用c语言做了一个小游戏,实现了下以前的小愿望哈。挺有意思的,当初选软件工程的原因就有游戏。有种小小的满足感,在学这个小游戏中学会了许多,也遇到了问题。还有开心的事,这个报告比博客容易弄,哈哈。

posted @ 2019-05-27 17:00  Scfyer  阅读(162)  评论(0编辑  收藏  举报