c++小游戏,题材:《蛊真人》
站在你面前的是:谋害花季少女为求修为桿升屠杀血亲族人来为自己提高资质用孩童兄妹练蛊格斗场中下死手来获取利益暗算帮助了自己无数次的琅琊地灵仙人之位大肆屠杀凡人只为削减敌方气运最后哪怕登临尊位依旧以敌方弱小的蛊仙威逼协迫别人的炼天魔尊古月方源。
·
站在你面前的是:
谋害花季少女为求修为桿升
屠杀血亲族人来为自己提高资质
用孩童兄妹练蛊
格斗场中下死手来获取利益
暗算帮助了自己无数次的琅琊地灵
仙人之位大肆屠杀凡人只为削减敌方气运
最后哪怕登临尊位依旧以敌方弱小的蛊仙威逼协迫别人的
炼天魔尊古月方源
1.帅照



2.方源语录
1.
落魄谷中寒风吹,春秋蝉鸣少年归。荡魂山处石人泪,定仙游走魔向北。逆流河上万千退,爱情不敌坚持泪。宿命天成命中败,仙尊悔而我不悔。
2.
我乃三转巅峰,何人敢杀我,何人能杀我!
3.
岂不闻天无绝人之路,只要我想走,路就在脚下!
3.代码
废话不多说,放代码:
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include<bits/stdc++.h>
#include <windows.h>
#include <time.h>
using namespace std;
int p,t;
string s;
class Player;
// ================== 蛊虫种类枚举 ==================
enum GuType {
GU_A,
GU_B,
GU_C,
GU_D,
GU_E,
GU_F,
GU_G,
GU_H,
GU_I,
GU_J,
GU_L,
GU_M,
GU_N,
GU_O,
GU_P,
GU_Q,
GU_R,
GU_S,
GU_T,
GU_U,
GU_V,
GU_W,
GU_X,
GU_Y,
GU_Z,
GU_LIFE_BOOST, // 添加这一行
GU_HEAL // 疗伤类蛊虫
};
string getGuTypeName(enum GuType type);
// ================== 蛊虫类 Gu ==================
class Gu {
public:
string name;
enum GuType type;
int power;
int transformation;
Gu(string n, enum GuType t, int p, int trans);
string getTypeName() const;
void applyEffect(Player& player); // 声明 applyEffect
};
// ================== 玩家境界结构体 ==================
struct PlayerStage {
int transformation; // 当前几转(1~9)
string stage; // 阶段:初阶、中阶、高阶、巅峰
PlayerStage() : transformation(1), stage("初阶") {}
void nextStage() {
if (stage == "初阶") stage = "中阶";
else if (stage == "中阶") stage = "高阶";
else if (stage == "高阶") stage = "巅峰";
else {
transformation++;
stage = "初阶";
if(transformation > 5)p=1;
if (transformation > 9) transformation = 9;
}
t=transformation;s=stage;
}
string toString() const {
return string("【") + (char)('0' + transformation) + "转" + stage + "】";
}
int getRequiredExp() const {
return transformation * transformation * 100;
}
};
// ================== 玩家类 Player ==================
class Player {
public:
int health;
int maxHealth;
int life; // 寿命
int baseLife; // 基础寿命
int exp; // 经验
PlayerStage stage;
vector<Gu> guList;
vector<Gu> unrefinedGuBag;
map<string, int> inventory;
Player();
void exploreWild();
void refineGu();
void cultivate(); // 修炼
void addExp(int amount);
void checkLevelUp();
bool consumeLife(int amount); // 是否能扣除寿命
void healLife(int amount); // 使用寿蛊恢复寿命
void showStatus();
void useItem(const string& itemName); // 使用物品或蛊虫
void battle();
};
// ================== 函数实现 ==================
void color(int a){//颜色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void HideCursor(){//不显示光标
CONSOLE_CURSOR_INFO cur={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
}
void ShowCursor(){//显示光标
CONSOLE_CURSOR_INFO cur={1,1};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
}
string getGuTypeName(enum GuType type) {
switch (type) {
case GU_A: return "剑道";
case GU_B: return "魂道";
case GU_C: return "奴道";
case GU_D: return "力道";
case GU_E: return "天道";
case GU_F: return "毒道";
case GU_G: return "水道";
case GU_H: return "暗道";
case GU_I: return "信道";
case GU_J: return "变化道";
case GU_L: return "血道";
case GU_M: return "刀道";
case GU_N: return "雷道";
case GU_O: return "光道";
case GU_P: return "骨道";
case GU_Q: return "金道";
case GU_R: return "宇道";
case GU_S: return "律道";
case GU_T: return "木道";
case GU_U: return "炎道";
case GU_V: return "人道";
case GU_W: return "音道";
case GU_X: return "杀道";
case GU_Y: return "智道";
case GU_Z: return "土道";
default: return "未知";
}
}
Gu::Gu(string n, enum GuType t, int p, int trans)
: name(n), type(t), power(p), transformation(trans) {}
string Gu::getTypeName() const {
return getGuTypeName(type);
}
void Gu::applyEffect(Player& player) {
if (type == GU_LIFE_BOOST) {
player.healLife(power);
} else if (type == GU_HEAL) {
player.health += power;
if (player.health > player.maxHealth) {
player.health = player.maxHealth;
}
cout << "你通过炼化获得了 " << power << " 点生命值恢复。\n";
}
}
Player::Player()
: health(100), maxHealth(100), life(100), baseLife(100), exp(0) {
inventory["疗伤药"] = 3;
inventory["大疗伤药"] = 1;
srand((unsigned)time(NULL));
}
void Player::showStatus() {
if(t == 3&&s == "巅峰")cout<<"我乃三转巅峰,何人敢杀我,何人能杀我!"<<endl;
if(t == 5&&s == "巅峰")cout<<"岂不闻天无绝人之路,只要我想走,路就在脚下!"<<endl;
cout << "\n===== 当前状态 =====\n";
cout << "生命值: " << health << "/" << maxHealth << endl;
cout << "寿命: " << life << " 年\n";
cout << "境界: " << stage.toString() ;
if(p==1)cout<<"(蛊仙)";
cout<< endl;
cout << "经验: " << exp << "/" << stage.getRequiredExp() << endl;
cout << "蛊虫列表:\n";
int i;
for (i = 0; i < (int)guList.size(); ++i) {
Gu g = guList[i];
cout << i << ". " << g.name << "(" << g.transformation << "转"
<< g.getTypeName() << ",攻击力:" << g.power << ")\n";
}
cout << "未炼化蛊虫背包:\n";
for (i = 0; i < (int)unrefinedGuBag.size(); ++i) {
Gu g = unrefinedGuBag[i];
cout << i << ". [未炼化] " << g.name << "(" << g.transformation << "转"
<< g.getTypeName() << ")\n";
}
cout << "背包: 疗伤药 x" << inventory["疗伤药"]
<< ",大疗伤药 x" << inventory["大疗伤药"] << endl;
}
bool Player::consumeLife(int amount) {
if (life - amount <= 0) {
cout << "你的寿命已经耗尽,游戏结束。\n";
return false;
}
life -= amount;
return true;
}
void Player::healLife(int amount) {
life += amount;
cout << "你的寿命增加了 " << amount << " 年,当前寿命:" << life << " 年。\n";
}
void Player::addExp(int amount) {
exp += amount;
cout << "获得了 " << amount << " 点经验,当前经验:" << exp << endl;
checkLevelUp();
}
void Player::checkLevelUp() {
while (exp >= stage.getRequiredExp()) {
exp -= stage.getRequiredExp();
stage.nextStage();
maxHealth += stage.transformation * 10;
health = maxHealth;
cout << "恭喜!你晋升到了:" << stage.toString() << endl;
cout << "最大生命值提升至 " << maxHealth << ",已回满血量。\n";
}
}
void Player::cultivate() {
if (!consumeLife(1)) return;
int gain = rand() % 5 + 5;
cout << "你闭关修炼了一段时间,获得了 " << gain << " 点经验。\n";
addExp(gain);
}
void Player::useItem(const string& itemName) {
if (itemName == "疗伤药") {
if (inventory[itemName] <= 0) {
cout << "没有足够的 " << itemName << " 可用。\n";
return;
}
health += 30;
if (health > maxHealth) health = maxHealth;
inventory[itemName]--;
cout << "你使用了 " << itemName << ",恢复了30点生命值。当前生命值:" << health << endl;
} else if (itemName == "大疗伤药") {
if (inventory[itemName] <= 0) {
cout << "没有足够的 " << itemName << " 可用。\n";
return;
}
health = maxHealth;
inventory[itemName]--;
cout << "你使用了 " << itemName << ",生命值已回满。\n";
} else {
cout << "未知的物品。\n";
}
}
void Player::exploreWild() {
int playerTrans = stage.transformation;
int chance = rand() % 100;
Gu* newGu = NULL;
if(chance==0||chance==40||chance==41||chance==42)newGu=new Gu("月光蛊", GU_O,10 ,1 );
else if(chance==1||chance==37||chance==38||chance==39)newGu=new Gu("铜皮蛊", GU_D,11 ,1 );
else if(chance==2||chance==43||chance==44||chance==45)newGu=new Gu("黑豕蛊", GU_D,11 ,1 );
else if(chance==3||chance==46||chance==47||chance==48)newGu=new Gu("小光蛊", GU_O,8 ,1 );//1
else if(chance==4||chance==49||chance==50)newGu=new Gu("水罩蛊", GU_G,10 ,2 );
else if(chance==5||chance==51||chance==52)newGu=new Gu("纸鹤蛊", GU_I,9 ,2 );
else if(chance==6||chance==53||chance==54)newGu=new Gu("骨枪蛊", GU_P,20 ,2 );
else if(chance==7||chance==55||chance==56)newGu=new Gu("月痕蛊", GU_O,19 ,2 );//2
else if(chance==8||chance==57)newGu=new Gu("胆识蛊", GU_B,20 ,3 );
else if(chance==9||chance==58)newGu=new Gu("力气蛊", GU_D,31 ,3 );
else if(chance==10||chance==59)newGu=new Gu("刀翅血蝠蛊", GU_L,31 ,3 );
else if(chance==11||chance==60)newGu=new Gu("鬼火蛊", GU_B,31 ,3 );//3
else if(chance==12||chance==61)newGu=new Gu("月影蛊", GU_O,50 ,4 );
else if(chance==13||chance==62)newGu=new Gu("苦力蛊", GU_D,51 ,4 );
else if(chance==14||chance==63)newGu=new Gu("换位蛊", GU_R,47 ,4 );
else if(chance==15||chance==64)newGu=new Gu("奋战蛊", GU_Y,50 ,4 );//4
else if(chance==16||chance==65)newGu=new Gu("千里地狼蛛", GU_C,80 ,5 );
else if(chance==17||chance==66)newGu=new Gu("人力胜天蛊", GU_V,81 ,5 );
else if(chance==18||chance==67)newGu=new Gu("奴隶蛊", GU_C,78 ,5 );
else if(chance==19||chance==68)newGu=new Gu("飞僵蛊", GU_J,81 ,5 );
else if(chance==20||chance==69)newGu=new Gu("罗刹金蛊", GU_Q,80 ,5 );//5
else if(chance==21)newGu=new Gu("妇人心", GU_F,200 ,6 );
else if(chance==22)newGu=new Gu("单刀蛊", GU_M,200 ,6 );
else if(chance==23)newGu=new Gu("雷梭仙蛊", GU_N,200 ,6 );
else if(chance==24)newGu=new Gu("铁壁蛊", GU_Q,180 ,6 );//6
else if(chance==25)newGu=new Gu("飞剑蛊", GU_A,400 ,7 );
else if(chance==26)newGu=new Gu("死期将至蛊", GU_S,400 ,7 );
else if(chance==27)newGu=new Gu("松针仙蛊", GU_T,400 ,7 );
else if(chance==28)newGu=new Gu("水乳交融蛊", GU_G,380 ,7 );//7
else if(chance==29)newGu=new Gu("杀蛊", GU_X,900 ,8 );
else if(chance==30)newGu=new Gu("血本蛊", GU_L,890 ,8 );
else if(chance==31)newGu=new Gu("铃音蛊", GU_W,870 ,8 );
else if(chance==32)newGu=new Gu("鸿运齐天蛊", GU_H,880 ,8 );//8
else if(chance==33)newGu=new Gu("宿命蛊", GU_E,2000 ,9 );
else if(chance==34)newGu=new Gu("浴火蛊", GU_U,2000 ,9 );
else if(chance==35)newGu=new Gu("智慧蛊", GU_Y,2000 ,9 );
else if(chance==36)newGu=new Gu("爱情蛊", GU_Y,2000 ,9 );//9
else if(chance==70)newGu=new Gu("寿蛊", GU_LIFE_BOOST,5 ,1 );
else if(chance==71)newGu=new Gu("治疗蛊",GU_HEAL,10 ,1 );
else if(chance==72)newGu=new Gu("寿蛊",GU_LIFE_BOOST,10 ,2 );
else if(chance==73)newGu=new Gu("治疗蛊",GU_HEAL,20 ,2 );
else if(chance==74)newGu=new Gu("寿蛊",GU_LIFE_BOOST,15 ,3 );
else if(chance==75)newGu=new Gu("治疗蛊",GU_HEAL,30 ,3 );
else if(chance==76)newGu=new Gu("寿蛊",GU_LIFE_BOOST,25 ,4 );
else if(chance==77)newGu=new Gu("治疗蛊",GU_HEAL,50 ,4 );
else if(chance==78)newGu=new Gu("寿蛊",GU_LIFE_BOOST,50 ,5 );
else if(chance==79)newGu=new Gu("治疗蛊",GU_HEAL,75 ,5 );
if (!newGu) {
cout << "你在野外一无所获。\n";
return;
}
if (rand() % 100 >50) {
cout << "突然出现一名敌对蛊师试图抢夺你的蛊虫!\n";
int Power1=newGu->power ;
int playerTrans = stage.transformation;
int chance = rand() % 100;
Gu* newGu = NULL;
if(chance==0||chance==40||chance==41||chance==42)newGu=new Gu("月光蛊", GU_O,10 ,1 );
else if(chance==1||chance==37||chance==38||chance==39)newGu=new Gu("铜皮蛊", GU_D,11 ,1 );
else if(chance==2||chance==43||chance==44||chance==45)newGu=new Gu("黑豕蛊", GU_D,11 ,1 );
else if(chance==3||chance==46||chance==47||chance==48)newGu=new Gu("小光蛊", GU_O,8 ,1 );//1
else if(chance==4||chance==49||chance==50)newGu=new Gu("水罩蛊", GU_G,10 ,2 );
else if(chance==5||chance==51||chance==52)newGu=new Gu("纸鹤蛊", GU_I,9 ,2 );
else if(chance==6||chance==53||chance==54)newGu=new Gu("骨枪蛊", GU_P,20 ,2 );
else if(chance==7||chance==55||chance==56)newGu=new Gu("月痕蛊", GU_O,19 ,2 );//2
else if(chance==8||chance==57)newGu=new Gu("胆识蛊", GU_B,20 ,3 );
else if(chance==9||chance==58)newGu=new Gu("力气蛊", GU_D,31 ,3 );
else if(chance==10||chance==59)newGu=new Gu("刀翅血蝠蛊", GU_L,31 ,3 );
else if(chance==11||chance==60)newGu=new Gu("鬼火蛊", GU_B,31 ,3 );//3
else if(chance==12||chance==61)newGu=new Gu("月影蛊", GU_O,50 ,4 );
else if(chance==13||chance==62)newGu=new Gu("苦力蛊", GU_D,51 ,4 );
else if(chance==14||chance==63)newGu=new Gu("换位蛊", GU_R,47 ,4 );
else if(chance==15||chance==64)newGu=new Gu("奋战蛊", GU_Y,50 ,4 );//4
else if(chance==16||chance==65)newGu=new Gu("千里地狼蛛", GU_C,80 ,5 );
else if(chance==17||chance==66)newGu=new Gu("人力胜天蛊", GU_V,81 ,5 );
else if(chance==18||chance==67)newGu=new Gu("奴隶蛊", GU_C,78 ,5 );
else if(chance==19||chance==68)newGu=new Gu("飞僵蛊", GU_J,81 ,5 );
else if(chance==20||chance==69)newGu=new Gu("罗刹金蛊", GU_Q,80 ,5 );//5
else if(chance==21)newGu=new Gu("妇人心", GU_F,200 ,6 );
else if(chance==22)newGu=new Gu("单刀蛊", GU_M,200 ,6 );
else if(chance==23)newGu=new Gu("雷梭仙蛊", GU_N,200 ,6 );
else if(chance==24)newGu=new Gu("铁壁蛊", GU_Q,180 ,6 );//6
else if(chance==25)newGu=new Gu("飞剑蛊", GU_A,400 ,7 );
else if(chance==26)newGu=new Gu("死期将至蛊", GU_S,400 ,7 );
else if(chance==27)newGu=new Gu("松针仙蛊", GU_T,400 ,7 );
else if(chance==28)newGu=new Gu("水乳交融蛊", GU_G,380 ,7 );//7
else if(chance==29)newGu=new Gu("杀蛊", GU_X,900 ,8 );
else if(chance==30)newGu=new Gu("血本蛊", GU_L,890 ,8 );
else if(chance==31)newGu=new Gu("铃音蛊", GU_W,870 ,8 );
else if(chance==32)newGu=new Gu("鸿运齐天蛊", GU_H,880 ,8 );//8
else if(chance==33)newGu=new Gu("宿命蛊", GU_E,2000 ,9 );
else if(chance==34)newGu=new Gu("浴火蛊", GU_U,2000 ,9 );
else if(chance==35)newGu=new Gu("智慧蛊", GU_Y,2000 ,9 );
else if(chance==36)newGu=new Gu("爱情蛊", GU_Y,2000 ,9 );//9
else if(chance==70)newGu=new Gu("寿蛊", GU_LIFE_BOOST,5 ,1 );
else if(chance==71)newGu=new Gu("治疗蛊",GU_HEAL,10 ,1 );
else if(chance==72)newGu=new Gu("寿蛊",GU_LIFE_BOOST,10 ,2 );
else if(chance==73)newGu=new Gu("治疗蛊",GU_HEAL,20 ,2 );
else if(chance==74)newGu=new Gu("寿蛊",GU_LIFE_BOOST,15 ,3 );
else if(chance==75)newGu=new Gu("治疗蛊",GU_HEAL,30 ,3 );
else if(chance==76)newGu=new Gu("寿蛊",GU_LIFE_BOOST,25 ,4 );
else if(chance==77)newGu=new Gu("治疗蛊",GU_HEAL,50 ,4 );
else if(chance==78)newGu=new Gu("寿蛊",GU_LIFE_BOOST,50 ,5 );
else if(chance==79)newGu=new Gu("治疗蛊",GU_HEAL,75 ,5 );
int enemyPower = newGu->power ;
cout << "战斗开始!\n";
if (newGu->power > enemyPower) {
cout << "你成功击败了敌对蛊师!\n";
if (rand() % 100 < 50) {
cout << "你从敌对蛊师身上获得了他的蛊虫!\n";
newGu->name = "敌对" + newGu->name;
newGu->power *= 1.5;
}
} else {
cout << "你被打败了,失去了这个蛊虫!\n";
delete newGu;
return;
}
}
unrefinedGuBag.push_back(*newGu);
cout << "你在野外发现了 " << newGu->name << "(" << newGu->transformation << "转)已放入背包,尚未炼化。\n";
exp+=10;
delete newGu;
}
void Player::refineGu() {
if (unrefinedGuBag.empty()) {
cout << "你没有未炼化的蛊虫。\n";
return;
}
cout << "请选择要炼化的蛊虫编号:\n";
int i;
for (i = 0; i < (int)unrefinedGuBag.size(); ++i) {
Gu g = unrefinedGuBag[i];
cout << i << ". [" << g.transformation << "转] " << g.name << "(" << g.getTypeName() << ")\n";
}
int choice;
cin >> choice;
if (choice < 0 || choice >= (int)unrefinedGuBag.size()) {
cout << "无效选择。\n";
return;
}
Gu selected = unrefinedGuBag[choice];
if (selected.transformation > stage.transformation) {
cout << "该蛊虫境界过高,无法炼化。\n";
return;
}
if (rand() % 100 < 30) {
cout << "炼化失败," << selected.name << " 死亡了。\n";
unrefinedGuBag.erase(unrefinedGuBag.begin() + choice);
return;
}
cout << "炼化成功!" << selected.name << " 已加入你的蛊虫列表。\n";
selected.applyEffect(*this);
guList.push_back(selected);
unrefinedGuBag.erase(unrefinedGuBag.begin() + choice);
}
void Player::battle() {
int enemyPower;
int gushi=rand()%9;
switch (gushi){
case 0:{
enemyPower=rand()%13;
break;
}
case 1:{
enemyPower=rand()%23;
break;
}
case 2:{
enemyPower=rand()%33;
break;
}
case 3:{
enemyPower=rand()%53;
break;
}
case 4:{
enemyPower=rand()%83;
break;
}
case 5:{
enemyPower=rand()%203;
break;
}
case 6:{
enemyPower=rand()%403;
break;
}
case 7:{
enemyPower=rand()%903;
break;
}
case 8:{
enemyPower=rand()%2003;
break;
}
} cout << "敌人出现,战斗力为 " << enemyPower << "!\n";
if (guList.empty()) {
cout << "你没有蛊虫可用,只能硬拼……\n";
int playerPower = 10;
if (playerPower >= enemyPower) {
cout << "你勉强获胜,但受伤严重!\n";
health -= 20;
} else {
cout << "你被击败了!\n";
health -= 40;
}
} else {
cout << "请输入要出战的蛊虫编号(例如:1 2 3):\n";
for (unsigned int i = 0; i < guList.size(); ++i) {
cout << i + 1 << ". " << guList[i].name << " (战斗力: " << guList[i].power << ")\n";
}
string input;
cin.ignore(); // 清除缓冲区
getline(cin, input);
stringstream ss(input);
vector<int> choices;
int num;
while (ss >> num) {
choices.push_back(num - 1);
}
int totalPower = 0;
for (unsigned int i = 0; i < choices.size(); ++i) {
int choice = choices[i];
if (choice >= 0 && choice < (int)guList.size()) {
totalPower += guList[choice].power;
}
}
if (totalPower >= enemyPower) {
cout << "你们合力战胜了敌人!总战斗力: " << totalPower << endl;
} else {
cout << "你们合力仍不敌敌人,受了重伤。总战斗力: " << totalPower << endl;
health -= 30;
}
if (health <= 0) {
cout << "你已死亡,游戏结束。\n";
exit(0);
}
}
}
// ================== 主程序 ==================
int main() {
HideCursor();system("title 蛊真人");
for(int i=1;i<=8;i++) cout<<endl;
Sleep(2000);cout<<" 落魄谷中寒风吹,春秋蝉鸣少年归。"<<endl;
Sleep(2000);cout<<" 荡魂山处石人泪,定仙游走魔向北。"<<endl;
Sleep(2000);cout<<" 逆流河上万千退,爱情不敌坚持泪。"<<endl;
Sleep(2000);cout<<" 宿命天成命中败,仙尊悔而我不悔。"<<endl;
Sleep(3000);
Player player;
while (true) {
system("cls");
player.showStatus();
cout << "\n选项: \n"
<< "1. 探索野外\n"
<< "2. 炼化蛊虫\n"
<< "3. 修炼\n"
<< "4. 使用疗伤药\n"
<< "5. 战斗\n"
<< "6. 退出\n"
<< "请输入选项: ";
int choice;
cin >> choice;
cin.ignore();
switch (choice) {
case 1:{
player.exploreWild();system("pause");
break;}
case 2:{
player.refineGu();system("pause");
break;}
case 3:{
player.cultivate();system("pause");
break;}
case 4: {
string item;
cout << "输入要使用的物品名称(疗伤药/大疗伤药): ";
getline(cin, item);
player.useItem(item);system("pause");
break;}
case 5:{
player.battle() ;system("pause");
break;}
case 6:
return 0;
default:
cout << "无效选项。\n";
}
if (player.life <= 0) {
cout << "你的寿命已尽,游戏结束。\n";
return 0;
}
}
system("pause");
return 0;
}
给个赞吧,求求了!!!
更多推荐
所有评论(0)