#include<bits/stdc++.h>
#include <iostream>
#include <time.h>
#include <cstdlib>  
#include <ctime>
  
  
// 玩家结构体  
struct Player {  
    int health;  
    int p;  
  
    Player(int h, int a) : health(h), p(a) {}  
};  
  
// 嶂免枝结构体  
struct Pest {  
    int health;  
  
    Pest(int h) : health(h) {}  
};  
  
void displayStatus(const Player& player, const Pest& pest) {  
    std::cout << "玩家状态:\n";  
    std::cout << "生命值: " << player.health << "\n";  
    std::cout << "攻击力: " << player.p << "\n";  
    std::cout << "嶂免枝状态:\n";  
    std::cout << "生命值: " << pest.health << "\n";  
}  
  
void p(Player& player, Pest& pest) {  
    int damage = player.p;  
    pest.health -= damage;  
    if (pest.health <= 0) {  
        std::cout << "你成功除害了!你打败了陈晞,成为了华附的英雄。你的事迹也成为了一代传奇...\n";  
    } else {  
        std::cout << "回答正确!!!你攻击了嶂免枝,造成了 " << damage << " 点伤害。\n";  
    }  
}  
  
int main() {  
    // 初始化随机数生成器  
    std::srand(static_cast<unsigned>(std::time(0)));  
  
    // 创建玩家和嶂免枝  
    Player player(100, 20); // 玩家初始生命值100,攻击力20  
    Pest pest(50);         // 嶂免枝初始生命值50  
  
    // 游戏循环  
    while (player.health > 0 && pest.health > 0) {  
        displayStatus(player, pest);  
        std::cout << "判断题:张达轩是否强大?输入 'p' 表示非常强大,输入 'q' 表示非常弱小: ";  
        std::string input;  
        std::cin >> input;  
  
        if (input == "p") {  
            p(player, pest);  
        } else if (input == "q") {  
            std::cout << "回答错误!!!。\n";  
            break;  
        } else {  
            std::cout << "无效命令,请重新输入。\n";  
        }  
  
        // 模拟嶂免枝反击(可选)  
        if (pest.health > 0) {  
            int pestp = std::rand() % 10 + 5; // 嶂免枝攻击力随机在5到14之间  
            player.health -= pestp;  
            std::cout << "嶂免枝反击了,造成了 " << pestp << " 点伤害。\n";  
        }  
  
        // 检查玩家是否存活  
        if (player.health <= 0) {  
            std::cout << "你被嶂免枝击败了。\n";  
        }  
    }  
  
    std::cout << "游戏结束。\n";  
    return 0;  
}