C++#include<iostream>
#include<windows.h>
#include<bits/stdc++.h>
using namespace std;
// 精灵结构体,包含属性和技能
struct Spirit {
string name;
int hp;
int attack;
int defense;
string type;
string skill1;
int skill1Damage;
string skill2;
int skill2Damage;
};
// 初始化精灵数据
void initSpirits(Spirit spirits[]) {
spirits[0] = {"kkksc03", 100, 25, 20, "火", "火焰喷射", 30, "燃烧", 20};
spirits[1] = {"洛谷", 120, 20, 25, "水", "水炮", 35, "泡泡", 15};
spirits[2] = {"chen_zhe", 90, 30, 15, "草", "飞叶快刀", 30, "寄生种子", 10};
spirits[3] = {"小粉兔", 80, 35, 10, "电", "十万伏特", 40, "电光一闪", 15};
spirits[4] = {"xht", 110, 22, 23, "土", "地震", 32, "岩崩", 25};
spirits[5] = {"一扶苏一", 95, 28, 18, "风", "龙卷风", 34, "羽毛攻击", 18};
spirits[6] = {"「QQ红包」", 130, 18, 28, "钢", "铁头功", 25, "金属爆破", 35};
spirits[7] = {"ddd", 85, 32, 12, "暗", "暗影爪", 33, "黑夜诅咒", 22};
}
// 显示精灵信息
void showSpiritInfo(Spirit s) {
cout << "精灵名称: " << s.name << endl;
cout << "生命值: " << s.hp << endl;
cout << "攻击力: " << s.attack << endl;
cout << "防御力: " << s.defense << endl;
cout << "属性: " << s.type << endl;
cout << "技能1: " << s.skill1 << " (伤害: " << s.skill1Damage << ")" << endl;
cout << "技能2: " << s.skill2 << " (伤害: " << s.skill2Damage << ")" << endl;
cout << endl;
}
int main(){
Spirit spirits[8];
initSpirits(spirits);
string a[]={"kkksc03","洛谷","chen_zhe","小粉兔","xht","一扶苏一","「QQ红包」","ddd"};
int n1,n2,n3;
int jb1,jb2=50; // 初始金币增加到50
int sp=0; // 碎片数量
// 技能学习系统
string learnedSkills[3] = {"", "", ""};
int skillCount = 0;
// 背包系统
int potions = 0; // 药水数量
int maxPotions = 5; // 最大携带药水数量
laoal:
srand(time(0));
n1=rand()%8+0; // 改为0-7
n2=rand()%8+0;
n3=rand()%8+0;
if(n1==n2||n2==n3||n3==n1)goto laoal;
luaul:
cout<<"你来到了一个充满洛谷精灵的地方,你有以下精灵可以选择:" <<endl;
cout<<"1."<<a[n1]<<" "<<"2."<<a[n2]<<" "<<"3."<<a[n3]<<endl;
cout<<"输入对应数字选择精灵,输入4查看精灵详情:";
int x;
cin>>x;
if(x==4) {
system("cls");
cout << a[n1] << " 详情:" << endl;
showSpiritInfo(spirits[n1]);
cout << a[n2] << " 详情:" << endl;
showSpiritInfo(spirits[n2]);
cout << a[n3] << " 详情:" << endl;
showSpiritInfo(spirits[n3]);
system("pause");
system("cls");
goto luaul;
}
if(x!=1&&x!=3&&x!=2){cout<<"输入错误"<<endl;Sleep(1000);system("cls");goto luaul;}
else if(x==1)x=n1;
else if(x==2)x=n2;
else if(x==3)x=n3;
Spirit mySpirit = spirits[x]; // 获取选中的精灵
int mySpiritHp = mySpirit.hp; // 当前生命值
system("cls");
cout<<"你获得了一只"<<mySpirit.name<<endl;
cout << "属性: " << mySpirit.type << endl;
Sleep(2000);
system("cls");
char b1,b2,b3,b4,b5;
int y;
while(1){
laual:
Sleep(1000);
system("cls");
// 显示玩家状态
cout << "当前精灵: " << mySpirit.name << " (" << mySpiritHp << "/" << mySpirit.hp << ")" << endl;
cout << "金币: " << jb2 << " 碎片: " << sp << " 药水: " << potions << endl;
cout << endl;
cout<<"你想干什么?"<<endl;
cout<<"A.打怪 B.不玩了 C.探索世界 D.查看精灵状态 E.使用药水"<<endl;
cin>>b1;
system("cls");
if(b1==65){ // A.打怪
// 随机生成怪物
srand(time(0));
int enemyIndex = rand()%8;
while(enemyIndex == x) enemyIndex = rand()%8; // 确保怪物不是自己的精灵
Spirit enemy = spirits[enemyIndex];
int enemyHp = enemy.hp;
cout << "遇到了一只" << enemy.name << "!" << endl;
Sleep(1000);
while(1) {
if(mySpiritHp <= 0) {
cout << mySpirit.name << "失去了战斗能力!" << endl;
Sleep(1500);
mySpiritHp = mySpirit.hp / 2; // 生命值恢复一半
break;
}
if(enemyHp <= 0) {
cout << enemy.name << "被击败了!" << endl;
int exp = rand()%15 + 10; // 获得10-24经验值
cout << mySpirit.name << "获得了" << exp << "点经验值!" << endl;
// 随机获得金币
jb1 = rand()%15 + 5;
cout << "获得了" << jb1 << "金币!" << endl;
jb2 += jb1;
// 有几率获得碎片
if(rand()%3 == 0) {
sp++;
cout << "获得了一块碎片!" << endl;
}
Sleep(2000);
break;
}
lgagl:
cout << mySpirit.name << " (" << mySpiritHp << "/" << mySpirit.hp << ") vs "
<< enemy.name << " (" << enemyHp << "/" << enemy.hp << ")" << endl;
cout << "你想怎么做?" << endl;
cout << "A.攻击 B.使用技能 C.查看技能 D.逃跑" << endl;
cin >> b2;
system("cls");
if(b2==65) { // A.攻击
int damage = mySpirit.attack - enemy.defense/2;
if(damage < 5) damage = 5; // 最小伤害
enemyHp -= damage;
cout << mySpirit.name << "进行了普通攻击,造成了" << damage << "点伤害!" << endl;
// 怪物反击
if(enemyHp > 0) {
int enemyDamage = enemy.attack - mySpirit.defense/2;
if(enemyDamage < 5) enemyDamage = 5;
mySpiritHp -= enemyDamage;
cout << enemy.name << "反击,造成了" << enemyDamage << "点伤害!" << endl;
}
Sleep(1500);
system("cls");
}
else if(b2==66) { // B.使用技能
if(skillCount == 0) {
cout << "你还没有学习任何技能!" << endl;
Sleep(1000);
system("cls");
goto lgagl;
}
cout << "选择要使用的技能:" << endl;
for(int i=0; i<skillCount; i++) {
cout << i+1 << ". " << learnedSkills[i] << endl;
}
cout << skillCount+1 << ". 返回" << endl;
int skillChoice;
cin >> skillChoice;
system("cls");
if(skillChoice >= 1 && skillChoice <= skillCount) {
// 使用技能
int damage = rand()%10 + 15; // 技能基础伤害
cout << mySpirit.name << "使用了" << learnedSkills[skillChoice-1] << ",造成了"
<< damage << "点伤害!" << endl;
enemyHp -= damage;
// 怪物反击
if(enemyHp > 0) {
int enemyDamage = enemy.attack - mySpirit.defense/2;
if(enemyDamage < 5) enemyDamage = 5;
mySpiritHp -= enemyDamage;
cout << enemy.name << "反击,造成了" << enemyDamage << "点伤害!" << endl;
}
Sleep(1500);
system("cls");
}
}
else if(b2==67) { // C.查看技能
system("cls");
cout << mySpirit.name << "的技能:" << endl;
cout << "1. " << mySpirit.skill1 << " (伤害: " << mySpirit.skill1Damage << ")" << endl;
cout << "2. " << mySpirit.skill2 << " (伤害: " << mySpirit.skill2Damage << ")" << endl;
if(skillCount > 0) {
cout << "学习的技能:" << endl;
for(int i=0; i<skillCount; i++) {
cout << i+3 << ". " << learnedSkills[i] << endl;
}
}
else {
cout << "没有学习的技能" << endl;
}
system("pause");
system("cls");
}
else if(b2==68) { // D.逃跑
int escapeChance = rand()%100;
if(escapeChance > 30) {
cout << "你们成功逃走了!" << endl;
Sleep(1000);
break;
}
else {
cout << "逃跑失败!" << endl;
// 怪物反击
int enemyDamage = enemy.attack - mySpirit.defense/2;
if(enemyDamage < 5) enemyDamage = 5;
mySpiritHp -= enemyDamage;
cout << enemy.name << "趁机攻击,造成了" << enemyDamage << "点伤害!" << endl;
Sleep(1500);
system("cls");
}
}
else {
cout<<"输入错误"<<endl;
Sleep(1000);
system("cls");
goto lgagl;
}
}
}
else if(b1==66){ // B.不玩了
cout<<"好的,再见"<<endl;
return 0;
}
else if(b1==67){ // C.探索世界
srand(time(0));
y=rand()%5+1; // 增加更多探索可能性
if(y==1){ // 村庄
cout<<"你发现了一个村庄,这里的人们热情好客,招待了你。"<<endl;
lkakl:
Sleep(1000);
system("cls");
// 显示玩家状态
cout << "当前精灵: " << mySpirit.name << " (" << mySpiritHp << "/" << mySpirit.hp << ")" << endl;
cout << "金币: " << jb2 << " 碎片: " << sp << " 药水: " << potions << endl;
cout << endl;
cout<<"你要干什么?"<<endl;
cout<<"A.探索这个村庄 B.与村民战斗 C.离开"<<endl;
cin>>b3;
system("cls");
if(b3==65){ // A.探索村庄
b5=rand()%4+0; // 增加更多可能性
if(b5==1){ // 药水商人
cout<<"你遇到了一个药水商人"<<endl;
cout<<"他在售卖以下物品:"<<endl;
cout<<"1. 治疗药水 - 恢复50点生命值 (20金币)"<<endl;
cout<<"2. 超级药水 - 完全恢复生命值 (50金币)"<<endl;
cout<<"3. 离开"<<endl;
int buyChoice;
cin >> buyChoice;
system("cls");
if(buyChoice == 1) { // 购买治疗药水
if(jb2 >= 20 && potions < maxPotions) {
jb2 -= 20;
potions++;
cout << "你购买了一瓶治疗药水!" << endl;
}
else if(potions >= maxPotions) {
cout << "你的药水太多了,无法携带更多!" << endl;
}
else {
cout << "钱不够QWQ" << endl;
}
Sleep(1000);
system("cls");
goto lkakl;
}
else if(buyChoice == 2) { // 购买超级药水
if(jb2 >= 50) {
jb2 -= 50;
mySpiritHp = mySpirit.hp;
cout << "你使用了超级药水," << mySpirit.name << "的生命值已完全恢复!" << endl;
}
else {
cout << "钱不够QWQ" << endl;
}
Sleep(1000);
system("cls");
goto lkakl;
}
}
else if(b5==2){ // 机械商人
cout<<"你遇到了一个机械商人"<<endl;
cout<<"他在售卖机械碎片,碎片10元/块,要买吗?"<<endl;
cout<<"A.要 B.不要"<<endl;
cin>>b4;
system("cls");
if(b4==65){
if(jb2<10){
cout<<"钱不够QWQ"<<endl;
Sleep(1000);
system("cls");
goto lkakl;
}
else {
cout<<"你得到了一块碎片"<<endl;
sp++;
cout<<"碎片+1"<<endl;
cout<<"金币-10"<<endl;
jb2-=10;
Sleep(1500);
system("cls");
goto lkakl;
}
}
else if(b4==66){
cout<<"ok"<<endl;
Sleep(1000);
system("cls");
goto lkakl;
}
else {
cout<<"输入错误"<<endl;
Sleep(1000);
system("cls");
goto lkakl;
}
}
else if(b5==3){ // 技能导师
if(sp >= 3 && skillCount < 3) {
cout << "你遇到了一位技能导师!" << endl;
cout << "他可以教你的精灵一个新技能,但需要3块碎片。" << endl;
cout << "要学习吗? (Y/N)" << endl;
char learn;
cin >> learn;
if(learn == 'Y' || learn == 'y') {
sp -= 3;
string newSkills[5] = {"重击", "能量球", "快速攻击", "护盾", "龙卷风"};
int skillIndex = rand()%5;
learnedSkills[skillCount] = newSkills[skillIndex];
skillCount++;
cout << mySpirit.name << "学会了新技能:" << newSkills[skillIndex] << "!" << endl;
}
}
else if(skillCount >= 3) {
cout << "你遇到了一位技能导师,但你的精灵已经学会了所有能学的技能。" << endl;
}
else {
cout << "你遇到了一位技能导师,但你没有足够的碎片。" << endl;
}
Sleep(2000);
system("cls");
goto lkakl;
}
else { // 普通村民
cout << "你遇到了一位普通村民,他给了你一些建议..." << endl;
Sleep(1500);
system("cls");
goto lkakl;
}
}
else if(b3==66){ // B.与村民战斗
// 随机选择一个村民精灵战斗
srand(time(0));
int villagerIndex = rand()%8;
while(villagerIndex == x) villagerIndex = rand()%8;
Spirit villager = spirits[villagerIndex];
int villagerHp = villager.hp;
cout << "你向村民发起了挑战!他派出了" << villager.name << "!" << endl;
Sleep(1500);
while(1) {
if(mySpiritHp <= 0) {
cout << mySpirit.name << "失去了战斗能力!你输了!" << endl;
jb2 = jb2 / 2; // 输掉一半金币
cout << "你失去了一半的金币!" << endl;
Sleep(2000);
mySpiritHp = mySpirit.hp / 2;
break;
}
if(villagerHp <= 0) {
cout << villager.name << "被击败了!你赢了!" << endl;
int reward = rand()%30 + 15;
jb2 += reward;
cout << "你获得了" << reward << "金币!" << endl;
Sleep(2000);
break;
}
cout << mySpirit.name << " (" << mySpiritHp << "/" << mySpirit.hp << ") vs "
<< villager.name << " (" << villagerHp << "/" << villager.hp << ")" << endl;
cout << "你想怎么做?" << endl;
cout << "A.攻击 B.使用技能 C.查看技能 D.认输" << endl;
cin >> b4;
system("cls");
if(b4==65) { // A.攻击
int damage = mySpirit.attack - villager.defense/2;
if(damage < 5) damage = 5;
villagerHp -= damage;
cout << mySpirit.name << "进行了普通攻击,造成了" << damage << "点伤害!" << endl;
// 村民反击
if(villagerHp > 0) {
int villagerDamage = villager.attack - mySpirit.defense/2;
if(villagerDamage < 5) villagerDamage = 5;
mySpiritHp -= villagerDamage;
cout << villager.name << "反击,造成了" << villagerDamage << "点伤害!" << endl;
}
Sleep(1500);
system("cls");
}
else if(b4==66) { // B.使用技能
if(skillCount == 0) {
cout << "你还没有学习任何技能!" << endl;
Sleep(1000);
system("cls");
continue;
}
cout << "选择要使用的技能:" << endl;
for(int i=0; i<skillCount; i++) {
cout << i+1 << ". " << learnedSkills[i] << endl;
}
cout << skillCount+1 << ". 返回" << endl;
int skillChoice;
cin >> skillChoice;
system("cls");
if(skillChoice >= 1 && skillChoice <= skillCount) {
int damage = rand()%10 + 15;
cout << mySpirit.name << "使用了" << learnedSkills[skillChoice-1] << ",造成了"
<< damage << "点伤害!" << endl;
villagerHp -= damage;
// 村民反击
if(villagerHp > 0) {
int villagerDamage = villager.attack - mySpirit.defense/2;
if(villagerDamage < 5) villagerDamage = 5;
mySpiritHp -= villagerDamage;
cout << villager.name << "反击,造成了" << villagerDamage << "点伤害!" << endl;
}
Sleep(1500);
system("cls");
}
}
else if(b4==67) { // C.查看技能
system("cls");
cout << mySpirit.name << "的技能:" << endl;
cout << "1. " << mySpirit.skill1 << " (伤害: " << mySpirit.skill1Damage << ")" << endl;
cout << "2. " << mySpirit.skill2 << " (伤害: " << mySpirit.skill2Damage << ")" << endl;
if(skillCount > 0) {
cout << "学习的技能:" << endl;
for(int i=0; i<skillCount; i++) {
cout << i+3 << ". " << learnedSkills[i] << endl;
}
}
else {
cout << "没有学习的技能" << endl;
}
system("pause");
system("cls");
}
else if(b4==68) { // D.认输
cout << "你认输了!" << endl;
jb2 = jb2 / 2;
cout << "你失去了一半的金币!" << endl;
Sleep(2000);
break;
}
}
goto lkakl;
}
else if(b3!=67){ // 不是C.离开
cout<<"输入错误"<<endl;
Sleep(1000);
system("cls");
goto lkakl;
}
}
else if(y==2){ // 沙漠建筑
cout<<"你发现了一个沙漠里的建筑,你发现了宝藏"<<endl;
Sleep(500);
system("cls");
jb1=rand()%20+10; // 增加奖励
cout<<"金币+"<<jb1<<endl;
jb2+=jb1;
// 有几率找到药水
if(rand()%3 == 0 && potions < maxPotions) {
potions++;
cout << "你找到了一瓶治疗药水!" << endl;
}
Sleep(1500);
}
else if(y==3){ // 丛林遗迹
cout<<"你发现了一个丛林遗迹,你发现很多好东西"<<endl;
Sleep(500);
system("cls");
jb1=rand()%25+15; // 增加奖励
cout<<"金币+"<<jb1<<endl;
jb2+=jb1;
// 有几率找到碎片
if(rand()%2 == 0) {
int fragmentCount = rand()%3 + 1;
sp += fragmentCount;
cout << "你找到了" << fragmentCount << "块碎片!" << endl;
}
Sleep(1500);
}
else if(y==4){ // 神秘洞穴
cout << "你发现了一个神秘洞穴,要进去看看吗? (Y/N)" << endl;
char enter;
cin >> enter;
if(enter == 'Y' || enter == 'y') {
system("cls");
cout << "你进入了洞穴... 里面很暗..." << endl;
Sleep(1000);
// 随机事件
int caveEvent = rand()%4;
if(caveEvent == 0) {
cout << "你踩到了陷阱!" << endl;
int trapDamage = rand()%20 + 10;
mySpiritHp -= trapDamage;
cout << mySpirit.name << "受到了" << trapDamage << "点伤害!" << endl;
if(mySpiritHp <= 0) {
cout << mySpirit.name << "失去了战斗能力!" << endl;
mySpiritHp = mySpirit.hp / 2;
}
}
else if(caveEvent == 1) {
cout << "你发现了一个宝箱!" << endl;
Sleep(1000);
cout << "宝箱里有..." << endl;
Sleep(1000);
int treasureType = rand()%3;
if(treasureType == 0) {
jb1 = rand()%50 + 30;
jb2 += jb1;
cout << jb1 << "金币!" << endl;
}
else if(treasureType == 1) {
int fragmentCount = rand()%5 + 2;
sp += fragmentCount;
cout << fragmentCount << "块碎片!" << endl;
}
else {
potions = maxPotions; // 满药水
cout << "几瓶治疗药水!你的药水已装满。" << endl;
}
}
else if(caveEvent == 2) {
cout << "你遇到了一只神秘的精灵!" << endl;
Sleep(1000);
cout << "它教会了你的精灵一个强大的技能!" << endl;
if(skillCount < 3) {
string secretSkills[3] = {"能量爆破", "神圣庇护", "元素风暴"};
int skillIndex = rand()%3;
learnedSkills[skillCount] = secretSkills[skillIndex];
skillCount++;
cout << mySpirit.name << "学会了新技能:" << secretSkills[skillIndex] << "!" << endl;
}
else {
cout << "但是你的精灵已经学会了所有技能..." << endl;
}
}
else {
cout << "你在洞穴里迷路了..." << endl;
Sleep(2000);
cout << "经过一番探索,你终于找到了出口。" << endl;
}
Sleep(2000);
}
}
else { // 随机事件
int randomEvent = rand()%3;
if(randomEvent == 0) {
cout << "你遇到了一个旅行者,他给了你一些金币。" << endl;
jb1 = rand()%15 + 5;
jb2 += jb1;
cout << "获得了" << jb1 << "金币!" << endl;
}
else if(randomEvent == 1) {
cout << "你不小心掉进了河里!" << endl;
mySpiritHp -= rand()%15 + 5;
cout << mySpirit.name << "受到了一些伤害!" << endl;
if(mySpiritHp <= 0) {
cout << mySpirit.name << "失去了战斗能力!" << endl;
mySpiritHp = mySpirit.hp / 2;
}
}
else {
cout << "你遇到了一个精灵训练师,他向你发起了挑战!" << endl;
// 简单的战斗模拟
int trainerStrength = rand()%20 + 30;
int result = jb2 + mySpirit.attack - trainerStrength;
if(result > 0) {
cout << "你赢得了战斗!" << endl;
jb1 = rand()%30 + 20;
jb2 += jb1;
cout << "获得了" << jb1 << "金币!" << endl;
}
else {
cout << "你输了战斗..." << endl;
jb1 = jb2 / 3;
jb2 -= jb1;
cout << "失去了" << jb1 << "金币!" << endl;
}
}
Sleep(2000);
}
}
else if(b1==68) { // D.查看精灵状态
system("cls");
cout << mySpirit.name << "的状态:" << endl;
showSpiritInfo(mySpirit);
cout << "当前生命值: " << mySpiritHp << "/" << mySpirit.hp << endl;
if(skillCount > 0) {
cout << "学习的技能:" << endl;
for(int i=0; i<skillCount; i++) {
cout << i+1 << ". " << learnedSkills[i] << endl;
}
}
else {
cout << "没有学习的技能" << endl;
}
system("pause");
system("cls");
}
else if(b1==69) { // E.使用药水
if(potions > 0) {
potions--;
int healAmount = 50;
mySpiritHp += healAmount;
if(mySpiritHp > mySpirit.hp) mySpiritHp = mySpirit.hp;
cout << "你使用了一瓶治疗药水," << mySpirit.name << "恢复了" << healAmount << "点生命值!" << endl;
Sleep(1500);
}
else {
cout << "你没有药水了!" << endl;
Sleep(1000);
}
}
else{
cout<<"输入错误"<<endl;
Sleep(1000);
system("cls");
goto laual;
}
}
return 0;
}