[C++] 小游戏 死亡禁区 1.0.0 正式版 !爷青回!zty回来了!!
!!爷青回!!
目录
!!爷青回!!
前言
演示用编译器
标准
先 赞 后 看 养 成 习 惯
正文
适配操作系统
如果显示不全
后记
前言
哈哈哈哈哈哈哈哈哈哈!!!爷青回!!!你们的zty带着他的全新作品回来了。本次,我开发了一个完整的2D+FPS+肉鸽玩法的游戏,死亡禁区。鸣谢胎神带来的启发(膜拜)。目前游戏还处在起步阶段,大家有什么建议和投稿都可以评论的呀哈哈哈。
先 赞 后 看 养 成 习 惯
众所不周知,zty每篇文章都有一个头图

(小声嘀咕)宝可梦!!
先 赞 后 看 养 成 习 惯
演示用编译器
Dev C++ 6.7.5 Red panda
[C++编译器] Dev-C++ 6.7.5 (附下载链接、安装教程)_red panda dev-c++-CSDN博客
标准
C++14
先 赞 后 看 养 成 习 惯
正文
适配操作系统
本代码为Windows版,其他操作系统不兼容,如想兼容很简单,把文章开头的
#include
换为自己操作系统所对应的就行了,例如换为
#include
完整代码(Windows版)
下面是完整代码(Windows版),代码总长62829,68K。
#include
#include
#include
#include
#include
#include
#include
#include
#define KEY_DOWN(VK_NONAME)((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
using namespace std;
// 定义方向数组,简化怪物移动逻辑
const int dx4[] = {-1, 0, 1, 0}; // 上、右、下、左
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, -1, 0, 1, 1, 1, 0, -1}; // 顺时针8个方向
const int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
bool CanGo(int, int, int);
void Laser_Drawing(int, int, int, int);
int m[45][45], n[45][45];
void Map_Colors(int a) {
if (a == 0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
if (a == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
if (a == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
if (a == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
if (a == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
if (a == 5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
if (a == 6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
if (a == 7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN); //木
if (a == 8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); //铁
if (a == 9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
if (a == 10) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | BACKGROUND_GREEN);
if (a == 11) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE | BACKGROUND_GREEN);
if (a == 12) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | BACKGROUND_GREEN);
if (a == 13) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE | BACKGROUND_INTENSITY | BACKGROUND_BLUE);
}
void SetPos(int x, int y) {
COORD pos;
pos.X = y * 2, pos.Y = x + 3;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int X, Y, gx, gy, Muzzle, Gun_type, T, G[11], F[30];
int Win, Lev, HP_Player, DE_Player, MaxHP_Player, MaxDE_Player, Unable_To_Be_Attacked, Num_Monsters, Dazzling_Entrance, Farewell_Gift, sy, shootCooldown;
int Bx, By, Boss_HP, Boss_CrossBullet_CD, Boss_CornerBullet_CD, Boss_Poison_CD, Boss_Conjure_CD, Bxz, Byz;
const int INVISIBLE_CYCLE = 30; // 隐形周期(帧数)
const int VISIBLE_DURATION = 10; // 显形持续时间(帧数)
int Money = 0; // 玩家当前金钱
const int MONEY_DUMB_MONSTER = 3;
const int MONEY_POISON_MONSTER = 10;
const int MONEY_SHOTGUN_MONSTER = 6;
const int MONEY_SNIPER_MONSTER = 6;
const int MONEY_LASER_MONSTER = 8;
const int MONEY_INVISIBLE_MONSTER = 20;
const int MONEY_BOSS_PER_BAR = 10; // BOSS每血条金钱
// ==================== 优化的怪物AI函数 ====================
int InvisibleMonsterVisible[45][45]; // 记录隐形怪当前是否可见
int InvisibleMonsterTimer[45][45]; // 记录隐形怪的计时器
void ResetInvisibleMonsterState() {
memset(InvisibleMonsterVisible, 0, sizeof(InvisibleMonsterVisible));
memset(InvisibleMonsterTimer, 0, sizeof(InvisibleMonsterTimer));
}
// 怪物基类行为函数 - 尝试移动怪物
// 修改TryMoveMonster函数,在怪物类型判断中添加隐形怪
bool TryMoveMonster(int i, int j, int targetX, int targetY, int monsterType, bool nx[42][42]) {
int moveDir = -1;
// 添加隐形怪到怪物类型判断中
if (monsterType == 55 || monsterType == 50 || monsterType == 51) {
// 无脑怪、毒怪和隐形怪的简单AI
if (rand() % 2 == 0) {
// 50%概率向玩家移动
if (abs(targetX - i) > abs(targetY - j)) {
moveDir = (targetX > i) ? 2 : 0; // 上下
} else {
moveDir = (targetY > j) ? 1 : 3; // 左右
}
} else {
// 50%概率随机移动
moveDir = rand() % 4;
}
} else if (monsterType == 52 || monsterType == 53 || monsterType == 54) {
// 散弹怪、狙击怪、激光怪的移动(更智能)
if (rand() % 4 == 0) {
// 25%概率向玩家移动
if (abs(targetX - i) > abs(targetY - j)) {
moveDir = (targetX > i) ? 2 : 0;
} else {
moveDir = (targetY > j) ? 1 : 3;
}
} else {
// 75%概率随机移动
moveDir = rand() % 4;
}
}
// 移动逻辑保持不变,但添加对隐形怪的颜色处理
if (moveDir != -1) {
int newI = i + dx4[moveDir];
int newJ = j + dy4[moveDir];
if (CanGo(newI, newJ, 1)) {
// 移动怪物
m[i][j] = 0;
InvisibleMonsterVisible[i][j] = 0; // 清除原位置的可见状态
InvisibleMonsterTimer[i][j] = 0; // 清除原位置的计时器
m[newI][newJ] = monsterType;
// 移动计时器状态到新位置
InvisibleMonsterTimer[newI][newJ] = InvisibleMonsterTimer[i][j];
InvisibleMonsterVisible[newI][newJ] = InvisibleMonsterVisible[i][j];
SetPos(i, j);
cout << " ";
SetPos(newI, newJ);
// 根据怪物类型显示不同颜色
if (monsterType == 50) Map_Colors(1);
else if (monsterType == 51) Map_Colors(10);
else if (monsterType == 52) Map_Colors(3);
else if (monsterType == 53) Map_Colors(4);
else if (monsterType == 54) Map_Colors(5);
else if (monsterType == 55) {
// 隐形怪:只有可见时才显示,否则显示为半透明
if (InvisibleMonsterVisible[newI][newJ]) {
Map_Colors(13); // 深灰色表示可见的隐形怪
} else {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
// 完全隐藏(显示空格)
}
}
cout << "●";
Map_Colors(0);
nx[newI][newJ] = true;
return true;
}
}
return false;
}
// 毒怪的特殊行为:释放毒气
void PoisonMonsterAttack(int i, int j) {
if (rand() % 10 == 0) { // 约6.7%概率释放毒气
for (int k = i - 2; k <= i + 2; k++) {
for (int l = j - 2; l <= j + 2; l++) {
if (k > 1 && l > 1 && k <= 28 && l <= 28 &&
(CanGo(k, l, 1) || m[k][l] == 1)) {
m[k][l] = 59; // 怪物毒气
}
}
}
}
}
// 散弹怪的攻击行为
void ShotgunMonsterAttack(int i, int j) {
if (rand() % 10 == 0) { // 10%概率发射散弹
int shotCount = rand() % 3 + 1; // 发射1-3发子弹
for (int shot = 0; shot < shotCount; shot++) {
int direction = rand() % 8; // 随机8个方向
int newI = i + dx8[direction];
int newJ = j + dy8[direction];
if (CanGo(newI, newJ, 6)) {
m[newI][newJ] = 210 + (direction + 1); // 子弹编码
}
}
}
}
// 狙击怪的攻击行为
void SniperMonsterAttack(int i, int j, int playerX, int playerY) {
if (rand() % 6 == 0) { // 约16.7%概率射击
// 计算玩家方向
int dx = playerX - i;
int dy = playerY - j;
// 找到最接近玩家方向的方向
int bestDir = 0;
float bestScore = -9999;
for (int dir = 0; dir < 8; dir++) {
float score = dx8[dir] * dx + dy8[dir] * dy;
if (score > bestScore) {
bestScore = score;
bestDir = dir;
}
}
int newI = i + dx8[bestDir];
int newJ = j + dy8[bestDir];
if (CanGo(newI, newJ, 6)) {
m[newI][newJ] = 210 + (bestDir + 1); // 子弹编码
}
}
}
// 激光怪的攻击行为
void LaserMonsterAttack(int i, int j) {
if (rand() % 10 == 0) { // 10%概率发射激光
int laserDir = rand() % 4; // 随机选择4个主要方向
// 激光方向:1-上,3-右,5-下,7-左
int direction = laserDir * 2 + 1;
Laser_Drawing(i, j, 230 + direction, 2);
}
}
// 主怪物逻辑处理函数
void ProcessMonsters(bool nx[42][42]) {
for (int i = 2; i <= 38; i++) {
for (int j = 2; j <= 38; j++) {
if (nx[i][j]) continue;
int monsterType = m[i][j];
// 隐形怪 (55)
// 无脑怪 (50) - 每2帧移动一次
if (monsterType == 50 && T % 2 == 0) {
TryMoveMonster(i, j, X, Y, 50, nx);
}
// 毒怪 (51)
else if (monsterType == 51) {
// 先释放毒气
PoisonMonsterAttack(i, j);
// 然后尝试移动
if (TryMoveMonster(i, j, X, Y, 51, nx)) {
// 移动后可能再次释放毒气
PoisonMonsterAttack(i + dx4[0], j + dy4[0]);
}
}
// 散弹怪 (52)
else if (monsterType == 52) {
ShotgunMonsterAttack(i, j);
// 66%概率移动
if (rand() % 3 != 0) {
TryMoveMonster(i, j, X, Y, 52, nx);
}
}
// 狙击怪 (53)
else if (monsterType == 53) {
SniperMonsterAttack(i, j, X, Y);
// 约16.7%概率移动
if (rand() % 6 == 0) {
TryMoveMonster(i, j, X, Y, 53, nx);
}
}
// 激光怪 (54)
else if (monsterType == 54) {
LaserMonsterAttack(i, j);
// 25%概率移动
if (rand() % 4 == 0) {
TryMoveMonster(i, j, X, Y, 54, nx);
}
} else if (monsterType == 55) {
// 更新隐形怪的计时器
InvisibleMonsterTimer[i][j]++;
// 检查是否需要切换可见状态
if (InvisibleMonsterVisible[i][j]) {
// 当前可见,检查是否需要变为不可见
if (InvisibleMonsterTimer[i][j] >= VISIBLE_DURATION) {
InvisibleMonsterVisible[i][j] = 0;
InvisibleMonsterTimer[i][j] = 0;
// 立即刷新显示(变为不可见)
SetPos(i, j);
cout << " ";
}
} else {
// 当前不可见,检查是否需要变为可见
if (InvisibleMonsterTimer[i][j] >= INVISIBLE_CYCLE) {
InvisibleMonsterVisible[i][j] = 1;
InvisibleMonsterTimer[i][j] = 0;
// 立即刷新显示(变为可见)
SetPos(i, j);
Map_Colors(13); // 深灰色
cout << "●";
Map_Colors(0);
}
TryMoveMonster(i, j, X, Y, 55, nx);
}
}
}
}
}
void bccd() { //保存存档
char line[256];
std::fstream myFile;
myFile.open("死亡禁区 26.1.29.1.0.0存档.txt", ios::out);
if (myFile.is_open()) {
myFile << Money << "
";
myFile.close();
}
}
void drcd() { //读入存档
string line;
std::fstream myFile;
int s = 0;
myFile.open("死亡禁区 26.1.29.1.0.0存档.txt", ios::in); // read,读
if (myFile.is_open()) {
while (getline(myFile, line)) {
string str(line);
s++;
if (s == 1)
Money = atoi(str.c_str());
}
myFile.close();
}
}
void MainMenu() {
system("cls");
int selected = 1; // 当前选中的菜单项
drcd();
while (true) {
system("cls");
Map_Colors(5);
// 游戏标题
SetPos(-1, 0);
cout << " ███ ████ █ ███ ████ ██ █ █ ████ ";
SetPos(0, 0);
cout << " █ █ █ ██ █ █ █ █ █ ██ █ █ ";
SetPos(1, 0);
cout << " █ █ █ █ █ █ █ █ █ █ ██ █ █ ";
SetPos(2, 0);
cout << " █ █ ████ █ █ █ █ █ █ █ █ █ █ ████ ";
SetPos(3, 0);
cout << " █ █ █ ███ █ █ █ █ █ █ ██ █ ";
SetPos(4, 0);
cout << " █ █ █ █ █ █ █ █ █ █ █ ██ █ ";
SetPos(5, 0);
cout << " ███ ████ █ █ ███ ████ ██ █ █ ████ ";
SetPos(6, 0);
cout << "==================================================================================";
SetPos(7, 0);
cout << " 《 死亡禁区 Dead Zone 》 1.0.0 正式版 ";
// 菜单选项
Map_Colors(selected == 1 ? 2 : 0);
SetPos(10, 14);
cout << "╔═══════════╗";
SetPos(11, 14);
cout << "║ 开始游戏 ║";
SetPos(12, 14);
cout << "╚═══════════╝";
Map_Colors(selected == 2 ? 2 : 0);
SetPos(14, 14);
cout << "╔═══════════╗";
SetPos(15, 14);
cout << "║ 游戏规则 ║";
SetPos(16, 14);
cout << "╚═══════════╝";
Map_Colors(selected == 3 ? 2 : 0);
SetPos(18, 14);
cout << "╔═══════════╗";
SetPos(19, 14);
cout << "║ 作者介绍 ║";
SetPos(20, 14);
cout << "╚═══════════╝";
Map_Colors(selected == 4 ? 2 : 0);
SetPos(22, 14);
cout << "╔═══════════╗";
SetPos(23, 14);
cout << "║ 退出游戏 ║";
SetPos(24, 14);
cout << "╚═══════════╝";
Map_Colors(5);
SetPos(37, 12);
cout << "使用 ↑ ↓ 键选择,Enter键确认";
// 操作说明
Map_Colors(5);
SetPos(39, 4);
cout << "方向键移动 A/D旋转枪口 Q切枪 W开箱 S射击(可长按)空格暂停";
SetPos(41, 0);
cout << " 作者:CSDN zty郑桐羽呀 抖音 zty_C++ QQ 3782663736 Luogu 1626767 (皆为同一人) ";
SetPos(42, 0);
cout << " 鸣谢 胎神 给予的启发,注:核心内容经过添改不构成侵权抄袭 ";
SetPos(43, 0);
cout << " 版权归属为 zty(上上行)一人所有,盗版侵权必究 版本号:26.1.29 : 1.0.0.Windows ";
// 按键检测
if (kbhit()) {
char ch = _getch();
if (ch == 13) { // Enter键
if (selected == 1) {
system("cls");
// 开始游戏
return;
} else if (selected == 2) {
// 游戏规则
system("cls");
Map_Colors(5);
SetPos(2, 5);
cout << "╔═════════════════════╗";
SetPos(3, 5);
cout << "║ 【游戏规则】 ║";
SetPos(4, 5);
cout << "╚═════════════════════╝";
Map_Colors(0);
SetPos(6, 2);
cout << "1. 使用方向键移动角色 空格键暂停游戏";
SetPos(8, 2);
cout << "2. 按A/D键顺/逆时针旋转枪口,按住S键连续发射子弹";
SetPos(10, 2);
cout << "3. 按Q键在拥有子弹的枪械之间切换";
SetPos(12, 2);
cout << "4. 按W键打开身边的宝箱";
SetPos(14, 2);
cout << "7. 清除所有怪物即可进入下一关";
SetPos(16, 2);
cout << "8. 每5关为BOSS关,击败BOSS可获双天赋";
Map_Colors(0);
SetPos(18, 3);
cout << "枪械类型:";
SetPos(19, 5);
cout << "1.制式突击步枪 2.破片弹投射器 3.反掩体重型狙 4.量子穿透利刃";
SetPos(20, 5);
cout << "5.RPG-01火箭筒 6.便携式毒气炮 7.史莱姆发射器 8.龙血骨钢长剑";
SetPos(22, 3);
cout << "怪物类型:";
SetPos(23, 5);
cout << "●唐恩普通士兵(蓝) ●唐恩病毒实验体(绿) ●唐恩自行无人火炮(紫)";
SetPos(24, 5);
cout << "●唐恩狙击手(红) ●唐恩自行激光干扰车(黄) ●唐恩隐形自爆车(灰)";
Map_Colors(3);
SetPos(26, 7);
cout << "按任意键返回主菜单...";
_getch();
} else if (selected == 3) {
// 作者介绍
system("cls");
Map_Colors(5);
SetPos(2, 4);
cout << "╔═════════════════════╗";
SetPos(3, 4);
cout << "║ 【作者介绍】 ║";
SetPos(4, 4);
cout << "╚═════════════════════╝";
Map_Colors(0);
SetPos(10, 2);
cout << " 作者:zty(注意:此为个人项目,非团队项目)";
SetPos(12, 2);
cout << " QQ:3782663736(注明来意),也欢迎大家来交朋友/骚扰";
SetPos(14, 0);
cout << "讲一些话吧:";
SetPos(16, 0);
cout << " 感谢大家来玩zty的船新作品,说实话,最近zty有些迷茫,啊啊~";
SetPos(18, 0);
cout << " 主要是为了中考嘛,然后写代码有点影响我的学业了";
SetPos(20, 0);
cout << " 其实zty学习还不错,大连高中前三甲(8中、育明、24中),";
SetPos(22, 0);
cout << " 应该是没希望了,但是重点肯定是能上的,我也尽量趁着寒假多写一些";
SetPos(24, 0);
cout << " zty 写这个不是为了盈利,只是想让大家在学习C++的过程中有些欢乐";
SetPos(26, 0);
cout << " 大家可以自己改改代码,如果有不懂的欢迎QQ来问我吽(读哦)~";
SetPos(28, 2);
cout << " ——一个只知道写代码的男初zty";
Map_Colors(6);
SetPos(30, 5);
cout << "按任意键返回主菜单...";
_getch();
} else if (selected == 4) {
// 退出游戏
system("cls");
Map_Colors(5);
SetPos(12, 15);
cout << "感谢游玩《死亡禁区》!";
SetPos(14, 17);
cout << "再见!";
Sleep(2000);
exit(0);
}
} else if (ch == -32) { // 方向键
ch = _getch();
if (ch == 72 && selected > 1) selected--; // 上键
if (ch == 80 && selected < 4) selected++; // 下键
} else if (ch == 'w' || ch == 'W') {
if (selected > 1) selected--;
} else if (ch == 's' || ch == 'S') {
if (selected < 4) selected++;
} else if (ch == 27) { // ESC键
// 退出游戏
system("cls");
Map_Colors(5);
SetPos(12, 15);
cout << "感谢游玩《死亡禁区》!";
SetPos(14, 17);
cout << "再见!";
Sleep(2000);
exit(0);
}
}
Sleep(100);
}
}
void Map(int x);
void Jian(int x) {
if (Unable_To_Be_Attacked > 0) return;
if (DE_Player > x) DE_Player -= x;
else if (DE_Player <= 0) HP_Player -= x;
else if (DE_Player > 0 && DE_Player <= x) {
if (F[13] == 0) HP_Player -= x - DE_Player;
if (F[13] == 1) Unable_To_Be_Attacked = 20;
if (F[17] == 1) Farewell_Gift = 3;
DE_Player = -1;
}
}
bool CanGo(int x, int y, int q) {
if (x < 1 || x > 39 || y < 1 || y > 39) {
return 0; // 返回0,不计数
}
if (abs(Bx - x) <= 1 && abs(By - y) <= 1 && q == 1) return 0;
if (m[x][y] == 2 || m[x][y] == 3) return 0;
if ((q == 0 || q == 1) && n[x][y] == 1) return 0;
if (m[x][y] == 0) return 1;
if (m[x][y] >= 4 && m[x][y] <= 8) return 1;
if (m[x][y] >= 84 && m[x][y] <= 88) return 1;
if (m[x][y] >= 9 && m[x][y] <= 31) return 1;
if (m[x][y] >= 59 && m[x][y] <= 81) return 1;
if ((q == 2 || q == 3 || q == 5) && m[x][y] == 1) return 1; // 剑可以破坏木墙
if ((q == 2 || q == 3) && m[x][y] >= 100 && m[x][y] < 250) return 1;
if ((q == 0 || q == 3 || q == 5) && m[x][y] >= 50 && m[x][y] < 55) return 1;
if ((q == 4 || q == 7) && m[x][y] / 100 == 1) return 1;
if ((q == 0 || q == 3 || q == 5) && m[x][y] == 55) return true; // 玩家可以走到隐形怪上(会受伤)
if ((q == 4 || q == 7) && m[x][y] / 100 == 1) return true; // 子弹可以击中隐形怪
return 0;
}
void CoutMe() {
if (gx < 0 && CanGo(X - 1, Y, 0)) X--;
if (gx > 0 && CanGo(X + 1, Y, 0)) X++;
if (gy < 0 && CanGo(X, Y - 1, 0)) Y--;
if (gy > 0 && CanGo(X, Y + 1, 0)) Y++;
int r;
// 根据当前枪械类型设置枪口箭头颜色
int gunColor = 0; // 默认白色
switch (Gun_type) {
case 1: // 普通枪 - 白色
gunColor = 0;
break;
case 2: // 破片弹投射器 - 紫色
gunColor = 3;
break;
case 3: // 反掩体重型狙 - 蓝色
gunColor = 1;
break;
case 4: // 量子穿透利刃 - 黄色
gunColor = 5;
break;
case 5: // RPG-01火箭筒 - 红色
gunColor = 4;
break;
case 6: // 便携式毒气炮 - 深绿
gunColor = 2;
break;
case 7: // 史莱姆发射器 - 浅绿
gunColor = 10;
break;
case 8: // 龙血骨钢长剑 - 亮红色加闪烁效果
if (T % 10 < 5) gunColor = 4; // 闪烁效果:亮红色
else gunColor = 5; // 闪烁效果:黄色
break;
default:
gunColor = 0;
break;
}
// 设置枪口箭头颜色
Map_Colors(gunColor);
if (Unable_To_Be_Attacked > 0) {
r = rand() % 5 + 1;
Map_Colors(r); // 无敌状态时随机颜色
}
// 如果使用长剑,用特殊符号表示
if (Gun_type == 8) {
if (Muzzle == 1) SetPos(X - 1, Y), cout << "↑";
else if (Muzzle == 2) SetPos(X - 1, Y + 1), cout << "↗";
else if (Muzzle == 3) SetPos(X, Y + 1), cout << "→";
else if (Muzzle == 4) SetPos(X + 1, Y + 1), cout << "↘";
else if (Muzzle == 5) SetPos(X + 1, Y), cout << "↓";
else if (Muzzle == 6) SetPos(X + 1, Y - 1), cout << "↙";
else if (Muzzle == 7) SetPos(X, Y - 1), cout << "←";
else if (Muzzle == 8) SetPos(X - 1, Y - 1), cout << "↖";
// 玩家角色显示剑的符号
Map_Colors(4); // 红色
SetPos(X, Y), cout << "╬";
} else {
// 其他武器的显示
if (Muzzle != 1) SetPos(X - 1, Y), cout << "︹";
if (Muzzle != 5) SetPos(X + 1, Y), cout << "︺";
if (Muzzle != 7) SetPos(X, Y - 1), cout << "﹝";
if (Muzzle != 3) SetPos(X, Y + 1), cout << "﹞";
if (Muzzle == 1) SetPos(X - 1, Y), cout << "↑";
if (Muzzle == 2) SetPos(X - 1, Y + 1), cout << "↗";
if (Muzzle == 3) SetPos(X, Y + 1), cout << "→";
if (Muzzle == 4) SetPos(X + 1, Y + 1), cout << "↘";
if (Muzzle == 5) SetPos(X + 1, Y), cout << "↓";
if (Muzzle == 6) SetPos(X + 1, Y - 1), cout << "↙";
if (Muzzle == 7) SetPos(X, Y - 1), cout << "←";
if (Muzzle == 8) SetPos(X - 1, Y - 1), cout << "↖";
// 玩家角色
Map_Colors(0);
SetPos(X, Y), cout << "●";
}
// 重置为默认颜色
Map_Colors(0);
if (Unable_To_Be_Attacked > 0) Map(4);
if (m[X][Y] >= 50 && m[X][Y] < 55) Jian(5), system("color 4F"), Sleep(30), system("color 0F"), Map(4);
if (m[X][Y] >= 4 && m[X][Y] <= 7 && F[12] == 0) Jian(3), system("color 4F"), Sleep(30), system("color 0F"), Map(4);
if (m[X][Y] >= 4 && m[X][Y] <= 7 && F[12] == 1) Jian(1), system("color 4F"), Sleep(30), system("color 0F"), Map(4);
if (m[X][Y] >= 59 && m[X][Y] <= 80 && F[4] == 0) Jian(1), system("color 4F"), Sleep(30), system("color 0F"), Map(4);
if (m[X][Y] == 2 && F[4] == 0) Jian(3), system("color 4F"), Sleep(30), system("color 0F"), Map(4);
if (m[X][Y] == 55) {
Jian(5); // 和普通怪一样造成5点伤害
system("color 4F");
Sleep(30);
system("color 0F");
Map(4);
}
m[X][Y] = 0, gx = gy = 0;
}
int Cout(int x, int i, int j) {
int Guai = 0;
if (m[i][j] == 0 && x == 2) SetPos(i, j), cout << " ";
if (m[i][j] == 1) SetPos(i, j), Map_Colors(7), cout << "■", Map_Colors(0); //木
if (n[i][j] == 0 && m[i][j] == 2) SetPos(i, j), Map_Colors(8), cout << "■", Map_Colors(0); //铁
if (n[i][j] == 10 && m[i][j] == 0) SetPos(i, j), cout << " ", Map_Colors(0);
if (n[i][j] == 31 && m[i][j] == 0) SetPos(i, j), cout << " ", Map_Colors(0);
if (m[i][j] == 32) m[i][j] = 0; //怪子弹灰
if (n[i][j] >= 20 && n[i][j] < 22 && m[i][j] == 1) SetPos(i, j), Map_Colors(7), cout << "▁", Map_Colors(0); //木
if (n[i][j] >= 22 && n[i][j] < 24 && m[i][j] == 1) SetPos(i, j), Map_Colors(7), cout << "▂", Map_Colors(0); //木
if (n[i][j] >= 24 && n[i][j] < 26 && m[i][j] == 1) SetPos(i, j), Map_Colors(7), cout << "▄", Map_Colors(0); //木
if (n[i][j] >= 26 && n[i][j] < 28 && m[i][j] == 1) SetPos(i, j), Map_Colors(7), cout << "▆", Map_Colors(0); //木
if (n[i][j] >= 28 && n[i][j] < 30 && m[i][j] == 1) SetPos(i, j), Map_Colors(7), cout << "▆", Map_Colors(0); //木
if (n[i][j] > 45 && n[i][j] <= 50 && m[i][j] == 2) SetPos(i, j), Map_Colors(4), cout << "▲", Map_Colors(0); //刺
if (m[i][j] == 3) SetPos(i, j), Map_Colors(5), cout << "〓", Map_Colors(0); //箱
if (m[i][j] >= 4 && m[i][j] <= 7) SetPos(i, j), Map_Colors(5), cout << "█", Map_Colors(0), m[i][j]++; //烟
if (m[i][j] == 8) SetPos(i, j), cout << " ", m[i][j] = 0; //烟尘
if (m[i][j] >= 84 && m[i][j] <= 87) SetPos(i, j), Map_Colors(5), cout << "█", Map_Colors(0), m[i][j]++; //烟
if (m[i][j] == 88) SetPos(i, j), cout << " ", m[i][j] = 0; //烟尘
if (m[i][j] >= 10 && m[i][j] <= 30) SetPos(i, j), Map_Colors(10), cout << "# ", Map_Colors(0), m[i][j]++; //毒
if (m[i][j] >= 60 && m[i][j] <= 80) SetPos(i, j), Map_Colors(11), cout << "# ", Map_Colors(0), m[i][j]++; //怪毒
if (m[i][j] == 9 || m[i][j] == 59) SetPos(i, j), Map_Colors(12), cout << "# ", Map_Colors(0), m[i][j]++; //金毒
if (m[i][j] == 31 || m[i][j] == 81) SetPos(i, j), cout << " ", m[i][j] = 0; //毒尘
if (n[i][j] == 1) SetPos(i, j), Map_Colors(13), cout << "~ ", Map_Colors(0); //水
if (m[i][j] == 50) SetPos(i, j), Map_Colors(1), cout << "●", Map_Colors(0), Guai++; // 普通怪
if (m[i][j] == 51) SetPos(i, j), Map_Colors(10), cout << "●", Map_Colors(0), Guai++; // 毒怪
if (m[i][j] == 52) SetPos(i, j), Map_Colors(3), cout << "●", Map_Colors(0), Guai++; // 散弹怪
if (m[i][j] == 53) SetPos(i, j), Map_Colors(4), cout << "●", Map_Colors(0), Guai++; // 狙击怪
if (m[i][j] == 54) SetPos(i, j), Map_Colors(5), cout << "●", Map_Colors(0), Guai++; // 激光怪
// 隐形怪
if (m[i][j] == 55) {
if (InvisibleMonsterVisible[i][j]) {
// 可见时显示为深灰色
SetPos(i, j), Map_Colors(13), cout << "●", Map_Colors(0), Guai++;
} else {
// 不可见时显示为非常淡的灰色(几乎看不见)
// SetPos(i, j);
// SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);
// cout << ". "; // 使用小点表示隐约可见的轮廓
// Map_Colors(0);
Guai++; // 仍然计入怪物数量
}
}
if (m[i][j] / 100 == 1) {
if ((m[i][j] % 100) / 10 <= 1) SetPos(i, j), cout << "☉";
if ((m[i][j] % 100) / 10 == 2) SetPos(i, j), Map_Colors(4), cout << "◎", Map_Colors(0);
if ((m[i][j] % 100) / 10 == 3) SetPos(i, j), Map_Colors(1), cout << "◎", Map_Colors(0);
if ((m[i][j] % 100) / 10 == 4) m[i][j] = 4;
if ((m[i][j] % 100) / 10 == 5) SetPos(i, j), Map_Colors(3), cout << "◎", Map_Colors(0);
if ((m[i][j] % 100) / 10 == 6) SetPos(i, j), Map_Colors(2), cout << "¤", Map_Colors(0);
if ((m[i][j] % 100) / 10 >= 7 && (m[i][j] % 100) / 10 <= 9) SetPos(i, j), Map_Colors(2), cout << "◎", Map_Colors(0);
}
if (m[i][j] / 100 == 2) if ((m[i][j] % 100) / 10 == 1) SetPos(i, j), Map_Colors(3), cout << "☉", Map_Colors(0);
return Guai;
}
void Boss() {
SetPos(Bx - 1, By - 1), cout << " ";
SetPos(Bx, By - 1), cout << " ";
SetPos(Bx + 1, By - 1), cout << " ";
int mov = rand() % 30 + 1, R = rand() % 300, ms;
if (mov == 1 && CanGo(Bx - 1, By - 2, 1) && CanGo(Bx, By - 2, 1) && CanGo(Bx + 1, By - 2, 1)) By--;
if (mov == 2 && CanGo(Bx - 1, By + 2, 1) && CanGo(Bx, By + 2, 1) && CanGo(Bx + 1, By + 2, 1)) By++;
if (mov == 3 && CanGo(Bx - 2, By - 1, 1) && CanGo(Bx - 2, By, 1) && CanGo(Bx - 2, By + 1, 1)) Bx--;
if (mov == 4 && CanGo(Bx + 2, By - 1, 1) && CanGo(Bx + 2, By, 1) && CanGo(Bx + 2, By + 1, 1)) Bx++;
if (mov == 5 && Boss_CrossBullet_CD == 0) Boss_CrossBullet_CD += rand() % 3 + 1;
if (mov == 6 && Boss_CornerBullet_CD == 0) Boss_CornerBullet_CD += rand() % 3 + 1;
if (mov == 7 && Boss_Poison_CD == 0) Boss_Poison_CD += 5;
if (mov == 8 && Bxz == 0) Bxz += rand() % 20 - 10;
if (mov == 9 && Byz == 0) Byz += rand() % 20 - 10;
if (Byz < 0) {
Byz++;
if (By - 2 > 1) By--;
}
if (Byz > 0) {
Byz--;
if (By + 2 < 28) By++;
}
if (Bxz < 0) {
Bxz++;
if (Bx - 2 > 1) Bx--;
}
if (Bxz > 0) {
Bxz--;
if (Bx + 2 < 28) Bx++;
}
if (R < 15 & Num_Monsters <= 5) Boss_Conjure_CD++;
else if (R < 5 && Num_Monsters <= 10) Boss_Conjure_CD++;
else if (R == 0) Boss_Conjure_CD++;
SetPos(Bx - 1, By - 1), Map_Colors(0), cout << " ●● ";
SetPos(Bx, By - 1), Map_Colors(4), cout << ">####<";
SetPos(Bx + 1, By - 1), Map_Colors(4), cout << " ^^^^ ";
Map_Colors(0);
if (abs(Bx - X) <= 1 && abs(By - Y) <= 1) Jian(50);
int I, J;
if (Boss_CrossBullet_CD > 0) {
Boss_CrossBullet_CD--;
I = Bx - 2, J = By + rand() % 3 - 1;
if (CanGo(I, J, 7)) m[I][J] = 211;
I = Bx + rand() % 3 - 1, J = By + 2;
if (CanGo(I, J, 7)) m[I][J] = 213;
I = Bx + 2, J = By + rand() % 3 - 1;
if (CanGo(I, J, 7)) m[I][J] = 215;
I = Bx + rand() % 3 - 1, J = By - 2;
if (CanGo(I, J, 7)) m[I][J] = 217;
}
if (Boss_CornerBullet_CD > 0) {
Boss_CornerBullet_CD--;
I = Bx - 2, J = By + 2;
if (CanGo(I, J, 7)) m[I][J] = 212;
I = Bx + 2, J = By + 2;
if (CanGo(I, J, 7)) m[I][J] = 214;
I = Bx + 2, J = By - 2;
if (CanGo(I, J, 7)) m[I][J] = 216;
I = Bx - 2, J = By - 2;
if (CanGo(I, J, 7)) m[I][J] = 218;
}
if (Boss_Poison_CD > 0) {
if (Boss_Poison_CD > 0) Boss_Poison_CD--;
for (int i = Bx - 4; i <= Bx + 4; i++) for (int j = By - 4; j <= By + 4; j++) if (CanGo(i, j, 2) && abs(Bx - X) > 1 && abs(By - Y) > 1 && i > 0 && j > 0) m[i][j] = 59;
}
if (Boss_Conjure_CD > 0) {
Boss_Conjure_CD--;
I = Bx + rand() % 5 - 2, J = By + rand() % 5 - 2;
int rr = rand() % 6 - 1;
if (rr == -1) rr = 0;
if (((rr < 3 && Lev < 5) || (Lev > 5)) && (CanGo(I, J, 7))) m[I][J] = 50 + rr;
}
if (Lev == 4) ms = 3;
if (Lev == 9) ms = 5;
if (Lev == 14) ms = 10;
if (Lev == 19) ms = 15;
if (Lev == 24) ms = 20;
if (T % 50 == 0 && Boss_HP < ms * 12) Boss_HP++, Map(3);
// 处理BOSS被子弹击中的金钱奖励
for (int i = Bx - 1; i <= Bx + 1; i++) {
for (int j = By - 1; j <= By + 1; j++) {
int du = 0;
if (m[i][j] / 100 == 1) {
int oldBossHP = Boss_HP;
Boss_HP -= 1, Boss_CrossBullet_CD += rand() % 3 + 1, Map(3);
// 如果BOSS死亡,给予金钱奖励
if (Boss_HP <= 0 && oldBossHP > 0) {
Money += ms * MONEY_BOSS_PER_BAR;
}
}
if (m[i][j] / 10 == 15) {
int oldBossHP = Boss_HP;
Boss_HP -= 2, Map(3);
// 如果BOSS死亡,给予金钱奖励
if (Boss_HP <= 0 && oldBossHP > 0) {
Money += ms * MONEY_BOSS_PER_BAR;
}
}
if (m[i][j] < 50 || m[i][j] > 55) m[i][j] = 0;
if (m[i][j] >= 84 && m[i][j] <= 87) {
int oldBossHP = Boss_HP;
Boss_HP -= 1, Boss_CrossBullet_CD += rand() % 3 + 1, Map(3);
// 如果BOSS死亡,给予金钱奖励
if (Boss_HP <= 0 && oldBossHP > 0) {
Money += ms * MONEY_BOSS_PER_BAR;
}
}
if (du == 0 && m[i][j] >= 9 && m[i][j] <= 30) {
int oldBossHP = Boss_HP;
Boss_HP -= 1, du++, Boss_Poison_CD++, Map(3);
// 如果BOSS死亡,给予金钱奖励
if (Boss_HP <= 0 && oldBossHP > 0) {
Money += ms * MONEY_BOSS_PER_BAR;
}
}
if (Boss_HP <= 0) {
Boss_HP = 0;
SetPos(Bx - 1, By - 1), cout << " ";
SetPos(Bx, By - 1), cout << " ";
SetPos(Bx + 1, By - 1), cout << " ";
}
}
}
}
void Map(int x) {
if (x != 4) CoutMe();
int f1, f2, f3, f4, Guai = 0;
if (x == 0) f1 = f3 = 2, f2 = f4 = 38;
if (x == 1 ) f1 = f3 = 1, f2 = f4 = 39;
if (x == 2) f1 = X - 1, f2 = X + 1, f3 = Y - 1, f4 = Y + 1;
if (f1 < 1) f1 = 1;
if (f2 > 39) f2 = 39;
if (f3 < 1) f3 = 1;
if (f4 > 39) f4 = 39;
if ((x == 4 || x == 3 || x == 1) && Win >= 0) {
// 修改Map()函数中的武器显示部分
SetPos(44, 2), cout << " 武器: ";
if (Gun_type == 1) cout << "制式突击步枪";
if (Gun_type == 2) cout << "破片弹投射器";
if (Gun_type == 3) cout << "反掩体重型狙";
if (Gun_type == 4) cout << "量子穿透利刃";
if (Gun_type == 5) cout << "RPG-01火箭筒";
if (Gun_type == 6) cout << "便携式毒气炮";
if (Gun_type == 7) cout << "史莱姆发射器";
if (Gun_type == 8) cout << "龙血骨钢长剑"; // 改为龙血骨钢长剑
cout << " 弹药:";
if (Gun_type == 1) cout << "∞";
else if (Gun_type == 8) cout << "∞"; // 剑也是无限的
else cout << G[Gun_type] << " ";
// 添加金钱显示
SetPos(45, 2);
Map_Colors(5); // 金色
cout << " 金钱: " << Money << "$ (可能没法及时显示,但关卡结束会一并返还)";
Map_Colors(0);
SetPos(41, 2), cout << " HP:";
Map_Colors(4);
int r;
if (Unable_To_Be_Attacked > 0) r = rand() % 5 + 1, Map_Colors(r);
for (int i = 1; i <= HP_Player; i++) cout << "█";
Map_Colors(0);
for (int i = HP_Player; i < MaxHP_Player; i++) cout << "█";
Map_Colors(0);
SetPos(42, 2), cout << " DE:";
Map_Colors(9);
if (DE_Player != 0) for (int i = 1; i <= DE_Player; i++) cout << "█";
Map_Colors(0);
for (int i = max(1, DE_Player); i < MaxDE_Player; i++) cout << "█";
// 显示关卡信息
SetPos(-2, 5), cout << " 关卡: " << Lev / 5 + 1 << " - " << Lev % 5 + 1;
int count = 0;
for (int i = 2; i <= 38; i++) {
for (int j = 2; j <= 38; j++) {
if (m[i][j] >= 50 && m[i][j] <= 54) {
count++;
}
}
}
// 如果是BOSS关,加上BOSS
if (Boss_HP > 0) {
count++;
}
Num_Monsters = count;
SetPos(-1, 5), cout << " 剩余怪物:" << Num_Monsters;
if (Boss_HP > 0) {
int ms;
if (Lev == 4) ms = 3;
if (Lev == 9) ms = 5;
if (Lev == 14) ms = 10;
if (Lev == 19) ms = 15;
if (Lev == 24) ms = 20;
// BOSS血量显示在右侧
SetPos(-3, 15), cout << "BOSS血条:";
Map_Colors(4);
SetPos(-3, 15), cout << " ";
Map_Colors(4);
for (int i = 1; i <= 12; i++) {
if ((i <= Boss_HP % 12) || (Boss_HP / 12 != 0 && Boss_HP % 12 == 0) ) {
Map_Colors(4);
cout << "█";
} else {
Map_Colors(0);
cout << "█";
}
}
Map_Colors(4);
SetPos(-2, 20), cout << " 血条数: " << (Boss_HP - 1) / 12 + 1 << " / " << ms;
Map_Colors(0);
}
}
if (x != 3 && x != 4) {
for (int i = f1; i <= f2; i++)
for (int j = f3; j <= f4; j++) Guai += Cout(x, i, j);
if (x != 2) {
int Rr = rand() % 3;
if (Guai < Num_Monsters && Guai != 0 && F[15] == 1 && Rr == 0 && Lev % 5 == 4)
DE_Player = min(MaxDE_Player, DE_Player + 1), Map(3);
Num_Monsters = Guai;
}
if (Guai == 0 && x == 0 && Win == 0 && Boss_HP <= 0) {
bccd();
if (Lev != 24) {
system("color 6E"), Map_Colors(5);
SetPos(2, 2), cout << "You! Win!!!";
Sleep(500);
SetPos(3, 2), cout << "Please point 'y' to Play AGain.", Sleep(1000);
system("color 0F");
Map(1);
}
Win++, Lev++;
}
}
}
void Slime_Bounce(int i, int j, int M) {
if (M % 10 == 1 || M % 10 == 3) m[i][j] = M + 4;
if (M % 10 == 5 || M % 10 == 7) m[i][j] = M - 4;
if (M % 10 == 2) {
if (m[i][j + 1] != 0 || m[i - 2][j + 1] != 0) m[i][j] = M + 6;
else if (m[i - 1][j] != 0 || m[i - 1][j + 2] != 0) m[i][j] = M + 2;
else m[i][j] = M + 4;
}
if (M % 10 == 4) {
if (m[i + 1][j] != 0 || m[i + 1][j + 2] != 0) m[i][j] = M - 2;
else if (m[i][j + 1] != 0 || m[i + 2][j + 1] != 0) m[i][j] = M + 2;
else m[i][j] = M + 4;
}
if (M % 10 == 6) {
if (m[i][j - 1] != 0 || m[i + 2][j - 1] != 0) m[i][j] = M - 2;
else if (m[i + 1][j] != 0 || m[i + 1][j - 2] != 0) m[i][j] = M + 2;
else m[i][j] = M - 4;
}
if (M % 10 == 8) {
if (m[i][j - 1] != 0 || m[i - 2][j - 1] != 0) m[i][j] = M - 6;
else if (m[i - 1][j] != 0 || m[i - 1][j - 2] != 0) m[i][j] = M - 2;
else m[i][j] = M - 4;
}
}
void Laser_Drawing(int i, int j, int M, int x) {
if (M % 10 == 1) for (int k = 1; CanGo(i - k, j, x); k++) {
if (x == 3) m[i - k][j] = 84;
else m[i - k][j] = 4;
}
if (M % 10 == 2) for (int k = 1; CanGo(i - k, j + k, x); k++) {
if (x == 3) m[i - k][j + k] = 84;
else m[i - k][j + k] = 4;
}
if (M % 10 == 3) for (int k = 1; CanGo(i, j + k, x); k++) {
if (x == 3) m[i][j + k] = 84;
else m[i][j + k] = 4;
}
if (M % 10 == 4) for (int k = 1; CanGo(i + k, j + k, x); k++) {
if (x == 3) m[i + k][j + k] = 84;
else m[i + k][j + k] = 4;
}
if (M % 10 == 5) for (int k = 1; CanGo(i + k, j, x); k++) {
if (x == 3) m[i + k][j] = 84;
else m[i + k][j] = 4;
}
if (M % 10 == 6) for (int k = 1; CanGo(i + k, j - k, x); k++) {
if (x == 3) m[i + k][j - k] = 84;
else m[i + k][j - k] = 4;
}
if (M % 10 == 7) for (int k = 1; CanGo(i, j - k, x); k++) {
if (x == 3) m[i][j - k] = 84;
else m[i][j - k] = 4;
}
if (M % 10 == 8) for (int k = 1; CanGo(i - k, j - k, x); k++) {
if (x == 3) m[i - k][j - k] = 84;
else m[i - k][j - k] = 4;
}
}
void Move() {
bool nx[42][42];
memset(nx, 0, sizeof(nx));
ProcessMonsters(nx);
// 原有的子弹处理逻辑保持不变
for (int i = 2; i <= 38; i++) {
for (int j = 2; j <= 38; j++) {
if (m[i][j] / 100 == 2 && F[3] == 1 && T % 2 == 0) nx[i][j] = 1;
if ((m[i][j] / 100 == 1 || m[i][j] / 100 == 2) && nx[i][j] == 0) { //子弹
int M = m[i][j], I, J;
m[i][j] = 0;
SetPos(i, j), cout << " ";
if (M % 10 == 1) I = i - 1, J = j;
if (M % 10 == 2) I = i - 1, J = j + 1;
if (M % 10 == 3) I = i, J = j + 1;
if (M % 10 == 4) I = i + 1, J = j + 1;
if (M % 10 == 5) I = i + 1, J = j;
if (M % 10 == 6) I = i + 1, J = j - 1;
if (M % 10 == 7) I = i, J = j - 1;
if (M % 10 == 8) I = i - 1, J = j - 1;
if (I == X && J == Y && M / 100 == 2) {
Jian(2), system("color 4F"), Sleep(30);
system("color 0F"), m[i][j] = 0;
Map(4);
} else if (I == X && J == Y && M / 100 == 1) m[I][J] = 0;
else if (M / 100 == 2 && m[I][J] / 100 == 1) m[i][j] = 32;
else if (M / 100 == 2 && m[I][J] < 55 && m[I][J] >= 50) m[i][j] = 0;
else if (m[I][J] == 2 || m[I][J] == 3) { //石
if ((M % 100) / 10 == 0) {
int rr = rand() % 3;
if (rr == 0) Slime_Bounce(i, j, M), m[i][j] += 10;
else m[i][j] = 84;
}
if ((M % 100) / 10 == 1) {
m[i][j] = 84;
int rr = rand() % 5;
if (rr == 0 && F[14] == 1 && M / 100 == 1) {
for (int ii = i - 1; ii <= i + 1; ii++)
for (int jj = j - 1; jj <= j + 1; jj++)
if (m[ii][jj] != 2 && m[ii][jj] != 3 && ii <= 28 && jj <= 28) m[ii][jj] = 84;
}
}
if ((M % 100) / 10 == 2) {
m[i][j] = 84;
if (m[i - 1][j] != 2 && m[i - 1][j] != 3) m[i - 1][j] = 111;
if (m[i - 1][j + 1] != 2 && m[i - 1][j + 1] != 3) m[i - 1][j + 1] = 112;
if (m[i][j + 1] != 2 && m[i][j + 1] != 3) m[i][j + 1] = 113;
if (m[i + 1][j + 1] != 2 && m[i + 1][j + 1] != 3) m[i + 1][j + 1] = 114;
if (m[i + 1][j] != 2 && m[i + 1][j] != 3) m[i + 1][j] = 115;
if (m[i + 1][j - 1] != 2 && m[i + 1][j - 1] != 3) m[i + 1][j - 1] = 116;
if (m[i][j - 1] != 2 && m[i][j - 1] != 3) m[i][j - 1] = 117;
if (m[i - 1][j - 1] != 2 && m[i - 1][j - 1] != 3) m[i - 1][j - 1] = 118;
}
if ((M % 100) / 10 == 3) {
if (m[I][J] == 2 && (I != 1 && J != 1 && I != 29 && J != 29)) m[I][J] = 84;
else m[i][j] = 84;
}
if ((M % 100) / 10 == 4) m[i][j] = 84;
if ((M % 100) / 10 == 5) {
for (int ii = i - 2; ii <= i + 2; ii++)
for (int jj = j - 2; jj <= j + 2; jj++)
if (m[ii][jj] != 2 && m[ii][jj] != 3 && ii <= 28 && jj <= 28) m[ii][jj] = 84;
}
if ((M % 100) / 10 == 6) {
for (int ii = i - 1; ii <= i + 1; ii++)
for (int jj = j - 1; jj <= j + 1; jj++)
if (m[ii][jj] != 2 && m[ii][jj] != 3 && ii <= 28 && jj <= 28) m[ii][jj] = 9;
}
if ((M % 100) / 10 >= 7 && (M % 100) / 10 < 9) Slime_Bounce(i, j, M), m[i][j] += (rand() % 2) * 10;
if ((M % 100) / 10 == 9) m[i][j] = 84;
} else if (!CanGo(I, J, 6)) {
// 这里是子弹击中怪物或障碍物的处理
// 首先检查是否击中了怪物
if (m[I][J] >= 50 && m[I][J] <= 55) {
// 击中怪物,给予金钱奖励
switch (m[I][J]) {
case 50: // 无脑怪
Money += MONEY_DUMB_MONSTER;
break;
case 51: // 毒怪
Money += MONEY_POISON_MONSTER;
break;
case 52: // 散射怪
Money += MONEY_SHOTGUN_MONSTER;
break;
case 53: // 狙击怪
Money += MONEY_SNIPER_MONSTER;
break;
case 54: // 激光怪
Money += MONEY_LASER_MONSTER;
break;
case 55: // 隐形怪
Money += MONEY_INVISIBLE_MONSTER;
break;
}
}
// 然后根据子弹类型处理击中效果
if ((M % 100) / 10 == 0) {
m[I][J] = 84, Slime_Bounce(i, j, M), m[i][j] += 10;
}
if ((M % 100) / 10 == 1) {
if (M / 100 == 2 && m[I][J] == 50) m[i][j] = 0;
else m[I][J] = 84;
if (F[14] == 1 && M / 100 == 1) {
for (int ii = I - 1; ii <= I + 1; ii++)
for (int jj = J - 1; jj <= J + 1; jj++)
if (m[ii][jj] != 2 && m[ii][jj] != 3 && ii <= 28 && jj <= 28) m[ii][jj] = 84;
}
}
if ((M % 100) / 10 == 2) {
m[I][J] = 84;
if (m[I - 1][J] != 2 && m[I - 1][J] != 3) m[I - 1][J] = 111;
if (m[I - 1][J + 1] != 2 && m[I - 1][J + 1] != 3) m[I - 1][J + 1] = 112;
if (m[I][J + 1] != 2 && m[I][J + 1] != 3) m[I][J + 1] = 113;
if (m[I + 1][J + 1] != 2 && m[I + 1][J + 1] != 3) m[I + 1][J + 1] = 114;
if (m[I + 1][J] != 2 && m[I + 1][J] != 3) m[I + 1][J] = 115;
if (m[I + 1][J - 1] != 2 && m[I + 1][J - 1] != 3) m[I + 1][J - 1] = 116;
if (m[I][J - 1] != 2 && m[I][J - 1] != 3) m[I][J - 1] = 117;
if (m[I - 1][J - 1] != 2 && m[I - 1][J - 1] != 3) m[I - 1][J - 1] = 118;
}
if ((M % 100) / 10 == 3) m[I][J] = M, nx[I][J] = 1;
if ((M % 100) / 10 == 4) Laser_Drawing(i, j, M, 3);
if ((M % 100) / 10 == 5) {
for (int ii = I - 2; ii <= I + 2; ii++)
for (int jj = J - 2; jj <= J + 2; jj++)
if (m[ii][jj] != 2 && m[ii][jj] != 3 && ii <= 28 && jj <= 28) m[ii][jj] = 84;
}
if ((M % 100) / 10 == 6) {
for (int ii = I - 1; ii <= I + 1; ii++)
for (int jj = J - 1; jj <= J + 1; jj++)
if (m[ii][jj] != 2 && m[ii][jj] != 3 && ii <= 28 && jj <= 28) m[ii][jj] = 9;
}
if ((M % 100) / 10 >= 7 && (M % 100) / 10 < 9) m[I][J] = 84, Slime_Bounce(i, j, M);
if ((M % 100) / 10 == 9) m[I][J] = 84;
} else { //空地
if ((M % 100) / 10 == 6) {
m[i][j] = 9;
if (CanGo(i, j - 1, 5)) m[i][j - 1] = 9;
if (CanGo(i, j + 1, 5)) m[i][j + 1] = 9;
if (CanGo(i - 1, j, 5)) m[i - 1][j] = 9;
if (CanGo(i - 1, j, 5)) m[i + 1][j] = 9;
m[I][J] = M, nx[I][J] = 1;
}
if ((M % 100) / 10 == 4) m[i][j] = 84, m[I][J] = M, i = 2, j = 2;
else m[I][J] = M, nx[I][J] = 1;
}
}
}
}
if (Boss_HP > 0) Boss();
}
void Bullet() {
int I = 0, J = 0, R = rand() % 10, Rr = rand() % 3, Rrr, K = 0, tg = Muzzle;
// 如果是龙血骨钢长剑,执行近战攻击
if (Gun_type == 8) {
// 计算攻击范围(面前5x3区域)
int killCount = 0;
int bossDamage = 0; // 用于计算对BOSS的伤害
// 根据枪口方向确定攻击范围和方向
int startX, startY, endX, endY;
switch (Muzzle) {
case 1: // 上
startX = X - 5;
endX = X - 1;
startY = Y - 1;
endY = Y + 1;
break;
case 2: // 右上
startX = X - 5;
endX = X - 1;
startY = Y + 1;
endY = Y + 5;
break;
case 3: // 右
startX = X - 1;
endX = X + 1;
startY = Y + 1;
endY = Y + 5;
break;
case 4: // 右下
startX = X + 1;
endX = X + 5;
startY = Y + 1;
endY = Y + 5;
break;
case 5: // 下
startX = X + 1;
endX = X + 5;
startY = Y - 1;
endY = Y + 1;
break;
case 6: // 左下
startX = X + 1;
endX = X + 5;
startY = Y - 5;
endY = Y - 1;
break;
case 7: // 左
startX = X - 1;
endX = X + 1;
startY = Y - 5;
endY = Y - 1;
break;
case 8: // 左上
startX = X - 5;
endX = X - 1;
startY = Y - 5;
endY = Y - 1;
break;
}
// 确保坐标在合理范围内
startX = max(2, startX);
endX = min(38, endX);
startY = max(2, startY);
endY = min(38, endY);
// 确保startX <= endX, startY <= endY
if (startX > endX) {
int temp = startX;
startX = endX;
endX = temp;
}
if (startY > endY) {
int temp = startY;
startY = endY;
endY = temp;
}
// 显示剑击效果 - 先显示剑锋轨迹
for (int step = 1; step <= 5; step++) {
int centerX, centerY;
switch (Muzzle) {
case 1:
centerX = X - step;
centerY = Y;
break; // 上
case 2:
centerX = X - step;
centerY = Y + step;
break; // 右上
case 3:
centerX = X;
centerY = Y + step;
break; // 右
case 4:
centerX = X + step;
centerY = Y + step;
break; // 右下
case 5:
centerX = X + step;
centerY = Y;
break; // 下
case 6:
centerX = X + step;
centerY = Y - step;
break; // 左下
case 7:
centerX = X;
centerY = Y - step;
break; // 左
case 8:
centerX = X - step;
centerY = Y - step;
break; // 左上
}
}
Sleep(30); // 短暂显示剑轨迹
// 显示完整的5x3区域攻击效果
for (int i = startX; i <= endX; i++) {
for (int j = startY; j <= endY; j++) {
SetPos(i, j);
Map_Colors(4); // 红色表示剑击
cout << "╳";
}
}
for (int i = startX; i <= endX; i++) {
for (int j = startY; j <= endY; j++) {
if (i >= 2 && i <= 38 && j >= 2 && j <= 38) {
// 判断是否可破坏
if (m[i][j] >= 50 && m[i][j] <= 55) {
// 杀死怪物并给予金钱(长剑攻击杀死怪物)
switch (m[i][j]) {
case 50: // 无脑怪
Money += MONEY_DUMB_MONSTER;
break;
case 51: // 毒怪
Money += MONEY_POISON_MONSTER;
break;
case 52: // 散射怪
Money += MONEY_SHOTGUN_MONSTER;
break;
case 53: // 狙击怪
Money += MONEY_SNIPER_MONSTER;
break;
case 54: // 激光怪
Money += MONEY_LASER_MONSTER;
break;
case 55: // 隐形怪(如果被长剑击杀)
Money += MONEY_INVISIBLE_MONSTER;
break;
}
m[i][j] = 84; // 烟尘效果
killCount++;
} else if (m[i][j] == 1) { // 木墙
// 破坏木墙
m[i][j] = 84; // 烟尘效果
} else if (m[i][j] >= 4 && m[i][j] <= 7) { // 烟雾
m[i][j] = 84; // 清烟
}
}
}
}
// BOSS被长剑击中的处理
if (Boss_HP > 0) {
// 检查剑的攻击范围是否与BOSS的3x3区域重叠
int bossLeft = Bx - 1;
int bossRight = Bx + 1;
int bossTop = By - 1;
int bossBottom = By + 1;
// 检查是否有重叠
bool hitBoss = false;
if (startX <= bossRight && endX >= bossLeft &&
startY <= bossBottom && endY >= bossTop) {
hitBoss = true;
}
// 如果攻击到BOSS,造成伤害
if (hitBoss) {
bossDamage = 1; // 每次攻击造成1点伤害
int oldBossHP = Boss_HP;
Boss_HP = max(0, Boss_HP - bossDamage);
// 如果BOSS死亡,给予金钱奖励
if (Boss_HP <= 0 && oldBossHP > 0) {
int ms;
if (Lev == 4) ms = 3;
else if (Lev == 9) ms = 5;
else if (Lev == 14) ms = 10;
else if (Lev == 19) ms = 15;
else if (Lev == 24) ms = 20;
else ms = Lev / 5 + 1;
Money += ms * MONEY_BOSS_PER_BAR;
}
for (int i = bossLeft; i <= bossRight; i++) {
for (int j = bossTop; j <= bossBottom; j++) {
if (i >= startX && i <= endX && j >= startY && j <= endY) {
}
}
}
// 更新BOSS显示
Map(3);
}
}
// 短暂延迟后清除剑击效果
Sleep(50);
for (int i = startX; i <= endX; i++) {
for (int j = startY; j <= endY; j++) {
if (i >= 2 && i <= 38 && j >= 2 && j <= 38) {
SetPos(i, j);
// 恢复原来的显示
if (m[i][j] == 0) {
cout << " ";
}
}
}
}
Map_Colors(0);
if (killCount > 0) {
DE_Player = min(MaxDE_Player, DE_Player + killCount);
Map(3); // 更新显示
}
Map(3);
return;
}
Hh:
Rrr = rand() % 20;
if (Muzzle == 1 && m[X - 1][Y] != 2 && m[X - 1][Y] != 3) I = X - 1, J = Y;
if (Muzzle == 2 && m[X - 1][Y + 1] != 2 && m[X - 1][Y + 1] != 3) I = X - 1, J = Y + 1;
if (Muzzle == 3 && m[X][Y + 1] != 2 && m[X][Y + 1] != 3) I = X, J = Y + 1;
if (Muzzle == 4 && m[X + 1][Y + 1] != 2 && m[X + 1][Y + 1] != 3) I = X + 1, J = Y + 1;
if (Muzzle == 5 && m[X + 1][Y] != 2 && m[X + 1][Y] != 3) I = X + 1, J = Y;
if (Muzzle == 6 && m[X + 1][Y - 1] != 2 && m[X + 1][Y - 1] != 3) I = X + 1, J = Y - 1;
if (Muzzle == 7 && m[X][Y - 1] != 2 && m[X][Y - 1] != 3) I = X, J = Y - 1;
if (Muzzle == 8 && m[X - 1][Y - 1] != 2 && m[X - 1][Y - 1] != 3) I = X - 1, J = Y - 1;
if (I != 0 && J != 0) m[I][J] = 100 + 10 * Gun_type + Muzzle;
if (K == 1) m[I][J] = 110 + Muzzle;
if (F[2] == 1 && Gun_type == 1) m[I][J] = 100 + Muzzle;
if (F[8] == 1 && R == 0 && K == 0) {
Muzzle = rand() % 8 + 1;
K = 1;
goto Hh;
}
if (F[8] == 1 && K != 0 && K < Rr) {
Muzzle = rand() % 8 + 1;
K++;
goto Hh;
}
if (K >= Rr) Muzzle = tg;
if (Rrr == 0 && F[11] == 1 && K == 0) {
m[I][J] = 100 + 10 * (rand() % 7 + 1) + Muzzle;
}
if (Gun_type != 1 && Gun_type != 8) {
G[Gun_type]--;
if (G[Gun_type] <= 0) G[Gun_type] = 0, Gun_type = 1;
Map(3);
}
}
void SwitchGun() {
int startGun = Gun_type;
int nextGun = Gun_type;
do {
nextGun++;
if (nextGun > 8) nextGun = 1;
if (nextGun == 1 || nextGun == 8) {
Gun_type = nextGun;
Map(3);
return;
}
if (G[nextGun] > 0) {
Gun_type = nextGun;
Map(3);
return;
}
} while (nextGun != startGun);
Gun_type = 1;
Map(3);
}
void OpenBox(int a) {
for (int i = X - 1; i <= X + 1; i++)
for (int j = Y - 1; j <= Y + 1; j++)
if (m[i][j] == 3) {
int r = rand() % 8 + 2;
if (a == 1) r = rand() % 6 + 2;
if (F[9] == 1) r = rand() % 12 + 2;
SetPos(i, j);
Map_Colors(5);
if (r == 2) cout << "破片弹投射器!";
if (r == 3) cout << "反掩体重型狙!";
if (r == 4) cout << "量子穿透利刃!";
if (r == 5) cout << "RPG-01火箭筒!";
if (r == 6) cout << "便携式毒气炮!";
if (r == 7) cout << "史莱姆发射器!";
if (r == 8) cout << "肾上腺素!", HP_Player += 5, MaxHP_Player += 2, Map(3);
if (r == 9) cout << "高级护甲!", DE_Player += 5, MaxDE_Player += 2, Map(3);
if (F[9] == 1 && r >= 8 && r <= 13) cout << "肾上腺素!", HP_Player += 5, MaxHP_Player += 2, Map(3);
Sleep(1000);
m[i][j] = 84;
if (r <= 7 && F[6] == 0) G[r] += 10;
if (r <= 7 && F[6] == 1) G[r] += 20;
SetPos(i, j);
cout << " ";
Map(0);
}
}
void Sheng() {
memset(m, 0, sizeof(m));
memset(n, 0, sizeof(n));
int q = 0, T = 0, II = 0, JJ = 0;
Re:
q++;
int r = rand() % 20 + 1; // 增加更多地图类型
if (F[19] == 1) r = rand() % 25 + 1; // 增加更多地图类型
if (r == 1) {
for (int i = 8; i <= 10; i++)for (int j = 8; j <= 10; j++) m[i][j] = 2;
for (int i = 30; i <= 32; i++)for (int j = 8; j <= 10; j++) m[i][j] = 2;
for (int i = 8; i <= 10; i++)for (int j = 30; j <= 32; j++) m[i][j] = 2;
for (int i = 30; i <= 32; i++)for (int j = 30; j <= 32; j++) m[i][j] = 2;
}
if (r == 2) {
for (int i = 18; i <= 22; i++) for (int j = 18; j <= 22; j++) m[i][j] = 1;
}
if (r == 3) {
for (int i = 2; i <= 38; i++) m[i][10] = m[i][30] = m[10][i] = m[30][i] = 1; // 调整位置
}
if (r == 4) {
for (int i = 2; i <= 38; i++) m[i][20] = m[20][i] = 1; // 调整位置
}
if (r == 5) {
for (int i = 2; i <= 38; i++) if (abs(i - 20) >= 5) m[i][20] = m[20][i] = 2; // 调整位置
}
if (r == 6) {
for (int i = 2; i <= 38; i++) for (int j = 2; j <= 38; j++) if (i == j || i + j == 40) m[i][j] = 1; // 调整对角线
}
if (r == 7) {
for (int i = 2; i <= 38; i++) for (int j = 2; j <= 38; j++) if (abs(i - 20) + abs(j - 20) == 15) m[i][j] = 1; // 调整菱形
}
if (r == 8) {
for (int i = 8; i <= 32; i++) if (abs(i - 20) >= 3) m[i][13] = m[i][27] = m[13][i] = m[27][i] = 2; // 调整位置
}
if (r == 9) {
for (int i = 2; i <= 38; i++) for (int j = 2; j <= 38; j++) {
int rr = rand() % 25; // 调整密度
if (rr == 0 && m[i][j] == 0) m[i][j] = 1;
}
}
if (r >= 10 && II == 0) {
T--;
int ii = rand() % 35 + 3; // 调整范围
int jj = rand() % 35 + 3; // 调整范围
for (int i = ii - 1; i <= ii + 1; i++) for (int j = jj - 1; j <= jj + 1; j++) if (m[i][j] == 0) m[i][j] = 1;
II = ii, JJ = jj;
}
if (r >= 10 && II != 0) goto Re;
T++;
if (T == 1) goto Re;
if (II != 0) m[II][JJ] = 3;
r = rand() % 20 + 1;
if (r == 1) {
for (int i = 5; i <= 35; i++) n[i][8] = n[i][15] = n[i][22] = n[i][29] = n[i][36] = 31; // 调整位置
}
if (r == 2) {
for (int i = 10; i <= 30; i++) n[i][10] = n[i][30] = n[10][i] = n[30][i] = 31; // 调整位置
}
if (r == 3) {
for (int i = 1; i <= 7; i++) { // 增加数量
int ii = rand() % 33 + 4, jj = rand() % 33 + 4; // 调整范围
for (int ki = ii - 3; ki <= ii + 3; ki++)for (int kj = jj - 3; kj <= jj + 3; kj++) if (abs(ki - X) > 3 || abs(kj - Y) > 3) n[ki][kj] = 1; // 调整范围
}
}
if (r == 4) {
for (int i = 1; i <= 7; i++) {
int ii = rand() % 33 + 4, jj = rand() % 33 + 4;
for (int ki = ii - 1; ki <= ii + 1; ki++)
for (int kj = jj - 1; kj <= jj + 1; kj++)
n[ki][kj] = 11;
}
}
if (r == 5) {
for (int i = 1; i <= 30; i++) {
int ii = rand() % 33 + 4, jj = rand() % 20 + 1; // 调整随机范围
jj *= 2;
// 确保不超过边界
if (jj + 1 <= 38) {
for (int ki = max(2, ii - 1); ki <= min(38, ii + 1); ki++)
n[jj + 1][ki] = 31;
}
}
}
if (r == 6) {
for (int i = 2; i <= 38; i++)
n[i][12] = n[i][13] = n[i][20] = n[i][21] = n[i][28] = n[i][29] = 11;
}
if (r == 7) {
for (int i = 5; i <= 35; i++)
n[8][i] = n[15][i] = n[22][i] = n[29][i] = n[36][i] = 31;
}
if (r == 8) {
for (int i = 10; i <= 30; i++)
for (int j = 10; j <= 30; j++)
if (i == j || i + j == 40) n[i][j] = 31;
}
if (r == 9) {
for (int i = 2; i <= 38; i++) {
if (i != 8 && i != 32 && !(i == Y && (19 <= X && 21 >= X))) {
n[19][i] = n[20][i] = n[21][i] = 1;
m[19][i] = m[20][i] = m[21][i] = 0;
}
}
}
if (r == 10) {
for (int i = 10; i <= 30; i++)
if (abs(i - 20) > 1)
n[i][10] = n[i][30] = n[10][i] = n[30][i] = 1;
}
guai:
int k = 0, K[45][45];
memset(K, 0, sizeof(K));
if (Lev % 5 != 4) {
for (int i = 2; i <= 38; i++) {
for (int j = 2; j <= 38; j++) {
if (Lev <= 1) {
int r = rand() % 250;
if (r == 0) K[i][j] = 50, k++; // 普通怪
} else if (Lev <= 3) {
int r = rand() % 300;
if (r == 0) K[i][j] = 50;
if (r == 1) K[i][j] = 51;
if (r <= 1) k++;
} else if (Lev <= 5) {
int r = rand() % 320;
if (r == 0) K[i][j] = 50;
if (r == 1) K[i][j] = 51;
if (r == 2) K[i][j] = 52;
if (r == 3) K[i][j] = 55;
if (r <= 3) k++;
} else if (Lev <= 8) {
int r = rand() % 420;
if (r == 0) K[i][j] = 50;
if (r == 1) K[i][j] = 51;
if (r == 2) K[i][j] = 52;
if (r == 3) K[i][j] = 53;
if (r == 4) K[i][j] = 55;
if (r <= 4) k++;
} else if (Lev <= 12) {
int r = rand() % 490;
if (r == 0) K[i][j] = 50;
if (r == 1) K[i][j] = 51;
if (r == 2) K[i][j] = 52;
if (r == 3) K[i][j] = 53;
if (r == 4) K[i][j] = 54;
if (r == 5) K[i][j] = 55;
if (r <= 5) k++;
} else {
int r;
if (Lev <= 15) r = rand() % 450;
if (Lev <= 20) r = rand() % 420;
if (Lev <= 25) r = rand() % 380;
if (r == 0) K[i][j] = 50;
if (r == 1) K[i][j] = 51;
if (r == 2) K[i][j] = 52;
if (r == 3) K[i][j] = 53;
if (r == 4) K[i][j] = 54;
if (r == 5) K[i][j] = 55;
if (r <= 5) k++;
}
}
}
// 怪物数量阈值
if (k < 5) goto guai;
if (k > 5 && Lev <= 3) goto guai;
if (k < 8 && Lev >= 10) goto guai;
if (k > 10 && Lev <= 10) goto guai;
if (k > 15 && Lev <= 15) goto guai;
if (k < 20 && Lev >= 20) goto guai;
if (k > 25 && Lev <= 20) goto guai;
}
for (int i = 2; i <= 38; i++) for (int j = 2; j <= 38; j++) {
if (n[i][j] != 0) m[i][j] = 0;
if (K[i][j] != 0 && (m[i - 1][j] != 2 || m[i + 1][j] != 2 || m[i][j - 1] != 2 || m[i][j + 1] != 2)) m[i][j] = K[i][j];
}
if (Lev % 5 == 4) {
int ms;
if (Lev == 4) ms = 3;
if (Lev == 9) ms = 5;
if (Lev == 14) ms = 10;
if (Lev == 19) ms = 15;
if (Lev == 24) ms = 20;
Bx = rand() % 30 + 6;
By = rand() % 30 + 6;
Boss_HP = ms * 12;
Boss_CrossBullet_CD = Boss_CornerBullet_CD = Boss_Poison_CD = Boss_Conjure_CD = 0;
Bxz = Byz = 0;
while ((abs(Bx - X) < 8 && abs(By - Y) < 8)) {
Bx = rand() % 30 + 6;
By = rand() % 30 + 6;
}
for (int i = max(2, Bx - 2); i <= min(38, Bx + 2); i++) {
for (int j = max(2, By - 2); j <= min(38, By + 2); j++) {
m[i][j] = 0;
n[i][j] = 0;
}
}
}
for (int i = X - 1; i <= X + 1; i++) for (int j = Y - 1; j <= Y + 1; j++) if (i != 1 && i != 39 && j != 1 && j != 39) m[i][j] = 0;
for (int i = 1; i <= 39; i++) m[1][i] = 2, m[39][i] = 2;
for (int i = 1; i <= 39; i++) m[i][1] = 2, m[i][39] = 2;
}
void Talent() {
int A[5], ss = 0;
system("cls");
if (Lev % 5 == 4) {
SetPos(5, 5), cout << "击败BOSS!可以选择两个天赋!(数字键选择)";
} else {
SetPos(5, 5), cout << "选择一个天赋!(数字键选择)";
}
Tf:
int R = rand() % 20 + 1;
for (int i = 1; i <= 4; i++) if (R == A[i]) goto Tf;
if (F[R] == 1) goto Tf;
ss++, A[ss] = R;
SetPos(4 * ss + 5, 8), cout << ss << "、";
if (R == 1) SetPos(4 * ss + 5, 10), cout << "护甲自动修复装置升级";
if (R == 2) SetPos(4 * ss + 5, 10), cout << "为制式突击步枪安装史莱姆弹夹";
if (R == 3) SetPos(4 * ss + 5, 10), cout << "时间流速减半(自己除外)";
if (R == 4) SetPos(4 * ss + 5, 10), cout << "获得战术靴子和毒气面罩";
if (R == 5) SetPos(4 * ss + 5, 10), cout << "开局金身时间升级";
if (R == 6) SetPos(4 * ss + 5, 10), cout << "更持久的空投武器";
if (R == 7) SetPos(4 * ss + 5, 10), cout << "特种护甲";
if (R == 8) SetPos(4 * ss + 5, 10), cout << "为制式突击步枪安装霰弹";
if (R == 9) SetPos(4 * ss + 5, 10), cout << "空投中的肾上腺素显著提升";
if (R == 10) SetPos(4 * ss + 5, 10), cout << "每次开局有概率增加HP";
if (R == 11) SetPos(4 * ss + 5, 10), cout << "为制式突击步枪安装魔法弹夹";
if (R == 12) SetPos(4 * ss + 5, 10), cout << "反光镜(饰品,似乎对某些光有用)";
if (R == 13) SetPos(4 * ss + 5, 10), cout << "护甲的临别赠礼(金身)";
if (R == 14) SetPos(4 * ss + 5, 10), cout << "为制式突击步枪安装高爆子弹";
if (R == 15) SetPos(4 * ss + 5, 10), cout << "概率缴获敌人护甲(BOSS关除外)";
if (R == 16) SetPos(4 * ss + 5, 10), cout << "天空一声巨响,主角闪亮登场";
if (R == 17) SetPos(4 * ss + 5, 10), cout << "护甲的临别赠礼(范围伤害)";
if (R == 18) SetPos(4 * ss + 5, 10), cout << "巴豆(吃完后有概率放屁)";
if (R == 19) SetPos(4 * ss + 5, 10), cout << "信号枪(更多的空投)";
if (R == 20) SetPos(4 * ss + 5, 10), cout << "如意(似乎可以变出点什么东西)";
if (ss < 4) goto Tf;
tF:
char c = _getch();
if (c >= '1' && c <= '4') F[A[c - '0']] = 1;
else goto tF;
if (A[c - '0'] == 7) MaxDE_Player += 3;
}
void Shock_Wave(int B) {
for (int i = X - B; i <= X + B; i++) if (CanGo(i, Y - B, 3) && i > 0 && Y - B > 0) m[i][Y - B] = 86, m[i][Y - B + 1] = 8;
for (int i = X - B; i <= X + B; i++) if (CanGo(i, Y + B, 3) && i > 0 && Y + B > 0) m[i][Y + B] = 86, m[i][Y + B - 1] = 8;
for (int j = Y - B; j <= Y + B; j++) if (CanGo(X + B, j, 3) && j > 0 && X + B > 0) m[X + B][j] = 86, m[X + B - 1][Y] = 8;
for (int j = Y - B; j <= Y + B; j++) if (CanGo(X - B, j, 3) && j > 0 && X - B > 0) m[X - B][j] = 86, m[X - B + 1][Y] = 8;
}
void Ci() {
for (int i = 1; i <= 29; i++)
for (int j = 1; j <= 29; j++) {
if (n[i][j] >= 10 && n[i][j] < 50 && n[i][j] != 30) n[i][j]++;
if (n[i][j] == 50) {
n[i][j] = 31;
if (m[i][j] == 2) m[i][j] = 0;
}
if (n[i][j] == 45 && !(m[i][j] >= 50 && m[i][j] < 55) && !(abs(Bx - i) <= 1 && abs(By - i) <= 1)) m[i][j] = 2;
if (n[i][j] > 20 && n[i][j] <= 30 && m[i][j] == 0) n[i][j] = 10;
if (n[i][j] == 20 && m[i][j] == 0 && !(abs(Bx - i) <= 1 && abs(By - i) <= 1)) m[i][j] = 1;
}
}
int main() {
system("mode con cols=82 lines=49");
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
srand((unsigned)time(NULL));
// 显示主菜单
MainMenu();
X = 4, Y = 8, gx = gy = 0, Muzzle = 1, Gun_type = 1, Lev = 0, T;
HP_Player = 10, DE_Player = 10, MaxHP_Player = 10, MaxDE_Player = 10;
memset(G, 0, sizeof(G));
memset(F, 0, sizeof(F));
St:
Win = 0;
Dazzling_Entrance = Farewell_Gift = 0;
memset(m, 0, sizeof(m));
memset(n, 0, sizeof(n));
ResetInvisibleMonsterState(); // 初始化隐形怪状态
G[8] = -1;
// 添加关卡开始的调试信息
if (Lev % 5 == 0 && Lev != 0) {
Talent();
Talent();
system("cls");
}
T = 0;
Sheng();
Map(1);
int rr = rand() % 3;
if (F[5] == 1) Unable_To_Be_Attacked = 60;
else Unable_To_Be_Attacked = 30;
if (rr == 0 && F[10] == 1) HP_Player = min(HP_Player + 1, MaxHP_Player);
if (F[16] == 1) Dazzling_Entrance = 4;
if (F[20] == 1) {
int Q = rand() % 7 + 2;
Gun_type = Q, G[Q] = 5;
}
X = max(2, min(38, X));
Y = max(2, min(38, Y));
while (Win <= 0 && HP_Player > 0 && Lev < 25) {
T++;
if (shootCooldown > 0) shootCooldown--;
if (Unable_To_Be_Attacked > 0) Unable_To_Be_Attacked--;
if (Unable_To_Be_Attacked == 1) Unable_To_Be_Attacked--, Map(4);
if (Dazzling_Entrance > 0) Shock_Wave(5 - Dazzling_Entrance), Dazzling_Entrance--;
if (Farewell_Gift > 0) Shock_Wave(4 - Farewell_Gift), Farewell_Gift--;
if (F[18] == 1) {
int Rrr = rand() % 30;
if (Rrr == 0)
for (int i = X - 2; i <= X + 2; i++)
for (int j = Y - 2; j <= Y + 2; j++) if (CanGo(i, j, 5) && i > 0 && j > 0) m[i][j] = 9;
}
if (DE_Player < MaxDE_Player) {
if (F[1] == 1 && T % 30 == 0) DE_Player++, Map(3);
if (F[1] == 0 && T % 70 == 0) DE_Player++, Map(3);
}
if (GetAsyncKeyState(VK_UP) & 0x8000) Map(2), gx--;
else if (GetAsyncKeyState(VK_DOWN) & 0x8000) Map(2), gx++;
else if (GetAsyncKeyState(VK_LEFT) & 0x8000) Map(2), gy--;
else if (GetAsyncKeyState(VK_RIGHT) & 0x8000) Map(2), gy++;
if (kbhit()) {
char g = _getch();
if (g == 'a') {
Map(2);
if (Muzzle != 1) Muzzle--;
else Muzzle = 8;
}
if (g == 'd') {
Map(2);
if (Muzzle != 8) Muzzle++;
else Muzzle = 1;
}
if (g == 'q') SwitchGun();
if (g == 'w') OpenBox(0);
if (g == 's' && shootCooldown <= 2) Bullet(), shootCooldown += 2;
if (GetAsyncKeyState(VK_DELETE) & 0x8000) {
// 清除当前关卡的所有怪物
for (int i = 2; i <= 28; i++) {
for (int j = 2; j <= 28; j++) {
if (m[i][j] >= 50 && m[i][j] <= 54) {
m[i][j] = 0;
}
}
}
if (Boss_HP > 0) {
Boss_HP = 0;
SetPos(Bx - 1, By - 1), cout << " ";
SetPos(Bx, By - 1), cout << " ";
SetPos(Bx + 1, By - 1), cout << " ";
}
system("cls");
system("color 6F");
SetPos(2, 10), Map_Colors(5), cout << "跳过当前关卡!";
bccd();
Sleep(500);
system("color 0F");
Map(1);
system("cls");
Win = 1;
Lev++;
break;
}
if (g == ' ') Sleep(100), SetPos(-1, 18), sy++, system("pause");
}
if (sy == 1) SetPos(-1, 18), cout << " ", sy--;
if (T % 2 == 0) Ci();
Move();
Map(0);
Sleep(50);
if (X < 1) X = 1;
if (X > 39) X = 39;
if (Y < 1) Y = 1;
if (Y > 39) Y = 39;
}
system("cls");
if (Win == 0 && HP_Player <= 0 && Lev < 25) {
system("color 7F"), Map_Colors(4);
Lev = 0;
HP_Player = DE_Player = MaxHP_Player = MaxDE_Player = 10;
Boss_HP = Boss_CrossBullet_CD = Boss_CornerBullet_CD = Boss_Poison_CD = Boss_Conjure_CD = 0;
memset(G, 0, sizeof(G));
memset(F, 0, sizeof(F));
SetPos(2, 2);
bccd();
cout << "游戏结束!", Sleep(1000);
SetPos(3, 2);
cout << "按任意键返回主菜单...";
_getch();
main();
}
if (Lev < 25) goto St;
if (Lev == 25) {
system("color 6E"), Map_Colors(5);
SetPos(2, 2), cout << "恭喜通关《死亡禁区》!";
SetPos(4, 2), cout << "你已经击败了所有BOSS!";
Sleep(3000);
system("color 0F");
system("cls");
main();
bccd();
}
return 0;
}
如果显示不全
如果你的游戏显示不全,请看这里(用Windows 7 演示,不过应该都差不多)
运行后正常是这样
如果你显示不全,右击顶部,选择属性,打开

将窗口大小调整为和zty一样,宽82,高49,其他不用管

字体大小选择8×16,字体选择点阵字体,就完成了
后记
作者:zty郑桐羽呀
联系方式:(不挂了,有事私信)
兄弟们给个赞呗
先 赞 后 看 养 成 习 惯








