MLEOLETLE(MOT)游戏
提示:4.0版本可以开荆棘,开到LV.20就可以结束了,然后不断休息,期间发现快要满了马上加附魔金苹果(还是什么来着),最后疯狂加时间,如果对方试图攻击你,对方是你伤害的2倍,对方用暴击更亏
远古版1.0
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
// 游戏上限配置
const int MAX_MEM = 128;
const int MAX_TIME = 1000;
const int MAX_OUTPUT = 256;
// 附魔结构
struct Enchant {
string name;
string desc;
int price;
string type;
int level;
};
Enchant shop[] = {
{"荆棘I", "受到伤害时,反弹20%给对方", 5, "thorn", 1},
{"过载I", "立刻让对方随机一条暴涨", 6, "overload", 1},
{"迟缓I", "对方每次行动额外加时间", 4, "slow", 1},
{"吞噬I", "偷对方属性给自己", 7, "steal", 1},
{"护盾I", "免疫一次对方干扰", 8, "shield", 1}
};
int shopSize = sizeof(shop)/sizeof(shop[0]);
// 玩家类
class Player {
public:
string name;
int mem = 0, time = 0, output = 0;
int gold = 20;
string enchType = "";
int enchLeft = 0;
int enchLvl = 0;
int dura = 1;
Player(string n) : name(n) {}
// 输了:任意条满
bool lose() {
return mem >= MAX_MEM || time >= MAX_TIME || output >= MAX_OUTPUT;
}
// 受到对方干扰 = 给自己加属性(核心修正)
void beAttacked(int m, int t, int o, Player& attacker) {
// 护盾免疫
if (enchType == "shield" && enchLeft > 0) {
enchLeft--;
cout << "🛡️ " << name << " 护盾免疫本次干扰!\n";
return;
}
// 受到干扰:属性增加
mem += m;
time += t;
output += o;
// 荆棘反弹
if (enchType == "thorn" && enchLeft > 0) {
enchLeft--;
int total = m + t/10 + o/2;
int back = total * 0.2 * enchLvl;
attacker.mem += back / 3;
attacker.time += back * 10;
attacker.output += back / 2;
cout << "🌵 荆棘反弹!对 " << attacker.name << " 造成干扰!\n";
}
}
void show() {
cout << "\n【" << name << "】\n";
cout << "内存:" << mem << "/" << MAX_MEM << "MB\n";
cout << "时间:" << time << "/" << MAX_TIME << "ms\n";
cout << "输出:" << output << "/" << MAX_OUTPUT << "Byte\n";
cout << "金币:" << gold << " | 耐久:" << dura << "倍\n";
if (!enchType.empty())
cout << "附魔:" << enchType << " 剩余:" << enchLeft << "\n";
else
cout << "附魔:无\n";
}
};
// 购买附魔
void buy(Player& p) {
cout << "\n===== 附魔商店 =====\n";
for (int i=0; i<shopSize; i++)
cout << i+1 << ". " << shop[i].name << " | " << shop[i].desc << " | " << shop[i].price << "金币\n";
cout << shopSize+1 << ". 取消\n";
int c; cin >> c;
if (c < 1 || c > shopSize) return;
Enchant e = shop[c-1];
if (p.gold < e.price) { cout << "金币不足!\n"; return; }
int d; cout << "耐久倍数(1-3):"; cin >> d;
d = max(1, min(3, d));
int total = e.price * d;
if (p.gold < total) { cout << "总价不足!\n"; return; }
p.gold -= total;
p.enchType = e.type;
p.enchLeft = d;
p.enchLvl = e.level;
p.dura = d;
cout << "✅ 购买成功!\n";
}
// 玩家行动:全部是【给对方加属性】
void playerTurn(Player& p, Player& en) {
cout << "\n===== 你的回合 =====\n";
cout << "1. 干扰内存 | 对方内存+10~20\n";
cout << "2. 干扰时间 | 对方时间+100~200\n";
cout << "3. 干扰输出 | 对方输出+20~40\n";
cout << "4. 休息 | 自身属性-5,金币+2\n";
cout << "5. 购买附魔\n";
int c; cin >> c;
int v;
switch(c) {
case 1:
v = rand()%11 +10;
en.beAttacked(v, 0, 0, p);
cout << "⚔️ 对方内存+" << v << "MB\n";
break;
case 2:
v = rand()%101 +100;
en.beAttacked(0, v, 0, p);
cout << "⚔️ 对方时间+" << v << "ms\n";
break;
case 3:
v = rand()%21 +20;
en.beAttacked(0, 0, v, p);
cout << "⚔️ 对方输出+" << v << "Byte\n";
break;
case 4:
p.mem = max(0, p.mem-5);
p.time = max(0, p.time-5);
p.output = max(0, p.output-5);
p.gold +=2;
cout << "😴 休息完成\n";
break;
case 5:
buy(p);
break;
default:
cout << "输入错误!\n";
playerTurn(p, en);
}
}
// 电脑行动:全部是【给玩家加属性】
void comTurn(Player& com, Player& p) {
cout << "\n===== 电脑回合 =====\n";
// 使用附魔
if (com.enchLeft > 0) {
if (com.enchType == "overload") {
int v = 30 * com.enchLvl;
p.beAttacked(v, v*10, v, com);
cout << "💥 电脑使用过载!\n";
}
else if (com.enchType == "steal") {
int v = 10 * com.enchLvl;
p.mem += v;
com.mem -= v;
cout << "🍗 电脑吞噬!\n";
}
com.enchLeft--;
return;
}
// 普通攻击:全部给玩家加属性
int act = rand()%3;
int v;
if (act ==0) {
v = rand()%11+8;
p.beAttacked(v,0,0, com);
cout << "电脑干扰内存!你的内存+" << v << "\n";
} else if (act ==1) {
v = rand()%101+80;
p.beAttacked(0,v,0, com);
cout << "电脑干扰时间!你的时间+" << v << "\n";
} else {
v = rand()%21+15;
p.beAttacked(0,0,v, com);
cout << "电脑干扰输出!你的输出+" << v << "\n";
}
}
int main() {
srand(time(0));
cout << "🎮 内存条攻防战(C++ 完美版)\n";
cout << "规则:谁先被干扰到任意条满,谁就输!\n\n";
system("pause");
Player me("玩家");
Player ai("电脑");
while(true) {
me.show();
ai.show();
playerTurn(me, ai);
if (ai.lose()) { cout << "\n🎉 你赢了!电脑被撑爆!\n"; break; }
comTurn(ai, me);
if (me.lose()) { cout << "\n💀 你输了!被电脑撑爆!\n"; break; }
}
system("pause");
return 0;
}远古版2.0
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
// 游戏数值
const int MAX_MEM = 128;
const int MAX_TIME = 1000; // 时间总容量保持 1000ms
const int MAX_OUTPUT = 256;
const int ATTACK_COST = 3; // 攻击消耗金币
// 玩家类
class Player {
public:
string name;
int mem = 0, time = 0, output = 0;
int gold = 35;
int thorn = 0; // 荆棘等级:直接叠加
int shield = 0;
Player(string n) : name(n) {}
bool isLost() {
return mem >= MAX_MEM || time >= MAX_TIME || output >= MAX_OUTPUT;
}
// A 攻击 B → B 调用 beAttacked
void beAttacked(int m, int t, int o, Player& attacker) {
if (shield > 0) {
shield--;
cout << "🛡️【" << name << "】护盾免疫本次攻击!\n";
return;
}
mem += m;
time += t;
output += o;
// 只要 B 有荆棘,攻击者 A 必反弹
if (thorn > 0) {
int total = m + (t / 2) + (o / 2);
int rebound = total * 0.2 * thorn; // 等级直接乘
attacker.mem += rebound / 3;
attacker.time += rebound;
attacker.output += rebound / 2;
cout << "🌵【" << name << "】荆棘 Lv." << thorn << " 反弹!\n";
}
}
void showStatus() {
cout << "\n===== " << name << " =====\n";
cout << "内存: " << mem << "/" << MAX_MEM << "MB\n";
cout << "时间: " << time << "/" << MAX_TIME << "ms\n";
cout << "输出: " << output << "/" << MAX_OUTPUT << "Byte\n";
cout << "金币: " << gold << "\n";
cout << "荆棘: Lv." << thorn << " 护盾: " << shield << "\n";
}
};
// 购买附魔:荆棘直接 +1
void buyEnchant(Player& p) {
cout << "\n===== 附魔商店 =====\n";
cout << "1. 荆棘 +1 (5金币)\n";
cout << "2. 护盾 +1 (6金币)\n";
cout << "3. 取消\n";
int c;
cin >> c;
if (c == 1) {
if (p.gold < 5) {
cout << "金币不足!\n";
return;
}
p.gold -= 5;
p.thorn += 1; // 👈 直接 +1,不是合成
cout << "✅ 荆棘提升!当前:荆棘 Lv." << p.thorn << "\n";
} else if (c == 2) {
if (p.gold < 6) {
cout << "金币不足!\n";
return;
}
p.gold -= 6;
p.shield += 1;
cout << "✅ 护盾 +1!\n";
}
}
// 玩家回合
void playerTurn(Player& p, Player& enemy) {
cout << "\n===== 你的回合 =====\n";
cout << "1. 干扰内存 (-3金币) 对方+10~20MB\n";
cout << "2. 干扰时间 (-3金币) 对方+5~10ms\n";
cout << "3. 干扰输出 (-3金币) 对方+20~40Byte\n";
cout << "4. 休息 (金币+2) 自身属性-5\n";
cout << "5. 购买附魔\n";
int c;
cin >> c;
int v;
switch (c) {
case 1:
if (p.gold < ATTACK_COST) { cout << "金币不够!\n"; return; }
p.gold -= ATTACK_COST;
v = rand() % 11 + 10;
enemy.beAttacked(v, 0, 0, p);
cout << "⚔️ 对方内存+" << v << "MB\n";
break;
case 2:
if (p.gold < ATTACK_COST) { cout << "金币不够!\n"; return; }
p.gold -= ATTACK_COST;
v = rand() % 6 + 5; // 5~10ms
enemy.beAttacked(0, v, 0, p);
cout << "⚔️ 对方时间+" << v << "ms\n";
break;
case 3:
if (p.gold < ATTACK_COST) { cout << "金币不够!\n"; return; }
p.gold -= ATTACK_COST;
v = rand() % 21 + 20;
enemy.beAttacked(0, 0, v, p);
cout << "⚔️ 对方输出+" << v << "Byte\n";
break;
case 4:
p.mem = max(0, p.mem - 5);
p.time = max(0, p.time - 5);
p.output = max(0, p.output - 5);
p.gold += 2;
cout << "😴 休息完成!\n";
break;
case 5:
buyEnchant(p);
break;
default:
cout << "输入错误!\n";
}
}
// 电脑回合
void computerTurn(Player& com, Player& p) {
cout << "\n===== 电脑回合 =====\n";
if (com.gold >= ATTACK_COST) {
int act = rand() % 3;
int v;
if (act == 0) {
com.gold -= ATTACK_COST;
v = rand() % 11 + 8;
p.beAttacked(v, 0, 0, com);
cout << "电脑干扰内存!你的内存+" << v << "\n";
} else if (act == 1) {
com.gold -= ATTACK_COST;
v = rand() % 6 + 4; // 4~9ms
p.beAttacked(0, v, 0, com);
cout << "电脑干扰时间!你的时间+" << v << "ms\n";
} else {
com.gold -= ATTACK_COST;
v = rand() % 21 + 15;
p.beAttacked(0, 0, v, com);
cout << "电脑干扰输出!你的输出+" << v << "\n";
}
} else {
com.mem = max(0, com.mem - 5);
com.time = max(0, com.time - 5);
com.output = max(0, com.output - 5);
com.gold += 2;
cout << "电脑金币不足,休息!\n";
}
}
int main() {
srand(time(0));
cout << "🎮 内存条攻防战 · 最终平衡版\n";
cout << "时间上限1000ms | 时间攻击5~10ms | 荆棘等级直接叠加\n\n";
system("pause");
Player player("玩家");
Player computer("电脑");
while (true) {
player.showStatus();
computer.showStatus();
playerTurn(player, computer);
if (computer.isLost()) {
cout << "\n🎉 你赢了!电脑被撑爆!\n";
break;
}
computerTurn(computer, player);
if (player.isLost()) {
cout << "\n💀 你输了!\n";
break;
}
}
system("pause");
return 0;
}怀旧版3.0
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
// ===================== 最终属性上限 =====================
const int MAX_MEM = 128; // 内存 128MB
const int MAX_TIME = 1000; // 时间 1000ms
const int MAX_OUTPUT = 128; // 输出 128Byte
const int ATTACK_COST = 3; // 攻击消耗3金币
// ===================== 玩家类 =====================
class Player {
public:
string name;
int mem = 0, time = 0, output = 0;
int gold = 40;
int thorn = 0; // 荆棘:直接叠加 2+1=3
int shield = 0;
Player(string n) : name(n) {}
// 任意条满即输
bool isLost() {
return mem >= MAX_MEM || time >= MAX_TIME || output >= MAX_OUTPUT;
}
// A攻击B → B调用此函数,受到伤害
void beAttacked(int m, int t, int o, Player& attacker) {
if (shield > 0) {
shield--;
cout << "🛡️【" << name << "】护盾免疫本次攻击!\n";
return;
}
// 受到攻击,属性增加
mem += m;
time += t;
output += o;
// 荆棘反弹:只要B有荆棘,攻击者A必受伤害
if (thorn > 0) {
int total = m + (t / 10) + o;
int rebound = total * 0.2 * thorn;
attacker.mem += max(1, rebound / 5);
attacker.time += max(2, rebound);
attacker.output += max(1, rebound / 5);
cout << "🌵荆棘 Lv." << thorn << " 反弹伤害!\n";
}
}
void showStatus() {
cout << "\n===== " << name << " =====\n";
cout << "内存: " << mem << "/" << MAX_MEM << "MB\n";
cout << "时间: " << time << "/" << MAX_TIME << "ms\n";
cout << "输出: " << output << "/" << MAX_OUTPUT << "Byte\n";
cout << "金币: " << gold << " | 荆棘 Lv." << thorn << " | 护盾: " << shield << "\n";
}
};
// 购买附魔:荆棘直接+1
void buyEnchant(Player& p) {
cout << "\n===== 附魔商店 =====\n";
cout << "1. 荆棘 +1 (5金币)\n";
cout << "2. 护盾 +1 (6金币)\n";
cout << "3. 取消\n";
int c;
cin >> c;
if (c == 1) {
if (p.gold < 5) { cout << "金币不足!\n"; return; }
p.gold -= 5;
p.thorn += 1;
cout << "✅ 荆棘升级!当前 Lv." << p.thorn << "\n";
}
else if (c == 2) {
if (p.gold < 6) { cout << "金币不足!\n"; return; }
p.gold -= 6;
p.shield += 1;
cout << "✅ 护盾 +1!\n";
}
}
// ===================== 玩家回合 =====================
void playerTurn(Player& p, Player& enemy) {
cout << "\n===== 你的回合 =====\n";
cout << "1. 干扰内存 (-3金币) 对方+1~2MB\n";
cout << "2. 干扰时间 (-3金币) 对方+7~16ms\n";
cout << "3. 干扰输出 (-3金币) 对方+1~2Byte\n";
cout << "4. 休息 (金币+2) 自身属性-1\n";
cout << "5. 购买附魔\n";
int c;
cin >> c;
int v;
switch (c) {
case 1:
if (p.gold < ATTACK_COST) { cout << "金币不足!\n"; return; }
p.gold -= ATTACK_COST;
v = rand() % 2 + 1; // 1~2MB
enemy.beAttacked(v, 0, 0, p);
cout << "⚔️ 对方内存+" << v << "MB\n";
break;
case 2:
if (p.gold < ATTACK_COST) { cout << "金币不足!\n"; return; }
p.gold -= ATTACK_COST;
v = rand() % 10 + 7; // 7~16ms
enemy.beAttacked(0, v, 0, p);
cout << "⚔️ 对方时间+" << v << "ms\n";
break;
case 3:
if (p.gold < ATTACK_COST) { cout << "金币不足!\n"; return; }
p.gold -= ATTACK_COST;
v = rand() % 2 + 1; // 1~2Byte
enemy.beAttacked(0, 0, v, p);
cout << "⚔️ 对方输出+" << v << "Byte\n";
break;
case 4:
p.mem = max(0, p.mem - 1);
p.time = max(0, p.time - 1);
p.output = max(0, p.output - 1);
p.gold += 2;
cout << "😴 休息完成!\n";
break;
case 5:
buyEnchant(p);
break;
default:
cout << "输入错误!\n";
}
}
// ===================== 电脑回合 =====================
void computerTurn(Player& com, Player& p) {
cout << "\n===== 电脑回合 =====\n";
if (com.gold >= ATTACK_COST) {
int act = rand() % 3;
int v;
if (act == 0) {
com.gold -= ATTACK_COST;
v = rand() % 2 + 1; // 1~2MB
p.beAttacked(v, 0, 0, com);
cout << "电脑干扰内存!你的内存+" << v << "\n";
}
else if (act == 1) {
com.gold -= ATTACK_COST;
v = rand() % 10 + 7; // 7~16ms
p.beAttacked(0, v, 0, com);
cout << "电脑干扰时间!你的时间+" << v << "\n";
}
else {
com.gold -= ATTACK_COST;
v = rand() % 2 + 1; // 1~2Byte
p.beAttacked(0, 0, v, com);
cout << "电脑干扰输出!你的输出+" << v << "\n";
}
}
else {
com.mem = max(0, com.mem - 1);
com.time = max(0, com.time - 1);
com.output = max(0, com.output - 1);
com.gold += 2;
cout << "电脑金币不足,休息!\n";
}
}
// ===================== 主函数 =====================
int main() {
srand(time(0));
cout << "🎮 内存条攻防战 · 终极精细平衡版\n";
cout << "内存+1~2 | 时间+7~16 | 输出+1~2 | 荆棘叠加\n\n";
system("pause");
Player player("玩家");
Player computer("电脑");
while (true) {
player.showStatus();
computer.showStatus();
playerTurn(player, computer);
if (computer.isLost()) { cout << "\n🎉 你赢了!电脑被撑爆!\n"; break; }
computerTurn(computer, player);
if (player.isLost()) { cout << "\n💀 你输了!\n"; break; }
}
system("pause");
return 0;
}最新版4.0
4.0:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
// ===================== 最终属性上限 =====================
const int MAX_MEM = 128; // 内存 128MB
const int MAX_TIME = 1000; // 时间 1000ms
const int MAX_OUTPUT = 128; // 输出 128Byte
const int ATTACK_COST = 3; // 攻击消耗3金币
// 道具价格
const int APPLE_PRICE = 5; // 金苹果价格
const int ENCHANTED_APPLE_PRICE = 15; // 附魔金苹果价格
// ===================== 玩家类 =====================
class Player {
public:
string name;
int mem = 0, time = 0, output = 0;
int gold = 40;
int thorn = 0; // 荆棘等级:反弹伤害
int shield = 0; // 护盾次数:免疫攻击
int lifeSteal = 0; // 吸血等级:攻击回金
int heavyHit = 0; // 重击等级:攻击加成
Player(string n) : name(n) {}
// 任意条满即输
bool isLost() {
return mem >= MAX_MEM || time >= MAX_TIME || output >= MAX_OUTPUT;
}
// 受到攻击 (由攻击者attacker发起)
void beAttacked(int m, int t, int o, Player& attacker) {
if (shield > 0) {
shield--;
cout << "???【" << name << "】护盾免疫本次攻击!\n";
return;
}
// 受到攻击,属性增加
mem += m;
time += t;
output += o;
// 荆棘反弹:只反弹对应属性的伤害,数值为本次攻击值 × 10% × 等级 (至少1)
if (thorn > 0) {
int rebound = 0;
string attr = "";
if (m > 0) {
rebound = m * 0.1 * thorn;
attr = "内存";
if (rebound < 1) rebound = 1;
attacker.mem += rebound;
}
else if (t > 0) {
rebound = t * 0.1 * thorn;
attr = "时间";
if (rebound < 1) rebound = 1;
attacker.time += rebound;
}
else if (o > 0) {
rebound = o * 0.1 * thorn;
attr = "输出";
if (rebound < 1) rebound = 1;
attacker.output += rebound;
}
cout << "??荆棘 Lv." << thorn << " 反弹 " << rebound << " 点" << attr << "伤害!\n";
}
}
void showStatus() {
cout << "\n===== " << name << " =====\n";
cout << "内存: " << mem << "/" << MAX_MEM << "MB\n";
cout << "时间: " << time << "/" << MAX_TIME << "ms\n";
cout << "输出: " << output << "/" << MAX_OUTPUT << "Byte\n";
cout << "金币: " << gold << "\n";
cout << "【附魔】荆棘 Lv." << thorn << " | 护盾 " << shield << "次 | 吸血 Lv." << lifeSteal << " | 重击 Lv." << heavyHit << "\n";
}
};
// 购买附魔(商店)
void buyEnchant(Player& p) {
while (true) {
cout << "\n===== 附魔商店 =====\n";
cout << "1. 荆棘 Lv." << p.thorn << " → Lv." << p.thorn+1 << " (5金币) 反弹伤害\n";
cout << "2. 护盾 +1 (6金币) 抵挡一次攻击\n";
cout << "3. 吸血 Lv." << p.lifeSteal << " → Lv." << p.lifeSteal+1 << " (8金币) 攻击回金+" << p.lifeSteal+1 << "\n";
cout << "4. 重击 Lv." << p.heavyHit << " → Lv." << p.heavyHit+1 << " (7金币) 攻击值+" << p.heavyHit+1 << "\n";
cout << "5. 取消\n";
cout << "请选择: ";
int c;
cin >> c;
if (cin.fail()) {
cin.clear();
cin.ignore(10000, '\n');
cout << "输入无效,请重试。\n";
continue;
}
switch (c) {
case 1:
if (p.gold < 5) { cout << "金币不足!\n"; break; }
p.gold -= 5;
p.thorn++;
cout << "? 荆棘升级!当前 Lv." << p.thorn << "\n";
return;
case 2:
if (p.gold < 6) { cout << "金币不足!\n"; break; }
p.gold -= 6;
p.shield++;
cout << "? 护盾 +1!当前 " << p.shield << " 次\n";
return;
case 3:
if (p.gold < 8) { cout << "金币不足!\n"; break; }
p.gold -= 8;
p.lifeSteal++;
cout << "? 吸血升级!当前 Lv." << p.lifeSteal << "\n";
return;
case 4:
if (p.gold < 7) { cout << "金币不足!\n"; break; }
p.gold -= 7;
p.heavyHit++;
cout << "? 重击升级!当前 Lv." << p.heavyHit << "\n";
return;
case 5:
cout << "离开商店。\n";
return;
default:
cout << "无效选项。\n";
}
}
}
// ===================== 玩家回合 =====================
void playerTurn(Player& p, Player& enemy) {
cout << "\n===== 你的回合 =====\n";
cout << "1. 干扰内存 (-3金币) 对方+1~2MB (受重击加成)\n";
cout << "2. 干扰时间 (-3金币) 对方+7~16ms (受重击加成)\n";
cout << "3. 干扰输出 (-3金币) 对方+1~2Byte (受重击加成)\n";
cout << "4. 休息 (金币+2) 自身属性-1\n";
cout << "5. 购买附魔\n";
cout << "6. 使用金苹果 (-" << APPLE_PRICE << "金币) 降低对方3MB/25ms/3Byte\n";
cout << "7. 使用附魔金苹果 (-" << ENCHANTED_APPLE_PRICE << "金币) 降低对方10MB/80ms/10Byte\n";
int c;
cin >> c;
if (cin.fail()) {
cin.clear();
cin.ignore(10000, '\n');
cout << "输入无效,跳过本回合。\n";
return;
}
int v;
int choice;
switch (c) {
case 1: // 内存攻击
if (p.gold < ATTACK_COST) { cout << "金币不足!\n"; return; }
p.gold -= ATTACK_COST;
v = rand() % 2 + 1 + p.heavyHit; // 基础1~2 + 重击等级
enemy.beAttacked(v, 0, 0, p);
cout << "?? 对方内存+" << v << "MB\n";
if (p.lifeSteal > 0) {
p.gold += p.lifeSteal;
cout << "?? 吸血+" << p.lifeSteal << "金币\n";
}
break;
case 2: // 时间攻击
if (p.gold < ATTACK_COST) { cout << "金币不足!\n"; return; }
p.gold -= ATTACK_COST;
v = rand() % 10 + 7 + p.heavyHit; // 7~16 + 重击
enemy.beAttacked(0, v, 0, p);
cout << "?? 对方时间+" << v << "ms\n";
if (p.lifeSteal > 0) {
p.gold += p.lifeSteal;
cout << "?? 吸血+" << p.lifeSteal << "金币\n";
}
break;
case 3: // 输出攻击
if (p.gold < ATTACK_COST) { cout << "金币不足!\n"; return; }
p.gold -= ATTACK_COST;
v = rand() % 2 + 1 + p.heavyHit; // 1~2 + 重击
enemy.beAttacked(0, 0, v, p);
cout << "?? 对方输出+" << v << "Byte\n";
if (p.lifeSteal > 0) {
p.gold += p.lifeSteal;
cout << "?? 吸血+" << p.lifeSteal << "金币\n";
}
break;
case 4: // 休息
p.mem = max(0, p.mem - 1);
p.time = max(0, p.time - 1);
p.output = max(0, p.output - 1);
p.gold += 2;
cout << "?? 休息完成!\n";
break;
case 5: // 商店
buyEnchant(p);
break;
case 6: // 金苹果
if (p.gold < APPLE_PRICE) { cout << "金币不足!\n"; return; }
cout << "选择要降低的属性:1.内存 2.时间 3.输出:";
cin >> choice;
if (cin.fail() || choice < 1 || choice > 3) {
cin.clear();
cin.ignore(10000, '\n');
cout << "无效选择,本次使用取消。\n";
return;
}
p.gold -= APPLE_PRICE;
switch (choice) {
case 1:
enemy.mem = max(0, enemy.mem - 3);
cout << "?? 对方内存-3MB\n";
break;
case 2:
enemy.time = max(0, enemy.time - 25);
cout << "?? 对方时间-25ms\n";
break;
case 3:
enemy.output = max(0, enemy.output - 3);
cout << "?? 对方输出-3Byte\n";
break;
}
break;
case 7: // 附魔金苹果
if (p.gold < ENCHANTED_APPLE_PRICE) { cout << "金币不足!\n"; return; }
cout << "选择要降低的属性:1.内存 2.时间 3.输出:";
cin >> choice;
if (cin.fail() || choice < 1 || choice > 3) {
cin.clear();
cin.ignore(10000, '\n');
cout << "无效选择,本次使用取消。\n";
return;
}
p.gold -= ENCHANTED_APPLE_PRICE;
switch (choice) {
case 1:
enemy.mem = max(0, enemy.mem - 10);
cout << "??? 对方内存-10MB\n";
break;
case 2:
enemy.time = max(0, enemy.time - 80);
cout << "??? 对方时间-80ms\n";
break;
case 3:
enemy.output = max(0, enemy.output - 10);
cout << "??? 对方输出-10Byte\n";
break;
}
break;
default:
cout << "输入错误!\n";
}
}
// 电脑购买附魔(简单AI)
void computerBuyEnchant(Player& com) {
if (com.gold < 5) return; // 最便宜的荆棘都买不起
int choice = rand() % 4; // 随机选一种附魔
switch (choice) {
case 0: // 荆棘
if (com.gold >= 5) {
com.gold -= 5;
com.thorn++;
cout << "电脑购买了荆棘 Lv." << com.thorn << "\n";
}
break;
case 1: // 护盾
if (com.gold >= 6) {
com.gold -= 6;
com.shield++;
cout << "电脑购买了护盾 +1\n";
}
break;
case 2: // 吸血
if (com.gold >= 8) {
com.gold -= 8;
com.lifeSteal++;
cout << "电脑购买了吸血 Lv." << com.lifeSteal << "\n";
}
break;
case 3: // 重击
if (com.gold >= 7) {
com.gold -= 7;
com.heavyHit++;
cout << "电脑购买了重击 Lv." << com.heavyHit << "\n";
}
break;
}
}
// ===================== 电脑回合 =====================
void computerTurn(Player& com, Player& p) {
cout << "\n===== 电脑回合 =====\n";
// 电脑有10%概率购买附魔(如果有钱)
if (rand() % 10 == 0 && com.gold >= 5) {
computerBuyEnchant(com);
}
// 否则尝试攻击
else if (com.gold >= ATTACK_COST) {
int act = rand() % 3;
int v;
switch (act) {
case 0:
com.gold -= ATTACK_COST;
v = rand() % 2 + 1 + com.heavyHit; // 基础+重击
p.beAttacked(v, 0, 0, com);
cout << "电脑干扰内存!你的内存+" << v << "\n";
if (com.lifeSteal > 0) {
com.gold += com.lifeSteal;
cout << "电脑吸血+" << com.lifeSteal << "金币\n";
}
break;
case 1:
com.gold -= ATTACK_COST;
v = rand() % 10 + 7 + com.heavyHit;
p.beAttacked(0, v, 0, com);
cout << "电脑干扰时间!你的时间+" << v << "\n";
if (com.lifeSteal > 0) {
com.gold += com.lifeSteal;
cout << "电脑吸血+" << com.lifeSteal << "金币\n";
}
break;
case 2:
com.gold -= ATTACK_COST;
v = rand() % 2 + 1 + com.heavyHit;
p.beAttacked(0, 0, v, com);
cout << "电脑干扰输出!你的输出+" << v << "\n";
if (com.lifeSteal > 0) {
com.gold += com.lifeSteal;
cout << "电脑吸血+" << com.lifeSteal << "金币\n";
}
break;
}
}
else {
// 金币不足,休息
com.mem = max(0, com.mem - 1);
com.time = max(0, com.time - 1);
com.output = max(0, com.output - 1);
com.gold += 2;
cout << "电脑金币不足,休息!\n";
}
}
// ===================== 主函数 =====================
int main() {
srand(time(0));
cout << "?? 内存条攻防战 · 附魔增强版 + 金苹果\n";
cout << "攻击:内存+1~2 | 时间+7~16 | 输出+1~2 (重击可加成)\n";
cout << "金苹果:降低对方3MB/25ms/3Byte (5金币)\n";
cout << "附魔金苹果:降低对方10MB/80ms/10Byte (15金币)\n";
cout << "荆棘:只反弹对应属性伤害!\n\n";
bool replay = true;
while (replay) {
Player player("玩家");
Player computer("电脑");
// 给电脑随机一个初始附魔(增加挑战)
int initEnchant = rand() % 2;
if (initEnchant == 0) {
computer.thorn = 1;
computer.gold -= 5; // 扣除购买金币
cout << "电脑初始拥有荆棘 Lv.1\n";
} else {
computer.shield = 1;
computer.gold -= 6;
cout << "电脑初始拥有护盾 1次\n";
}
while (true) {
player.showStatus();
computer.showStatus();
playerTurn(player, computer);
if (computer.isLost()) {
cout << "\n?? 你赢了!电脑被撑爆!\n";
break;
}
computerTurn(computer, player);
if (player.isLost()) {
cout << "\n?? 你输了!\n";
break;
}
}
// 询问是否重玩
cout << "\n再玩一局?(y/n): ";
char ch;
cin >> ch;
if (ch != 'y' && ch != 'Y') replay = false;
}
cout << "感谢游玩!\n";
system("pause");
return 0;
}刚刚更新的5.0
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <windows.h> // 用于控制台颜色
using namespace std;
// ===================== 最终属性上限 =====================
const int MAX_MEM = 128; // 内存 128MB
const int MAX_TIME = 1000; // 时间 1000ms
const int MAX_OUTPUT = 128; // 输出 128Byte
const int ATTACK_COST = 3; // 攻击消耗3金币
// 道具价格
const int APPLE_PRICE = 5; // 金苹果价格
const int ENCHANTED_APPLE_PRICE = 15; // 附魔金苹果价格
// 控制台颜色
enum Color {
BLACK = 0,
BLUE = 1,
GREEN = 2,
CYAN = 3,
RED = 4,
MAGENTA = 5,
YELLOW = 6,
WHITE = 7,
GRAY = 8,
LIGHT_BLUE = 9,
LIGHT_GREEN = 10,
LIGHT_CYAN = 11,
LIGHT_RED = 12,
LIGHT_MAGENTA = 13,
LIGHT_YELLOW = 14,
BRIGHT_WHITE = 15
};
// 设置控制台颜色
void setColor(int color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
// 重置颜色为默认白色
void resetColor() {
setColor(WHITE);
}
// ===================== 玩家类 =====================
class Player {
public:
string name;
int mem = 0, time = 0, output = 0;
int gold = 40;
int thorn = 0; // 荆棘等级:反弹伤害
int shield = 0; // 护盾次数:免疫攻击
int lifeSteal = 0; // 吸血等级:攻击回金
int heavyHit = 0; // 重击等级:攻击加成
Player(string n) : name(n) {}
// 任意条满即输
bool isLost() {
return mem >= MAX_MEM || time >= MAX_TIME || output >= MAX_OUTPUT;
}
// 受到攻击 (由攻击者attacker发起)
void beAttacked(int m, int t, int o, Player& attacker) {
if (shield > 0) {
shield--;
setColor(LIGHT_CYAN);
cout << "???【" << name << "】护盾免疫本次攻击!\n";
resetColor();
return;
}
// 受到攻击,属性增加
mem += m;
time += t;
output += o;
// 荆棘反弹:只反弹对应属性的伤害,数值为本次攻击值 × 10% × 等级 (至少1)
if (thorn > 0) {
int rebound = 0;
string attr = "";
if (m > 0) {
rebound = m * 0.1 * thorn;
attr = "内存";
if (rebound < 1) rebound = 1;
attacker.mem += rebound;
}
else if (t > 0) {
rebound = t * 0.1 * thorn;
attr = "时间";
if (rebound < 1) rebound = 1;
attacker.time += rebound;
}
else if (o > 0) {
rebound = o * 0.1 * thorn;
attr = "输出";
if (rebound < 1) rebound = 1;
attacker.output += rebound;
}
setColor(LIGHT_GREEN);
cout << "??荆棘 Lv." << thorn << " 反弹 " << rebound << " 点" << attr << "伤害!\n";
resetColor();
}
}
void showStatus() {
// 玩家名字用绿色
setColor(LIGHT_GREEN);
cout << "\n===== " << name << " =====\n";
resetColor();
// 内存
cout << "内存: " << mem << "/" << MAX_MEM << "MB";
if (mem > MAX_MEM * 0.8) {
setColor(LIGHT_RED);
cout << " ?? 接近上限!";
resetColor();
}
cout << "\n";
// 时间
cout << "时间: " << time << "/" << MAX_TIME << "ms";
if (time > MAX_TIME * 0.8) {
setColor(LIGHT_RED);
cout << " ?? 接近上限!";
resetColor();
}
cout << "\n";
// 输出
cout << "输出: " << output << "/" << MAX_OUTPUT << "Byte";
if (output > MAX_OUTPUT * 0.8) {
setColor(LIGHT_RED);
cout << " ?? 接近上限!";
resetColor();
}
cout << "\n";
cout << "金币: " << gold << "\n";
setColor(LIGHT_YELLOW);
cout << "【附魔】荆棘 Lv." << thorn << " | 护盾 " << shield << "次 | 吸血 Lv." << lifeSteal << " | 重击 Lv." << heavyHit << "\n";
resetColor();
// 如果任一属性接近上限,给出使用金苹果的建议
if (mem > MAX_MEM * 0.8 || time > MAX_TIME * 0.8 || output > MAX_OUTPUT * 0.8) {
setColor(LIGHT_MAGENTA);
cout << "?? 建议:可使用金苹果(5金)或附魔金苹果(15金)降低自己的对应属性,避免超限!\n";
resetColor();
}
}
};
// 购买附魔(商店)
void buyEnchant(Player& p) {
while (true) {
setColor(LIGHT_YELLOW);
cout << "\n===== 附魔商店 =====\n";
resetColor();
cout << "1. 荆棘 Lv." << p.thorn << " → Lv." << p.thorn+1 << " (5金币) 反弹伤害\n";
cout << "2. 护盾 +1 (6金币) 抵挡一次攻击\n";
cout << "3. 吸血 Lv." << p.lifeSteal << " → Lv." << p.lifeSteal+1 << " (8金币) 攻击回金+" << p.lifeSteal+1 << "\n";
cout << "4. 重击 Lv." << p.heavyHit << " → Lv." << p.heavyHit+1 << " (7金币) 攻击值+" << p.heavyHit+1 << "\n";
cout << "5. 取消\n";
cout << "请选择: ";
int c;
cin >> c;
if (cin.fail()) {
cin.clear();
cin.ignore(10000, '\n');
setColor(LIGHT_RED);
cout << "输入无效,请重试。\n";
resetColor();
continue;
}
switch (c) {
case 1:
if (p.gold < 5) {
setColor(LIGHT_RED);
cout << "金币不足!\n";
resetColor();
break;
}
p.gold -= 5;
p.thorn++;
setColor(LIGHT_GREEN);
cout << "? 荆棘升级!当前 Lv." << p.thorn << "\n";
resetColor();
return;
case 2:
if (p.gold < 6) {
setColor(LIGHT_RED);
cout << "金币不足!\n";
resetColor();
break;
}
p.gold -= 6;
p.shield++;
setColor(LIGHT_GREEN);
cout << "? 护盾 +1!当前 " << p.shield << " 次\n";
resetColor();
return;
case 3:
if (p.gold < 8) {
setColor(LIGHT_RED);
cout << "金币不足!\n";
resetColor();
break;
}
p.gold -= 8;
p.lifeSteal++;
setColor(LIGHT_GREEN);
cout << "? 吸血升级!当前 Lv." << p.lifeSteal << "\n";
resetColor();
return;
case 4:
if (p.gold < 7) {
setColor(LIGHT_RED);
cout << "金币不足!\n";
resetColor();
break;
}
p.gold -= 7;
p.heavyHit++;
setColor(LIGHT_GREEN);
cout << "? 重击升级!当前 Lv." << p.heavyHit << "\n";
resetColor();
return;
case 5:
cout << "离开商店。\n";
return;
default:
setColor(LIGHT_RED);
cout << "无效选项。\n";
resetColor();
}
}
}
// ===================== 玩家回合 =====================
void playerTurn(Player& p, Player& enemy) {
setColor(LIGHT_CYAN);
cout << "\n===== 你的回合 =====\n";
resetColor();
cout << "1. 干扰内存 (-3金币) 对方+1~2MB (受重击加成)\n";
cout << "2. 干扰时间 (-3金币) 对方+7~16ms (受重击加成)\n";
cout << "3. 干扰输出 (-3金币) 对方+1~2Byte (受重击加成)\n";
cout << "4. 休息 (金币+2) 自身属性-1\n";
cout << "5. 购买附魔\n";
setColor(LIGHT_YELLOW);
cout << "6. 使用金苹果 (-" << APPLE_PRICE << "金币) 减少自身3MB/25ms/3Byte\n";
cout << "7. 使用附魔金苹果 (-" << ENCHANTED_APPLE_PRICE << "金币) 减少自身10MB/80ms/10Byte\n";
resetColor();
int c;
cin >> c;
if (cin.fail()) {
cin.clear();
cin.ignore(10000, '\n');
setColor(LIGHT_RED);
cout << "输入无效,跳过本回合。\n";
resetColor();
return;
}
int v;
int choice;
switch (c) {
case 1: // 内存攻击
if (p.gold < ATTACK_COST) {
setColor(LIGHT_RED);
cout << "金币不足!\n";
resetColor();
return;
}
p.gold -= ATTACK_COST;
v = rand() % 2 + 1 + p.heavyHit;
enemy.beAttacked(v, 0, 0, p);
setColor(LIGHT_RED);
cout << "?? 对方内存+" << v << "MB\n";
resetColor();
if (p.lifeSteal > 0) {
p.gold += p.lifeSteal;
setColor(LIGHT_MAGENTA);
cout << "?? 吸血+" << p.lifeSteal << "金币\n";
resetColor();
}
break;
case 2: // 时间攻击
if (p.gold < ATTACK_COST) {
setColor(LIGHT_RED);
cout << "金币不足!\n";
resetColor();
return;
}
p.gold -= ATTACK_COST;
v = rand() % 10 + 7 + p.heavyHit;
enemy.beAttacked(0, v, 0, p);
setColor(LIGHT_RED);
cout << "?? 对方时间+" << v << "ms\n";
resetColor();
if (p.lifeSteal > 0) {
p.gold += p.lifeSteal;
setColor(LIGHT_MAGENTA);
cout << "?? 吸血+" << p.lifeSteal << "金币\n";
resetColor();
}
break;
case 3: // 输出攻击
if (p.gold < ATTACK_COST) {
setColor(LIGHT_RED);
cout << "金币不足!\n";
resetColor();
return;
}
p.gold -= ATTACK_COST;
v = rand() % 2 + 1 + p.heavyHit;
enemy.beAttacked(0, 0, v, p);
setColor(LIGHT_RED);
cout << "?? 对方输出+" << v << "Byte\n";
resetColor();
if (p.lifeSteal > 0) {
p.gold += p.lifeSteal;
setColor(LIGHT_MAGENTA);
cout << "?? 吸血+" << p.lifeSteal << "金币\n";
resetColor();
}
break;
case 4: // 休息
p.mem = max(0, p.mem - 1);
p.time = max(0, p.time - 1);
p.output = max(0, p.output - 1);
p.gold += 2;
setColor(LIGHT_BLUE);
cout << "?? 休息完成!\n";
resetColor();
break;
case 5: // 商店
buyEnchant(p);
break;
case 6: // 金苹果(自愈)
if (p.gold < APPLE_PRICE) {
setColor(LIGHT_RED);
cout << "金币不足!\n";
resetColor();
return;
}
cout << "选择要减少的自身属性:1.内存 2.时间 3.输出:";
cin >> choice;
if (cin.fail() || choice < 1 || choice > 3) {
cin.clear();
cin.ignore(10000, '\n');
setColor(LIGHT_RED);
cout << "无效选择,本次使用取消。\n";
resetColor();
return;
}
p.gold -= APPLE_PRICE;
switch (choice) {
case 1:
p.mem = max(0, p.mem - 3);
setColor(LIGHT_GREEN);
cout << "?? 自身内存-3MB\n";
resetColor();
break;
case 2:
p.time = max(0, p.time - 25);
setColor(LIGHT_GREEN);
cout << "?? 自身时间-25ms\n";
resetColor();
break;
case 3:
p.output = max(0, p.output - 3);
setColor(LIGHT_GREEN);
cout << "?? 自身输出-3Byte\n";
resetColor();
break;
}
break;
case 7: // 附魔金苹果(自愈)
if (p.gold < ENCHANTED_APPLE_PRICE) {
setColor(LIGHT_RED);
cout << "金币不足!\n";
resetColor();
return;
}
cout << "选择要减少的自身属性:1.内存 2.时间 3.输出:";
cin >> choice;
if (cin.fail() || choice < 1 || choice > 3) {
cin.clear();
cin.ignore(10000, '\n');
setColor(LIGHT_RED);
cout << "无效选择,本次使用取消。\n";
resetColor();
return;
}
p.gold -= ENCHANTED_APPLE_PRICE;
switch (choice) {
case 1:
p.mem = max(0, p.mem - 10);
setColor(LIGHT_YELLOW);
cout << "??? 自身内存-10MB\n";
resetColor();
break;
case 2:
p.time = max(0, p.time - 80);
setColor(LIGHT_YELLOW);
cout << "??? 自身时间-80ms\n";
resetColor();
break;
case 3:
p.output = max(0, p.output - 10);
setColor(LIGHT_YELLOW);
cout << "??? 自身输出-10Byte\n";
resetColor();
break;
}
break;
default:
setColor(LIGHT_RED);
cout << "输入错误!\n";
resetColor();
}
}
// 电脑购买附魔(简单AI)
void computerBuyEnchant(Player& com) {
if (com.gold < 5) return;
int choice = rand() % 4;
switch (choice) {
case 0: // 荆棘
if (com.gold >= 5) {
com.gold -= 5;
com.thorn++;
setColor(LIGHT_RED);
cout << "电脑购买了荆棘 Lv." << com.thorn << "\n";
resetColor();
}
break;
case 1: // 护盾
if (com.gold >= 6) {
com.gold -= 6;
com.shield++;
setColor(LIGHT_RED);
cout << "电脑购买了护盾 +1\n";
resetColor();
}
break;
case 2: // 吸血
if (com.gold >= 8) {
com.gold -= 8;
com.lifeSteal++;
setColor(LIGHT_RED);
cout << "电脑购买了吸血 Lv." << com.lifeSteal << "\n";
resetColor();
}
break;
case 3: // 重击
if (com.gold >= 7) {
com.gold -= 7;
com.heavyHit++;
setColor(LIGHT_RED);
cout << "电脑购买了重击 Lv." << com.heavyHit << "\n";
resetColor();
}
break;
}
}
// ===================== 电脑回合 =====================
void computerTurn(Player& com, Player& p) {
setColor(LIGHT_RED);
cout << "\n===== 电脑回合 =====\n";
resetColor();
// 电脑有10%概率购买附魔(如果有钱)
if (rand() % 10 == 0 && com.gold >= 5) {
computerBuyEnchant(com);
}
// 否则尝试攻击
else if (com.gold >= ATTACK_COST) {
int act = rand() % 3;
int v;
switch (act) {
case 0:
com.gold -= ATTACK_COST;
v = rand() % 2 + 1 + com.heavyHit;
p.beAttacked(v, 0, 0, com);
setColor(LIGHT_RED);
cout << "电脑干扰内存!你的内存+" << v << "\n";
resetColor();
if (com.lifeSteal > 0) {
com.gold += com.lifeSteal;
setColor(LIGHT_MAGENTA);
cout << "电脑吸血+" << com.lifeSteal << "金币\n";
resetColor();
}
break;
case 1:
com.gold -= ATTACK_COST;
v = rand() % 10 + 7 + com.heavyHit;
p.beAttacked(0, v, 0, com);
setColor(LIGHT_RED);
cout << "电脑干扰时间!你的时间+" << v << "\n";
resetColor();
if (com.lifeSteal > 0) {
com.gold += com.lifeSteal;
setColor(LIGHT_MAGENTA);
cout << "电脑吸血+" << com.lifeSteal << "金币\n";
resetColor();
}
break;
case 2:
com.gold -= ATTACK_COST;
v = rand() % 2 + 1 + com.heavyHit;
p.beAttacked(0, 0, v, com);
setColor(LIGHT_RED);
cout << "电脑干扰输出!你的输出+" << v << "\n";
resetColor();
if (com.lifeSteal > 0) {
com.gold += com.lifeSteal;
setColor(LIGHT_MAGENTA);
cout << "电脑吸血+" << com.lifeSteal << "金币\n";
resetColor();
}
break;
}
}
else {
// 金币不足,休息
com.mem = max(0, com.mem - 1);
com.time = max(0, com.time - 1);
com.output = max(0, com.output - 1);
com.gold += 2;
setColor(LIGHT_BLUE);
cout << "电脑金币不足,休息!\n";
resetColor();
}
}
// ===================== 主函数 =====================
int main() {
// 设置控制台标题
SetConsoleTitle("内存条攻防战 - 彩色版");
srand(time(0));
setColor(LIGHT_YELLOW);
cout << "?? 内存条攻防战 · 附魔增强版 + 金苹果(自愈)\n";
resetColor();
cout << "攻击:内存+1~2 | 时间+7~16 | 输出+1~2 (重击可加成)\n";
setColor(LIGHT_GREEN);
cout << "金苹果:消耗5金币,减少自身3MB/25ms/3Byte\n";
setColor(LIGHT_YELLOW);
cout << "附魔金苹果:消耗15金币,减少自身10MB/80ms/10Byte\n";
resetColor();
cout << "荆棘:只反弹对应属性伤害!\n\n";
bool replay = true;
while (replay) {
Player player("玩家");
Player computer("电脑");
// 给电脑随机一个初始附魔(增加挑战)
int initEnchant = rand() % 2;
if (initEnchant == 0) {
computer.thorn = 1;
computer.gold -= 5;
setColor(LIGHT_RED);
cout << "电脑初始拥有荆棘 Lv.1\n";
resetColor();
} else {
computer.shield = 1;
computer.gold -= 6;
setColor(LIGHT_RED);
cout << "电脑初始拥有护盾 1次\n";
resetColor();
}
while (true) {
player.showStatus();
// 电脑状态用红色显示名字
setColor(LIGHT_RED);
cout << "\n===== " << computer.name << " =====\n";
resetColor();
computer.showStatus();
playerTurn(player, computer);
if (computer.isLost()) {
setColor(LIGHT_GREEN);
cout << "\n?? 你赢了!电脑被撑爆!\n";
resetColor();
break;
}
computerTurn(computer, player);
if (player.isLost()) {
setColor(LIGHT_RED);
cout << "\n?? 你输了!\n";
resetColor();
break;
}
}
// 询问是否重玩
setColor(LIGHT_YELLOW);
cout << "\n再玩一局?(y/n): ";
resetColor();
char ch;
cin >> ch;
if (ch != 'y' && ch != 'Y') replay = false;
}
setColor(LIGHT_CYAN);
cout << "感谢游玩!\n";
resetColor();
system("pause");
return 0;
}注:接下来展示HTML网页,如果不知道html如何创建,私信我,我教你~ html代码: HTML直连网站