C++实现打飞机小游戏(源代码)

本文分享了一篇使用C++编写的打飞机小游戏的源代码,适合编程爱好者学习和研究。作者邀请读者关注、点赞和评论,并提到这是其第四次发表此类帖子。
摘要由CSDN通过智能技术生成

你们要的打飞机
还想让我做什么☺☺☺
>求关注,求点赞,求评论<
Thanks♪(・ω・)ノ
代码如下 ☟ ☟ ☟

#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<string>
using namespace std;
 
/*=============== all the structures ===============*/
 
typedef struct Frame
{
   
	COORD position[2];
	int flag;
}Frame;
 
 
/*=============== all the functions ===============*/
 
void SetPos(COORD a)// set cursor 
{
   
	HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(out, a);
}
 
void SetPos(int i, int j)// set cursor
{
   
	COORD pos={
   i, j};
	SetPos(pos);
}
 
void HideCursor()
{
   
	CONSOLE_CURSOR_INFO cursor_info = {
   1, 0}; 
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
 
//把第y行,[x1, x2) 之间的坐标填充为 ch
void drawRow(int y, int x1, int x2, char ch)
{
   
	SetPos(x1,y);
	for(int i = 0; i <= (x2-x1); i++)
		cout<<ch;
}
 
//在a, b 纵坐标相同的前提下,把坐标 [a, b] 之间填充为 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");
	}
}
 
//把第x列,[y1, y2] 之间的坐标填充为 ch
void drawCol(int x, int y1, int y2, char ch)
{
   
	int y=y1;
	while(y!=y2+1)
	{
   
		SetPos(x, y);
		cout<<ch;
		y++;
	}
}
 
//在a, b 横坐标相同的前提下,把坐标 [a, b] 之间填充为 ch
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, '=', '|');//	draw map frame;
	drawFrame(49, 0, 79, 4, '-', '|');//		draw output frame
	drawFrame(49, 4, 79, 9, '-', '|');//		draw score frame
	drawFrame(49, 9, 79, 20, '-', '|');//	draw operate frame
	drawFrame(49, 20, 79, 24, '-', '|');//	draw other message frame
	SetPos(52, 6);
	cout<<"得分:";
	SetPos(52, 7);
	cout<<"称号:";
	SetPos(52,10);
	cout<<"操作方式:";
	SetPos(52,12);
	cout<<"  a,s,d,w 控制战机移动。";
	SetPos(52,14);
	cout<<"  p 暂停游戏。";
	SetPos(52,16);
	cout<<"  e 退出游戏。";
}
 
//在[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
评论 49
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值