地牢探险V1.2.1-C++-deepseek
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <limits>
#include <memory> // 添加智能指针支持
using namespace std;
// 卡牌基类
class Card {
public:
string name;
string description;
int cost;
bool isAttack;
bool isDefense;
bool isUtility;
Card(string n, string desc, int c, bool atk, bool def, bool util)
: name(n), description(desc), cost(c), isAttack(atk), isDefense(def), isUtility(util) {}
virtual bool canPlay(int playerHealth, int playerDefense) {
return true;
}
virtual void play(int& playerHealth, int& playerDefense, int& enemyHealth, int& enemyDefense) = 0;
// 添加升级方法
virtual void upgrade() = 0;
virtual ~Card() {}
};
// 攻击卡牌
class AttackCard : public Card {
public:
int damage;
AttackCard(string n, string desc, int c, int dmg)
: Card(n, desc, c, true, false, false), damage(dmg) {}
// 实现升级方法
void upgrade() override {
damage += 3;
description = "造成" + to_string(damage) + "点伤害";
}
void play(int& playerHealth, int& playerDefense, int& enemyHealth, int& enemyDefense) override {
if (enemyDefense > 0) {
int actualDamage = min(damage, enemyDefense);
enemyDefense -= actualDamage;
damage -= actualDamage;
}
enemyHealth -= damage;
cout << "你使用 " << name << " 对敌人造成了 " << damage << " 点伤害!\n";
}
};
// 防御卡牌
class DefenseCard : public Card {
public:
int defense;
DefenseCard(string n, string desc, int c, int def)
: Card(n, desc, c, false, true, false), defense(def) {}
// 实现升级方法
void upgrade() override {
if (defense > 0) {
defense += 3;
description = "获得" + to_string(defense) + "点护甲";
} else {
defense -= 3; // 负效果卡牌升级效果更强
description = "扣" + to_string(-defense) + "点护甲获得" + to_string(-cost) + "点能量";
}
}
bool canPlay(int playerHealth, int playerDefense) override {
if (defense < 0) {
return playerDefense >= -defense;
}
return true;
}
void play(int& playerHealth, int& playerDefense, int& enemyHealth, int& enemyDefense) override {
playerDefense += defense;
if (defense < 0) {
cout << "你使用 " << name << " 消耗了 " << -defense << " 点护甲!\n";
} else {
cout << "你使用 " << name << " 获得了 " << defense << " 点护甲!\n";
}
}
};
// 实用卡牌
class UtilityCard : public Card {
public:
int healAmount;
UtilityCard(string n, string desc, int c, int heal)
: Card(n, desc, c, false, false, true), healAmount(heal) {}
// 实现升级方法
void upgrade() override {
if (healAmount > 0) {
healAmount += 3;
description = "恢复" + to_string(healAmount) + "点生命";
} else {
healAmount -= 3; // 负效果卡牌升级效果更强
description = "恢复" + to_string(-cost) + "点能量,扣" + to_string(-healAmount) + "生命";
}
}
bool canPlay(int playerHealth, int playerDefense) override {
if (healAmount < 0) {
return playerHealth > -healAmount;
}
return true;
}
void play(int& playerHealth, int& playerDefense, int& enemyHealth, int& enemyDefense) override {
playerHealth += healAmount;
if (healAmount < 0) {
cout << "你使用 " << name << " 消耗了 " << -healAmount << " 点生命值!\n";
} else {
cout << "你使用 " << name << " 恢复了 " << healAmount << " 点生命值!\n";
}
}
};
// 敌人基类
class Enemy {
public:
string name;
int health;
int attack;
int defense;
string description;
Enemy(string n, int hp, int atk, int def, string desc)
: name(n), health(hp), attack(atk), defense(def), description(desc) {}
virtual void takeTurn(int& playerHealth, int& playerDefense) {
if (defense > 0) {
cout << name << " 有 " << defense << " 点护甲!\n";
}
int actualAttack = attack;
if (playerDefense > 0) {
int blocked = min(actualAttack, playerDefense);
playerDefense -= blocked;
actualAttack -= blocked;
}
playerHealth -= actualAttack;
cout << name << " 对你造成了 " << actualAttack << " 点伤害!\n";
}
bool isDefeated() const {
return health <= 0;
}
};
// 玩家类
class Player {
public:
int health;
int maxHealth;
int defense;
int energy;
int maxEnergy;
int gold;
vector<Card*> deck;
vector<Card*> hand;
vector<Card*> discardPile;
int floor;
Player() : health(50), maxHealth(50), defense(0), energy(3), maxEnergy(3), gold(50), floor(1) {
// 初始卡组 - 使用智能指针
deck.push_back(new AttackCard("打击", "造成5点伤害", 1, 5));
deck.push_back(new AttackCard("打击", "造成5点伤害", 1, 5));
deck.push_back(new AttackCard("打击", "造成5点伤害", 1, 5));
deck.push_back(new AttackCard("打击", "造成5点伤害", 1, 5));
deck.push_back(new DefenseCard("防御", "获得5点护甲", 1, 5));
deck.push_back(new DefenseCard("防御", "获得5点护甲", 1, 5));
deck.push_back(new DefenseCard("防御", "获得5点护甲", 1, 5));
deck.push_back(new UtilityCard("治疗", "恢复5点生命", 1, 5));
}
~Player() {
for (Card* card : deck) delete card;
for (Card* card : hand) delete card;
for (Card* card : discardPile) delete card;
}
void drawHand() {
for (int i = 0; i < 5; i++) {
if (deck.empty()) {
shuffleDiscardIntoDeck();
if (deck.empty()) break;
}
hand.push_back(deck.back());
deck.pop_back();
}
}
void shuffleDiscardIntoDeck() {
random_shuffle(discardPile.begin(), discardPile.end());
for (Card* card : discardPile) {
deck.push_back(card);
}
discardPile.clear();
}
void discardHand() {
for (Card* card : hand) {
discardPile.push_back(card);
}
hand.clear();
}
void resetEnergy() {
energy = maxEnergy;
}
void heal(int amount) {
health = min(maxHealth, health + amount);
}
void addCardToDeck(Card* card) {
deck.push_back(card);
}
};
// 游戏类
class RogueCardGame {
private:
Player player;
Enemy* currentEnemy;
bool gameOver;
bool victory;
vector<Card*> allCards = {
new AttackCard("强力打击", "造成8点伤害", 2, 8),
new AttackCard("致命一击", "造成20点伤害", 3, 20),
new AttackCard("忘本", "造成50点伤害", 5, 50),
new AttackCard("权威", "造成100点伤害", 7, 100),
new AttackCard("权威 max pro 觉醒", "造成至少1e9点伤害", 50, 0x3f3f3f3f),
new DefenseCard("铁壁", "获得10点护甲", 2, 10),
new DefenseCard("振金屏障", "获得25点护甲", 7, 50),
new DefenseCard("莫比乌斯盾", "获得50点护甲", 10, 100),
new DefenseCard("莫比乌斯盾 max pro 觉醒", "获得100点护甲", 10, 100),
new DefenseCard("反射护盾", "获得5点护甲并反弹3点伤害", 2, 5),
new DefenseCard("破盾max", "扣20点护甲获得5点能量", -5, -20),
new DefenseCard("破盾max pro", "扣50点护甲获得15点能量", -15, -50),
new DefenseCard("破盾max pro 觉醒", "扣100点护甲获得50点能量", -50, -100),
new DefenseCard("破盾", "扣5点护甲获得1点能量", -1, -5),
new UtilityCard("圣光", "恢复10点生命", 2, 10),
new UtilityCard("生命吸取", "恢复5点生命", 1, 5),
new UtilityCard("能量转化", "恢复1点能量,扣3生命", -1, -3)
};
vector<Enemy*> allEnemies = {
new Enemy("哥布林", 30, 5, 0, "弱小但数量众多的生物"),
new Enemy("兽人战士", 50, 8, 3, "强壮而野蛮的战士"),
new Enemy("骷髅法师", 40, 10, 0, "能够施展黑暗魔法的亡灵"),
new Enemy("巨魔", 70, 12, 5, "再生能力强大的大型怪物"),
new Enemy("暗影刺客", 35, 15, 0, "高伤害但脆弱的刺客"),
new Enemy("黄浩chen", 10, 5, 0, "你的朋友,适合用来练手"),
new Enemy("黄浩chen max", 30, 15, 3, "你的朋友加强版,不是很适合用来练手"),
new Enemy("黄浩chen max pro", 50, 25, 5, "你的朋友最终版,绝对不适合用来练手"),
new Enemy("龙", 100, 20, 10, "最终BOSS,强大的巨龙"),
new Enemy("黄浩chen max pro 觉醒", 150, 75, 15, "你的朋友最终觉醒版,我觉得你不能胜利")
};
public:
RogueCardGame() : gameOver(false), victory(false), currentEnemy(nullptr) {
srand(time(0));
}
~RogueCardGame() {
for (Card* card : allCards) delete card;
for (Enemy* enemy : allEnemies) delete enemy;
delete currentEnemy;
}
void startGame() {
cout << "================================\n";
cout << " 肉鸽卡牌回合制冒险游戏 \n";
cout << "================================\n";
cout << "在每一层地牢中,你需要击败敌人来前进\n";
cout << "使用卡牌需要消耗能量,每回合恢复所有能量\n";
cout << "击败敌人后,你可以获得金币并选择新卡牌\n";
cout << "最终目标是击败第10层的最终BOSS!\n";
cout << "================================\n\n";
while (!gameOver && player.floor <= 10) {
generateEnemy();
battle();
if (!gameOver) {
if (player.floor == 10) {
victory = true;
gameOver = true;
} else {
player.floor++;
shopPhase();
}
}
}
endGame();
}
private:
void generateEnemy() {
if (player.floor == 10) {
// 最终BOSS
currentEnemy = new Enemy(*allEnemies.back());
} else {
// 随机敌人
int index = rand() % allEnemies.size();
currentEnemy = new Enemy(*allEnemies[index]);
}
cout << "\n================================\n";
cout << " 第 " << player.floor << " 层 - " << currentEnemy->name << "\n";
cout << "================================\n";
cout << currentEnemy->description << "\n";
}
void battle() {
player.defense = 0;
while (!currentEnemy->isDefeated() && player.health > 0) {
player.resetEnergy();
player.drawHand();
cout << "\n--------------------------------\n";
cout << "你的状态: 生命(" << player.health << "/" << player.maxHealth << ") ";
cout << "护甲(" << player.defense << ") ";
cout << "能量(" << player.energy << "/" << player.maxEnergy << ")\n";
cout << currentEnemy->name << ": 生命(" << currentEnemy->health << ")\n";
// 玩家回合
playerTurn();
if (currentEnemy->isDefeated()) {
cout << "\n你击败了 " << currentEnemy->name << "!\n";
int goldReward = 10 + player.floor * 5;
player.gold += goldReward;
cout << "获得 " << goldReward << " 金币!\n";
break;
}
// 敌人回合
enemyTurn();
}
player.discardHand();
if (player.health <= 0) {
gameOver = true;
}
}
void playerTurn() {
bool turnEnded = false;
while (!turnEnded && player.health > 0 && !currentEnemy->isDefeated()) {
cout << "\n你的手牌:\n";
for (int i = 0; i < player.hand.size(); i++) {
cout << i + 1 << ". " << player.hand[i]->name;
cout << " (" << player.hand[i]->cost << "能量)";
cout << " - " << player.hand[i]->description << "\n";
}
cout << "0. 结束回合\n";
cout << "选择一张卡牌使用 (0-" << player.hand.size() << "): ";
int choice;
cin >> choice;
if (cin.fail()) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "无效输入,请重新选择。\n";
continue;
}
if (choice == 0) {
turnEnded = true;
} else if (choice > 0 && choice <= player.hand.size()) {
Card* selectedCard = player.hand[choice - 1];
if (selectedCard->cost > player.energy) {
cout << "能量不足!\n";
} else if (!selectedCard->canPlay(player.health, player.defense)) {
if (dynamic_cast<DefenseCard*>(selectedCard) && dynamic_cast<DefenseCard*>(selectedCard)->defense < 0) {
cout << "护甲不足,无法使用此技能!\n";
} else if (dynamic_cast<UtilityCard*>(selectedCard) && dynamic_cast<UtilityCard*>(selectedCard)->healAmount < 0) {
cout << "生命值不足,无法使用此技能!\n";
} else {
cout << "无法使用此卡牌!\n";
}
} else {
player.energy -= selectedCard->cost;
selectedCard->play(player.health, player.defense, currentEnemy->health, currentEnemy->defense);
player.discardPile.push_back(selectedCard);
player.hand.erase(player.hand.begin() + choice - 1);
if (currentEnemy->isDefeated() || player.health <= 0) {
turnEnded = true;
}
}
} else {
cout << "无效选择,请重新输入。\n";
}
}
}
void enemyTurn() {
if (!currentEnemy->isDefeated() && player.health > 0) {
cout << "\n--- " << currentEnemy->name << " 的回合 ---\n";
currentEnemy->takeTurn(player.health, player.defense);
}
}
void shopPhase() {
cout << "\n================================\n";
cout << " 商店与休息区 \n";
cout << "================================\n";
cout << "金币: " << player.gold << "\n";
cout << "1. 休息 (恢复20点生命)\n";
cout << "2. 升级卡牌 (50金币)\n";
cout << "3. 购买新卡牌 (30金币)\n";
cout << "4. 提升最大生命值 (40金币)\n";
cout << "5. 提升最大能量 (100金币)\n";
cout << "0. 继续前进\n";
cout << "选择: ";
int choice;
cin >> choice;
switch (choice) {
case 1:
player.heal(20);
cout << "你休息了一会,恢复了20点生命。当前生命: " << player.health << "/" << player.maxHealth << "\n";
break;
case 2:
if (player.gold >= 50) {
player.gold -= 50;
upgradeCard();
} else {
cout << "金币不足!\n";
}
break;
case 3:
if (player.gold >= 30) {
player.gold -= 30;
buyNewCard();
} else {
cout << "金币不足!\n";
}
break;
case 4:
if (player.gold >= 40) {
player.gold -= 40;
player.maxHealth += 10;
player.health = player.maxHealth;
cout << "最大生命值提升至 " << player.maxHealth << "!\n";
} else {
cout << "金币不足!\n";
}
break;
case 5:
if (player.gold >= 100) {
player.gold -= 100;
player.maxEnergy++;
cout << "最大能量提升至 " << player.maxEnergy << "!\n";
} else {
cout << "金币不足!\n";
}
break;
case 0:
cout << "你继续前进...\n";
break;
default:
cout << "无效选择。\n";
}
}
void buyNewCard() {
cout << "\n可购买的卡牌:\n";
vector<Card*> availableCards;
for (int i = 0; i < 3; i++) {
int index = rand() % allCards.size();
availableCards.push_back(allCards[index]);
}
for (int i = 0; i < availableCards.size(); i++) {
cout << i + 1 << ". " << availableCards[i]->name;
cout << " (" << availableCards[i]->cost << "能量)";
cout << " - " << availableCards[i]->description << "\n";
}
cout << "0. 取消购买\n";
cout << "选择一张卡牌添加到你的牌组: ";
int choice;
cin >> choice;
if (choice > 0 && choice <= availableCards.size()) {
Card* selected = availableCards[choice - 1];
if (dynamic_cast<AttackCard*>(selected)) {
player.addCardToDeck(new AttackCard(
selected->name,
selected->description,
selected->cost,
dynamic_cast<AttackCard*>(selected)->damage
));
} else if (dynamic_cast<DefenseCard*>(selected)) {
player.addCardToDeck(new DefenseCard(
selected->name,
selected->description,
selected->cost,
dynamic_cast<DefenseCard*>(selected)->defense
));
} else if (dynamic_cast<UtilityCard*>(selected)) {
player.addCardToDeck(new UtilityCard(
selected->name,
selected->description,
selected->cost,
dynamic_cast<UtilityCard*>(selected)->healAmount
));
}
cout << "你获得了 " << selected->name << " 卡牌!\n";
} else {
cout << "购买取消。\n";
}
}
void upgradeCard() {
if (player.deck.empty()) {
cout << "你的牌组中没有卡牌可以升级!\n";
return;
}
cout << "\n选择要升级的卡牌:\n";
for (int i = 0; i < player.deck.size(); i++) {
cout << i + 1 << ". " << player.deck[i]->name;
cout << " - " << player.deck[i]->description << "\n";
}
cout << "0. 取消\n";
cout << "选择: ";
int choice;
cin >> choice;
if (choice > 0 && choice <= player.deck.size()) {
Card* card = player.deck[choice - 1];
card->upgrade(); // 直接调用卡牌的升级方法
cout << card->name << " 已升级! 新效果: " << card->description << "\n";
} else {
cout << "升级取消。\n";
}
}
void endGame() {
cout << "\n================================\n";
if (victory) {
cout << " 恭喜你击败了最终BOSS! \n";
cout << " 你成功通关了游戏! \n";
} else if (player.health <= 0) {
cout << " 你被击败了... \n";
cout << " 游戏结束 \n";
}
cout << "================================\n";
cout << "最终层数: " << player.floor << "\n";
cout << "最终金币: " << player.gold << "\n";
cout << "牌组大小: " << player.deck.size() << "\n";
}
};
int main() {
RogueCardGame game;
game.startGame();
return 0;
}
修改内容
1.添加更厉害的卡牌
2.升级系统开放
3.扣血扣盾技能被史诗级削弱
注意事项
发现bug立刻上报我
OvO