RPG角色生成器

这是一个创建RPG角色的程序,玩家可以输入ID选择性别,然后从多个种族和职业中进行选择。角色的属性,如力量、敏捷、体力、智力和智慧,会根据所选职业随机生成,并将角色信息保存到文档中。
摘要由CSDN通过智能技术生成

#include “iostream”
#include
#include “string”
#include “ctime”
#include “fstream”
using namespace std;

int occupation_choice; //玩家所选择的职业的序号

class Bwj //基础类,保存角色的姓名,性别
{
public:
void getBwj(); //功能实现
friend class Output; //友元类,用于输出角色信息
friend class File; //友元类,将角色信息保存到文档中
protected:
char name[10]; //记录角色名字
string sex; //记录性别
int sex_choice; //记录性别选择
};

void Bwj::getBwj() //输入角色名和性别
{
int i;
cout << “输入您的游戏ID:”;
cin >> name;
while(i)
{
cout << “选择游戏角色性别:”;
cout << “1.男 2.女” << endl;
cin >> sex_choice;
switch (sex_choice)
{

		case 1:
			sex = "男"; 
			i=0;
			break;
		case 2:
			sex = "女"; 
			i=0;
			break;
		default:
			cout<<"输入错误,请重新输入"<<endl;
			break;
	}
}

}

class Race :public Bwj //派生类,记录角色的种族、职业
{
public:
void getRace();
friend class Output; //友元类,用于输出角色信息
friend class File; //友元类,将角色信息保存到文档中
protected:
string race; //记录职业
string occupation; //记录种族
int race_choice;
};

void Race::getRace() //选择种族和职业
{
int i = 1;
while (i)
{
cout << “请选择阵营:” << endl;
cout << “1.求生者 2.监管者 3.随从 4.解说 5.观战” << endl;
cin >> race_choice;
switch (race_choice)
{
case 1:race = “求生者”;
i = 0;
break;
case 2:race = “监管者”;
i = 0;
break;
case 3:race = “随从”;
i = 0;
break;
case 4:race = “解说”;
i = 0;
break;
case 5:race = “观战”;
i = 0;
break;
default:cout << “输入错误,请重新输入!” << endl;
break;
}
}
while (1)
{
cout << “可以选择的角色:” << endl;
switch (race_choice)
{
case 1: cout << “1.幸运儿 2.园丁 3.慈善家 4.律师 5.祭司 6.医生” << endl; break;
case 2: cout << “7.厂长 8.小丑 9.鹿头 10.红蝶” << endl; break;
case 3: cout << "11.蜘蛛 12.黑白无常 13.摄影师 " << endl; break;
case 4: cout << "14.杰克 15.魔术师 16.佣兵 " << endl; break;
case 5: cout << “17.空军 18.机械师” << endl; break;
}
cin >> occupation_choice; //输入选择角色序号
if (race_choice == 1 && (occupation_choice >= 1 && occupation_choice <= 6))
break;
else
if (race_choice == 2 && (occupation_choice >= 7 && occupation_choice <= 10))
break;
else
if (race_choice == 3 && (occupation_choice >= 11 && occupation_choice <= 13))
break;
else
if (race_choice == 4 && (occupation_choice >= 14 && occupation_choice <= 16))
break;
else
if (race_choice == 5 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 6 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 7 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 8 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 9 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 10 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 11 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 12 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 13 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 14 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 15 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 16 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 17 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
if (race_choice == 18 && (occupation_choice >=17 && occupation_choice <=18))
break;
else
cout << “输入错误,请重新输入” << endl;
}
if (occupation_choice == 1) occupation = “幸运儿”;
if (occupation_choice == 2) occupation = “园丁”;
if (occupation_choice == 3) occupation = “慈善家”;
if (occupation_choice == 4) occupation = “律师”;
if (occupation_choice == 5) occupation = “祭司”;
if (occupation_choice == 6) occupation = “医生”;
if (occupation_choice == 7) occupation = “厂长”;
if (occupation_choice == 8) occupation = “小丑”;
if (occupation_choice == 9) occupation = “鹿头”;
if (occupation_choice == 10) occupation = “红蝶”;
if (occupation_choice == 11) occupation = “蜘蛛”;
if (occupation_choice == 12) occupation = “黑白无常”;
if (occupation_choice == 13) occupation = “摄影师”;
if (occupation_choice == 14) occupation = “杰克”;
if (occupation_choice == 15) occupation = “魔术师”;
if (occupation_choice == 16) occupation = “佣兵”;
if (occupation_choice == 17) occupation = “空军”;
if (occupation_choice == 18) occupation = “机械师”;
}

class Attribute :public Race //派生类,记录角色的属性
{
protected:
int strength; //力量
int agility; //敏捷
int physical; //体力
int intelligence; //智力
int wisdom; //智慧
int HP; //血量
int MP; //法力值
public:
void getAttribute();
void getRandom(int a, int b, int c, int d, int e);
friend class Output;
friend class File;
};

void Attribute::getRandom(int a, int b, int c, int d, int e) // 随机生成每项属性的值,abcd为该属性的最小值,e为第五个属性的最大值
{
int sum; //前4项属性之和
srand((unsigned)time(NULL));//设置定时器
do
{
strength = a + rand() % 3;
agility = b + rand() % 3;
physical = c + rand() % 3;
intelligence = d + rand() % 3;
sum = strength + agility + physical + intelligence;
}
while (((100 - e) < sum) && (sum < 100));
wisdom = 100 - sum;
HP = physical * 20;
MP = (wisdom + intelligence) * 10;
}

void Attribute::getAttribute() //根据选择的职业,向getRamdom传各职业最小值
{
if (occupation_choice == 1)
getRandom(40, 20, 30, 5, 5);
if (occupation_choice == 2)
getRandom(25, 15, 30, 20, 10);
if (occupation_choice == 3)
getRandom(20, 35, 20, 15, 10);
if (occupation_choice == 4)
getRandom(15, 40, 15, 10, 20);
if (occupation_choice == 5)
getRandom(15, 20, 15, 35, 15);
if (occupation_choice == 6)
getRandom(10, 20, 10, 20, 40);
if (occupation_choice == 7)
getRandom(40, 20, 30, 5, 5);
if (occupation_choice == 8)
getRandom(25, 15, 30, 20, 10);
if (occupation_choice == 9)
getRandom(20, 35, 20, 15, 10);
if (occupation_choice == 10)
getRandom(15, 40, 15, 10, 20);
if (occupation_choice == 11)
getRandom(15, 20, 15, 35, 15);
if (occupation_choice == 12)
getRandom(10, 20, 10, 20, 40);
if (occupation_choice == 13)
getRandom(40, 20, 30, 5, 5);
if (occupation_choice == 14)
getRandom(25, 15, 30, 20, 10);
if (occupation_choice == 15)
getRandom(20, 35, 20, 15, 10);
if (occupation_choice == 16)
getRandom(15, 40, 15, 10, 20);
if (occupation_choice == 17)
getRandom(15, 20, 15, 35, 15);
if (occupation_choice == 18)
getRandom(10, 20, 10, 20, 40);
}

class Output //输出角色属性
{
public:
void show(Bwj &, Race &, Attribute &);//访问友元类
};

void Output::show(Bwj &t1, Race &t2, Attribute &t3)
{
cout << “" << endl;
cout <<setw(14)<< “姓名:” << t1.name << endl;
cout << "
” << endl;
cout <<setw(14)<< “性别:” << t1.sex << endl;
cout << “" << endl;
cout <<setw(14)<< “种族:” << t2.race << endl;
cout << "
” << endl;
cout <<setw(14)<< “职业:” << t2.occupation << endl;
cout << “" << endl;
cout <<setw(14)<< “力量:” << t3.strength << endl;
cout << "
” << endl;
cout <<setw(14)<< “敏捷:” << t3.agility << endl;
cout << “" << endl;
cout <<setw(14)<< “体力:” << t3.physical << endl;
cout << "
” << endl;
cout <<setw(14)<< “智力:” << t3.intelligence << endl;
cout << “" << endl;
cout <<setw(14)<< “智慧:” << t3.wisdom << endl;
cout << "
” << endl;
cout <<setw(14)<< “生命值:” << t3.HP << endl;
cout << “" << endl;
cout <<setw(14)<< “法力值:” << t3.MP << endl;
cout << "
” << endl;
}

class File //将角色信息保存到文档
{
public:
void file(Bwj &, Race &, Attribute &);
};

void File::file(Bwj &t1, Race &t2, Attribute &t3)
{
ofstream outfile;
outfile.open(“角色数据保存”, ios::trunc);
cout << “" << endl;
outfile <<setw(14)<< “姓名:” << t1.name << endl;
cout << "
” << endl;
outfile <<setw(14)<< “性别:” << t1.sex << endl;
cout << “" << endl;
outfile <<setw(14)<< “种族:” << t2.race << endl;
cout << "
” << endl;
outfile <<setw(14)<< “职业:” << t2.occupation << endl;
cout << “" << endl;
outfile <<setw(14)<< “力量:” << t3.strength << endl;
cout << "
” << endl;
outfile <<setw(14)<< “敏捷:” << t3.agility << endl;
cout << “" << endl;
outfile <<setw(14)<< “体力:” << t3.physical << endl;
cout << "
” << endl;
outfile <<setw(14)<< “智力:” << t3.intelligence << endl;
cout << “" << endl;
outfile <<setw(14)<< “智慧:” << t3.wisdom << endl;
cout << "
” << endl;
outfile <<setw(14)<< “生命值:” << t3.HP << endl;
cout << “" << endl;
outfile <<setw(14)<< "法力值: " << t3.MP << endl;
cout << "
” << endl;
}

int main()
{
Bwj player;
Race player_race;
Attribute player_att;
Output player_show;
File keep;
int player_choice;
do
{
player.getBwj();
player_race.getRace();
player_att.getAttribute();
player_show.show(player, player_race, player_att);
cout << endl;
cout << “是否重置角色?如不满意,则重新生成” << endl;
cout << “0.否 1.是” << endl;
cin >> player_choice;
} while (player_choice);
keep.file(player, player_race, player_att);
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值