飞机大战作业C++实现

飞机大战源代码

大家都喜欢玩游戏,但是如何用C++完成一款比较完整的游戏呢?请按照如下说明完成空战游戏的开发。

.敌机数量>1, 飞机发射的子弹数量>1,所以用二维数组记录游戏画面中对应的元素,0表示输出空格,1表示输出飞机,2输出子弹,3输出敌机。

  1. 空战游戏开始有趣了,但是一些错误处理不够,也可以增加更多的游戏情节。
    i. 增加敌机boss,其形状更大、血量更多;
    ii. 尝试让敌机也发射子弹。
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<string>

using namespace std;


typedef struct Frame
{
   
	COORD position[2];
	int flag;
}Frame;



void SetPos(COORD a)
{
   
	HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(out, a);
}

void SetPos(int i, int j)
{
   
	COORD pos = {
    i, j };
	SetPos(pos);
}

void HideCursor()
{
   
	CONSOLE_CURSOR_INFO cursor_info = {
    1, 0 };
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}


void drawRow(int y, int x1, int x2, char ch)
{
   
	SetPos(x1, y);
	for (int i = 0; i <= (x2 - x1); i++)
		cout << ch;
}


void drawRow(COORD a, COORD b, char ch)
{
   
	if (a.Y == b.Y)
		drawRow(a.Y, a.X, b.X, ch);
	else
	{
   
		SetPos(0, 25);
		cout << "error code 01���޷�����У���Ϊ���������������(x)�����";
		system("pause");
	}
}


void drawCol(int x, int y1, int y2, char ch)
{
   
	int y = y1;
	while (y != y2 + 1)
	{
   
		SetPos(x, y);
		cout << ch;
		y++;
	}
}


void drawCol(COORD a, COORD b, char ch)
{
   
	if (a.X == b.X)
		drawCol(a.X, a.Y, b.Y, ch);
	else
	{
   
		SetPos(0, 25);
		cout << "error code 02���޷�����У���Ϊ��������ĺ�����(y)�����";
		system("pause");
	}
}

//���Ͻ����ꡢ���½����ꡢ��row����С���col�����
void drawFrame(COORD a, COORD  b, char row, char col)
{
   
	drawRow(a.Y, a.X + 1, b.X - 1, row);
	drawRow(b.Y, a.X + 1, b.X - 1, row);
	drawCol(a.X, a.Y + 1, b.Y - 1, col);
	drawCol(b.X, a.Y + 1, b.Y - 1, col);
}

void drawFrame(int x1, int y1, int x2, int y2, char row, char col)
{
   
	COORD a = {
    x1, y1 };
	COORD b = {
    x2, y2 };
	drawFrame(a, b, row, col);
}

void drawFrame(Frame frame, char row, char col)
{
   
	COORD a = frame.position[0];
	COORD b = frame.position[1];
	drawFrame(a, b, row, col);
}

void drawPlaying()
{
   
	drawFrame(0, 0, 48, 24, '#', '#');//	map frame;
	drawFrame(49, 4, 79, 9, '-', '|');//	 score frame
	SetPos(52, 6);
	cout << "�÷֣�";
	SetPos(52, 7);
	cout << "����";


}

//��[a, b)֮�����һ���������
int random(int a, int b)
{
   
	int c = (rand() % (a - b)) + a;
	return c;
}

//��������������ľ��ο����������һ������
COORD random(COORD a, COORD b)
{
   
	int x = random(a.X, b.X);
	int y = random(a.Y, b.Y);
	COORD c = {
    x, y };
	return c;
}

bool  judgeCoordInFrame(Frame frame, COORD spot)
{
   
	if 
  • 21
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值