程序设计 C语言飞机大战

作业要求:

1.游戏当中出现多类型敌人
2.游戏中能进行存档和读档
3.玩家控制的飞机由多字符组成
4.游戏过程中没有出现BUG 
5.游戏显示制作者信息
6.游戏当中带有BGM
7.其他个性化设定

成效:

代码:

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<mmsystem.h>				// 导入声音头文件
#pragma comment(lib,"Winmm.lib")	// 导入声音头文件库

#define High 20			// 游戏画面尺寸
#define Width 30
#define EnemyNum 5		// 敌机个数
#define BossNum 2		// Boss机个数

int flag;				// 飞机状态 
int color(int c);		// 更改文字颜色
void explation();		// 游戏提示
void show();			// 显示游戏界面
void endgame();			// 游戏结束
void startup();			// 数据初始化
void FileRead();		// 读档

// 全局变量
int position_x, position_y;				// 飞机位置
struct enemy{
	int x;
	int y;
	int life;
}Boss[BossNum], enemy[EnemyNum];		// 敌机位置

int canvas[High][Width] = {0};			// 二维数组存储游戏画布中对应的元素
										// 0为空格,1为飞机8,2为子弹o,3为敌机0 , 4为Boss敌机A
int score;								// 得分
int number;								// 销毁敌机数
int BulletWidth;						// 子弹宽度
int EnemyMoveSpeed;						// 敌机移动速度

// 光标移动到(x,y)位置
void gotoxy(int x, int y)
{
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos;
	pos.X = x;
	pos.Y = y;
	SetConsoleCursorPosition(handle, pos);
}

// 更改文字颜色
int color(int c)
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
	return 0;
}

// 隐藏光标
void HideCursor()
{
	CONSOLE_CURSOR_INFO cursor_info = {1,0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

// 开始界面
void welcometogame()
{
	int n, i, j = 1;
	system("cls");
	color(15);
	gotoxy(33, 1);
	printf("飞机大战 Plane War");
	color(56);
	for (i = 3; i <= 26; i++)       // 输出上下边框
	{
		for (j = 6; j <= 80; j++)   // 输出左右边框
		{
			gotoxy(j, i);
			if (i == 3 || i == 26)
				printf(" ");
			else if (j == 6 || j == 80)
				printf(" ");
		}
	}
	color(14);
	gotoxy(38, 6);
	printf("基本操作\n");
	gotoxy(19, 8);
	printf("空格:发射子弹  W:前进  A:左移  D:右移  S:后退\n");
	gotoxy(34, 11);
	printf("1.开始游戏(play)");
	gotoxy(34, 13);
	printf("2.游戏规则(rule)");
	gotoxy(34, 15);
	printf("3.读取存档(read)");
	gotoxy(34, 17);
	printf("4.退出游戏(quit)");
	color(15);
	gotoxy(14, 24);
	printf("游戏制作人:XXX   学号:XXXXXXXXX   联系方式:XXXXXXXXXXX");
	color(14);
	gotoxy(33, 20);
	printf("请选择 1 2 3 4: ");
	color(14);
	scanf("%d", &n);   // 输入选项
	switch (n)
	{
	case 1:
		flag = 1;
		system("cls");
		break;
	case 2:
		explation();   // 游戏规则
		break;
	case 3:
		system("cls"); // 读档
		break;
	case 4:
		gotoxy(30, 28);
		exit(0);       // 退出游戏
		break;
	default:
		color(9);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Twinkling_xxx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值