//C++ 枪战游戏

这段代码是用C++编写的坦克大战游戏的实现,包括玩家坦克、敌人坦克、子弹的移动、碰撞检测以及生命值显示等功能。玩家通过键盘控制坦克移动和射击,敌人会自动攻击,并且有血量显示。游戏结束条件是玩家或敌人生命值降为0。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <easyx.h>
#include <time.h>
#include <conio.h>

class Bullet;
class Tank;
class E_Bullet;
class Boss;
bool dead = false;
bool wined = false;
struct pos//坐标类
{
 int a;
 int b;
};
class E_Bullet//敌人打出的子弹
{
public:
 clock_t d;
 int x;
 int y;
 bool on = false;
 pos show()//画出新的位置
 {
 setfillcolor(RGB(255, 180, 20));
 fillrectangle(x - 5, y - 5, x + 5, y + 5);
 return pos{ x,y };
 }
 pos del()//覆盖原来的位置
 {
 setfillcolor(0);
 setlinecolor(0);
 fillrectangle(x - 5, y - 5, x + 5, y + 5);
 rectangle(x - 5, y - 5, x + 5, y + 5);
 return pos{ x,y };
 }
 pos move()//左移
 {
 x -= 3;
 return pos{ x,y };
 }
};
class Bullet//玩家打出的子弹,同上
{
public:
 clock_t d;
 int x;
 int y;
 bool on = false;
 pos show()
 {
 setfillcolor(RGB(150, 180, 210));
 fillrectangle(x - 5, y - 5, x + 5, y + 5);
 return pos{ x,y };
 }
 pos del()
 {
 setfillcolor(0);
 setlinecolor(0);
 fillrectangle(x - 5, y - 5, x + 5, y + 5);
 rectangle(x - 5, y - 5, x + 5, y + 5);
 return pos{ x,y };
 }
 pos move()//右移
 {
 x += 3;
 return pos{ x,y };
 }
};
class Boss//敌人
{
public:
 bool hurting = false;
 clock_t d_hurt;
 COLORREF clr = RGB(0, 130, 125);
 int x;
 int y;
 int hp = 100;//生命
 clock_t d;//判断举例上一次执行某一函数过了多久
 clock_t att_d;
 bool angle = false;//方向
 pos show()
 {
 setfillcolor(clr);
 fillrectangle(x - 20, y - 40, x + 20, y + 40);
 return pos{ x,y };
 }
 pos del()
 {

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值