-1
我想只能打電話給一個地區並有權選擇TAvark(鎮Avark)和森林,因此我可以一邊查看用戶在cin中輸入正確的文本並仍然允許它回到前一點,例如從森林回到城鎮,但是因爲目前你不能這樣做。如何組織班級,這樣我可以打電話給一個班級同時使用這兩個對象
namespace areas {
class TAvark {
public:
string Avark;
int Blacksmith;
int Merchant;
int Magic;
int NPC_quest;
};
class Forest{
public:
string RForest;
string Search;
string Return;
int heal;
using namespace areas;
TAvark TAvarkregion;
Forest Forestregion;
TAvarkregion.Avark;
Forestregion.RForest;
}
}
while (TAvarkregion.Avark != "Town" & TAvarkregion.Avark != "town" & Forestregion.RForest != "Forest" & Forestregion.RForest != "forest")
if (Charactergender.gender == "Male" & Charactergender.gender == "male")
cout << "Where would you like to go Sir " << Charactername.name << endl << endl;
else cout << "Where would you like to go Madam" << Charactername.name << endl << endl;
cout << "the Forest or the Town";
cin <<
Sleep(2000);
};
這裏是我的所有代碼,如果需要
#include <iostream>
#include <string>
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
using namespace std;
class mainhand {
int serratedblade;
int steelsword;
int cutless;
int falchion;
int staff;
int iron_dagger;
int enchanted_oak_staff;
int wand;
int enchanted_steel_dagger
};
class offhand {
int wooden_shield;
int off_wand;
int off_steel_dagger;
int off_iron_dagger;
int tower_shield;
};
class chest {
int leather_chest;
int iron_chest;
int robes;
int tunic;
int plated_mail;
int woven_mantle;
};
class helmet {
int horned_helmet;
int wizard_hat;
int iron_helmet;
int full_helm;
int hood;
};
namespace areas {
class TAvark {
public:
string Avark;
int Blacksmith;
int Merchant;
int Magic;
int NPC_quest;
};
class Forest{
public:
string RForest;
string Search;
string Return;
int heal;
class Goblin {
int health = rand() % 50 + 20;
int damage = rand() % 15 + 8;
int armor = rand() % 6 + 4;
int goldR = rand() % 30 + 5;
int experience = rand() % 60 + 40;
string serratedblade;
};
class spider {
int health = rand() % 50 + 20;
int damage = rand() % 15 + 8;
int armor = rand() % 6 + 4;
int goldR = rand() % 30 + 5;
int experience = rand() % 60 + 40;
};
class Haunted_Deer {
int health = rand() % 50 + 20;
int damage = rand() % 15 + 8;
int armor = rand() % 6 + 4;
int goldR = rand() % 30 + 5;
int experience = rand() % 60 + 40;
};
class Witch {
int health = rand() % 50 + 20;
int damage = rand() % 15 + 8;
int armor = rand() % 6 + 4;
int goldR = rand() % 30 + 5;
int experience = rand() % 60 + 40;
};
class ghost {
int health = rand() % 50 + 20;
int damage = rand() % 15 + 8;
int armor = rand() % 6 + 4;
int goldR = rand() % 30 + 5;
int experience = rand() % 60 + 40;
};
class bear {
int health = rand() % 50 + 20;
int damage = rand() % 15 + 8;
int armor = rand() % 6 + 4;
int goldR = rand() % 30 + 5;
int experience = rand() % 60 + 40;
};
class boss {
int health = rand() % 50 + 20;
int damage = rand() % 15 + 8;
int armor = rand() % 6 + 4;
int goldR = rand() % 30 + 5;
int experience = rand() % 60 + 40;
};
};
};
class Character {
public:
string name;
string gender;
string type;
string faction;
int strength;
int agility;
int intelligence;
int level;
int health;
int experience;
int mainweapon;
int offhand;
int chest;
int helmet;
int gold;
};
int main()
{
Character Charactername;
Character Charactergender;
Character Charactertype;
Character Characteragility;
Character Characterstrength;
Character Characterintelligence;
Character Characterfaction;
string done;
while (done != "Y" & done != "y") {
cout << "what is your name?\n";
cin >> Charactername.name;
while (Charactergender.gender != "Male" & Charactergender.gender != "Female" & Charactergender.gender != "male" & Charactergender.gender != "female") {
cout << "Male or Female\n";
cin >> Charactergender.gender;
if (Charactergender.gender != "Male" & Charactergender.gender != "Female" & Charactergender.gender != "male" & Charactergender.gender != "female")
cout << "you have entered an invalid option\n";
}
while (Charactertype.type != "Warrior" & Charactertype.type != "warrior" & Charactertype.type != "Mage" & Charactertype.type != "mage" & Charactertype.type != "Rogue" & Charactertype.type != "rogue") {
cout << "What class are you, Warrior, Mage or Rogue\n";
cin >> Charactertype.type;
if (Charactertype.type == "Warrior" || Charactertype.type == "warrior")
Characteragility.agility = 6, Characterstrength.strength = 10, Characterintelligence.intelligence = 4;
else if (Charactertype.type == "Mage" || Charactertype.type == "mage")
Characteragility.agility = 4, Characterstrength.strength = 6, Characterintelligence.intelligence = 10;
else if (Charactertype.type == "Rogue" || Charactertype.type == "rogue")
Characteragility.agility = 10, Characterstrength.strength = 4, Characterintelligence.intelligence = 6;
else {
cout << "you have entered an invalid name\n";
}
}
while (Characterfaction.faction != "Good" & Characterfaction.faction != "good" & Characterfaction.faction != "Bad" & Characterfaction.faction != "bad" & Characterfaction.faction != "Neutral" & Characterfaction.faction != "neutral") {
cout << "what faction are you in\n" << "Good\n" << "Bad\n" << "Neutral\n";
cin >> Characterfaction.faction;
}
cout << "your name is " << Charactername.name << endl << " your gender is " << Charactergender.gender << endl << " your class is " << Charactertype.type << endl << " and your faction is " << Characterfaction.faction << endl << " are you sure you want to continue with these choices" << endl << "press Y to continue or any key to go back to the start ";
cin >> done;
}
cout << "Welcome to the Elysium " << Charactername.name << endl;
Sleep(5000);
Character Characterhealth;
Characterhealth.health = 100;
Character Charactergold;
Charactergold.gold = 0;
Character Characterlevel;
Characterlevel.level = 1;
Character Characterexperience;
Characterexperience.experience = 0;
using namespace areas;
TAvark TAvarkregion;
Forest Forestregion;
TAvarkregion.Avark;
Forestregion.RForest;
while (TAvarkregion.Avark != "Town" & TAvarkregion.Avark != "town" & Forestregion.RForest != "Forest" & Forestregion.RForest != "forest")
if (Charactergender.gender == "Male" & Charactergender.gender == "male")
cout << "Where would you like to go Sir " << Charactername.name << endl << endl;
else cout << "Where would you like to go Madam" << Charactername.name << endl << endl;
cout << "the Forest or the Town";
cin <<
Sleep(2000);
};
我錯過了一些東西...... –
它看起來像你正在尋找的是一種工廠方法。雖然問題不是很清楚 –
對不起,不知道如何說出來 – gurkin