当前位置: 首页 > news >正文

火柴人遗产战争五

二话不说咱们直接上代码,不说废话了

 

#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <map>
#include <algorithm>

using namespace std;

// 角色类
class Character {
private:
    string name;
    int health;
    int maxHealth;
    int attack;
    int defense;
    int speed;
    int level;
    int exp;
    int expToNextLevel;
    
public:
    Character(string n, int h, int a, int d, int s) 
        : name(n), health(h), maxHealth(h), attack(a), defense(d), speed(s), level(1), exp(0), expToNextLevel(100) {}
    
    // 获取属性
    string getName() const { return name; }
    int getHealth() const { return health; }
    int getMaxHealth() const { return maxHealth; }
    int getAttack() const { return attack; }
    int getDefense() const { return defense; }
    int getSpeed() const { return speed; }
    int getLevel() const { return level; }
    int getExp() const { return exp; }
    int getExpToNextLevel() const { return expToNextLevel; }
    
    // 战斗方法
    void takeDamage(int damage) {
        int actualDamage = max(1, damage - defense);
        health = max(0, health - actualDamage);
    }
    
    void heal(int amount) {
        health = min(maxHealth, health + amount);
    }
    
    bool isAlive() const {
        return health > 0;
    }
    
    // 经验与升级6
    void gainExp(int amount) {
        exp += amount;
        while (exp >= expToNextLevel) {
            levelUp();
        }
    }
    
    void levelUp() {
        exp -= expToNextLevel;
        level++;
        maxHealth += 10;
        health = maxHealth;
        attack += 5;
        defense += 3;
        speed += 2;
        expToNextLevel = static_cast<int>(expToNextLevel * 1.5);
        
        cout << name << " 升级了! 现在是 " << level << " 级!" << endl;
        cout << "生命值: " << maxHealth << " 攻击力: " << attack << " 防御力: " << defense << endl;
    }
    
    // 显示状态
    void displayStatus() const {
        cout << name << " Lv." << level << " HP: " << health << "/" << maxHealth 
             << " 攻击:" << attack << " 防御:" << defense << " 速度:" << speed 
             << " EXP:" << exp << "/" << expToNextLevel << endl;
    }
};

// 技能类
class Skill {
private:
    string name;
    string description;
    int damageMultiplier;
    int manaCost;
    
public:
    Skill(string n, string desc, int mult, int cost)
        : name(n), description(desc), damageMultiplier(mult), manaCost(cost) {}
    
    string getName() const { return name; }
    string getDescription() const { return description; }
    int getDamageMultiplier() const { return damageMultiplier; }
    int getManaCost() const { return manaCost; }
};

// 游戏类
class StickmanLegacyWar {
private:
    Character player;
    vector<Character> enemies;
    vector<Skill> skills;
    int currentEnemyIndex;
    bool gameOver;
    
    // 创建敌人
    void createEnemies() {
        enemies.clear();
        enemies.push_back(Character("初级火柴人", 50, 10, 5, 8));
        enemies.push_back(Character("中级火柴人", 80, 15, 8, 10));
        enemies.push_back(Character("高级火柴人", 120, 20, 12, 12));
        enemies.push_back(Character("精英火柴人", 180, 25, 15, 15));
        enemies.push_back(Character("火柴人首领", 250, 30, 20, 18));
    }
    
    // 创建技能
    void createSkills() {
        skills.clear();
        skills.push_back(Skill("普通攻击", "基本的物理攻击", 1, 0));
        skills.push_back(Skill("重击", "强力的物理攻击", 2, 10));
        skills.push_back(Skill("火焰冲击", "火焰元素攻击", 3, 20));
        skills.push_back(Skill("雷霆一击", "雷电元素攻击", 4, 30));
    }
    
    // 显示战斗界面
    void displayBattleScreen() {
        system("cls");
        cout << "========== 火柴人遗产战争 ==========" << endl;
        cout << endl;
        
        // 显示敌人
        cout << "敌人: ";
        enemies[currentEnemyIndex].displayStatus();
        
        // 绘制简单的火柴人
        drawStickman();
        
        cout << endl;
        
        // 显示玩家
        cout << "玩家: ";
        player.displayStatus();
        
        cout << endl;
    }
    
    // 绘制火柴人
    void drawStickman() {
        cout << "    O" << endl;
        cout << "   /|\\" << endl;
        cout << "   / \\" << endl;
        cout << "===========" << endl;
    }
    
    // 显示技能列表
    void displaySkills() {
        cout << "可用技能:" << endl;
        for (int i = 0; i < skills.size(); i++) {
            cout << i + 1 << ". " << skills[i].getName() << " - " << skills[i].getDescription() 
                 << " (伤害倍数:" << skills[i].getDamageMultiplier() << ")" << endl;
        }
        cout << skills.size() + 1 << ". 逃跑" << endl;
    }
    
    // 玩家回合
    void playerTurn() {
        cout << "你的回合! 选择行动:" << endl;
        displaySkills();
        
        int choice;
        cin >> choice;
        
        if (choice < 1 || choice > skills.size() + 1) {
            cout << "无效选择!" << endl;
            playerTurn();
            return;
        }
        
        if (choice == skills.size() + 1) {
            // 逃跑
            cout << "你试图逃跑..." << endl;
            if (rand() % 100 < 30) { // 30% 逃跑成功率
                cout << "逃跑成功!" << endl;
                gameOver = true;
            } else {
                cout << "逃跑失败!" << endl;
            }
            return;
        }
        
        // 使用技能
        Skill selectedSkill = skills[choice - 1];
        int damage = player.getAttack() * selectedSkill.getDamageMultiplier();
        
        cout << "你使用了 " << selectedSkill.getName() << "!" << endl;
        cout << "对 " << enemies[currentEnemyIndex].getName() << " 造成了 " << damage << " 点伤害!" << endl;
        
        enemies[currentEnemyIndex].takeDamage(damage);
    }
    
    // 敌人回合
    void enemyTurn() {
        cout << enemies[currentEnemyIndex].getName() << " 的回合!" << endl;
        
        // 简单的AI: 随机选择攻击方式
        int damage = enemies[currentEnemyIndex].getAttack() * (1 + rand() % 2);
        
        cout << enemies[currentEnemyIndex].getName() << " 攻击了你!" << endl;
        cout << "你受到了 " << damage << " 点伤害!" << endl;
        
        player.takeDamage(damage);
    }
    
    // 检查战斗是否结束
    void checkBattleEnd() {
        if (!enemies[currentEnemyIndex].isAlive()) {
            int expGained = 50 + currentEnemyIndex * 30;
            cout << "你击败了 " << enemies[currentEnemyIndex].getName() << "!" << endl;
            cout << "获得了 " << expGained << " 点经验值!" << endl;
            
            player.gainExp(expGained);
            
            // 移动到下一个敌人或结束游戏
            currentEnemyIndex++;
            if (currentEnemyIndex >= enemies.size()) {
                cout << "恭喜! 你击败了所有敌人!" << endl;
                gameOver = true;
            } else {
                cout << "下一个敌人: " << enemies[currentEnemyIndex].getName() << endl;
                cout << "按任意键继续..." << endl;
                cin.ignore();
                cin.get();
            }
        }
        
        if (!player.isAlive()) {
            cout << "你被击败了! 游戏结束!" << endl;
            gameOver = true;
        }
    }
    
public:
    StickmanLegacyWar() 
        : player("玩家", 100, 15, 10, 12), currentEnemyIndex(0), gameOver(false) {
        srand(time(0));
        createEnemies();
        createSkills();
    }
    
    // 开始游戏
    void startGame() {
        cout << "欢迎来到火柴人遗产战争!" << endl;
        cout << "使用技能击败所有敌人,提升你的角色!" << endl;
        cout << "按任意键开始游戏..." << endl;
        cin.ignore();
        cin.get();
        
        while (!gameOver) {
            displayBattleScreen();
            
            // 根据速度决定行动顺序
            if (player.getSpeed() >= enemies[currentEnemyIndex].getSpeed()) {
                playerTurn();
                if (gameOver) break;
                
                if (enemies[currentEnemyIndex].isAlive()) {
                    enemyTurn();
                }
            } else {
                enemyTurn();
                if (player.isAlive()) {
                    playerTurn();
                }
            }
            
            checkBattleEnd();
            
            if (!gameOver) {
                cout << "按任意键继续..." << endl;
                cin.ignore();
                cin.get();
            }
        }
        
        cout << "游戏结束! 感谢游玩!" << endl;
    }
};

int main() {
    StickmanLegacyWar game;
    game.startGame();
    return 0;
}

如果有人能在评论区告诉我怎么发代码框,那就谢谢了

 

 

http://www.dtcms.com/a/496455.html

相关文章:

  • 学校网站建设代码怎么自己制作网页
  • [嵌入式系统-134]:目前市面上主流的智能体的硬件开发板
  • urllib.request.Request
  • 免费制作图片加文字如何做好网站站内优化
  • 阿里云代理商:适合使用CDN 预热的场景有哪些?
  • VMware
  • 企业网站pc优化网页设计包含的内容
  • 基于模拟退火算法解决带容量限制车辆路径问题的MATLAB实现
  • 安徽两学一做网站360 网站优化
  • 网站导航条图片素材wordpress默认固定链接
  • 与您探讨压电薄膜测试在电学检测领域的主要应用有哪些?
  • 杭州怎样建设网站建筑网站模板
  • 基于HTML 使用星辰拼出爱心,并附带闪烁+流星+点击生成流星
  • RHCSA基础指令整理
  • 下载黑龙江建设网官网网站用户登录网站开发
  • 广州网站建设定制费用前端开发有前途吗
  • 图扑 HT 数字孪生在智慧加油站中的技术实现与应用解析
  • 【NGINX实战】NGINX启用Gzip压缩(优化前端资源加载速度)
  • 企业营销型网站建设厂家海门网站建设制作
  • 装饰设计网站模板重庆知名网站建设公司
  • 【一篇为了Scaling law而整容的文章】Pre-training under infinite compute 论文阅读笔记
  • 定制网站型网站开发企业oa系统免费
  • 联通公司网站谁做的我想做电商
  • 网站建设_网站设计 app制作西城网站建设
  • 悟空AI CRM:发票功能,数字化发票管理的高效解决方案
  • 自己开发一个网站多少钱建造师个人业绩查询
  • 淘宝网站建设的目标是什么网站广告怎么赚钱
  • SpringBoot2整合Redis
  • 【CVOR】即插即用SCConv:新一代卷积模块,显著提升CNN效率与性能
  • 密云网站建设服务wordpress 写php页面跳转