我已经建立了一个基本的战斗系统,我希望在故事的不同阶段可以访问
int GameStart()
{
std::unique_ptr<blankCharacter> myCharacter;
std::unique_ptr<blankEnemy> myEnemy;
std::unique_ptr<Inventory> myInventory;
std::unique_ptr<blankEnemy> myBoss;
string name;
int choice;
int Battle;
cout << " Please enter player name." << endl << endl;
cin >> name;
system("cls");
cout << "______________________________________________________________________________" << endl;
cout << "______________________________________________________________________________" << endl;
cout << "Please select fighting class." << endl << endl;
cout <<" 1 - Mage, although not the physically strongest, mages offer a healing role" << endl;
cout <<" 2 - Warrior, the most balanced of all the classes, excelling in durability." << endl;
cout <<" 3 - Rogue, for players who want to take a more creative approach to battle." << endl;
cout << "______________________________________________________________________________" << endl;
cout << "______________________________________________________________________________" << endl;
cin >> choice;
switch(choice)
{
case 1: //Mage
myCharacter = std::unique_ptr<blankCharacter>(new Mage(20,40,60,70,100,180,60));
myInventory = std::unique_ptr<Inventory>(new Inventory(3, 3,3));
myEnemy = std::unique_ptr<blankEnemy>(new Enemy(150, 60, 150));
break;
case 2: //Warrior
myCharacter = std::unique_ptr<blankCharacter>(new Warrior(40,50,65,100,160,100,60));
myInventory = std::unique_ptr<Inventory>(new Inventory(3, 3, 3));
myEnemy = std::unique_ptr<blankEnemy>(new Enemy(150, 60, 150));
myBoss = std::unique_ptr<blankEnemy>(new Enemy(200, 200, 200));
break;
case 3: //Rogue
myCharacter = std::unique_ptr<blankCharacter>(new Rogue(30,55,70,90,160,100,100));
myInventory = std::unique_ptr<Inventory>(new Inventory(3, 3, 3));
myEnemy = std::unique_ptr<blankEnemy>(new Enemy(150,60,150));
break;
default:
cout << "Please select a relevant value 1 to 3" << endl << endl;
break;
}
在故事的开头部分之后,您可以沿着备用路径前进,但是我似乎无法将信息传递到它们的路径上,尽管我尝试传递它们。
int SecondPhase(blankCharacter, blankEnemy, string name, Inventory, int Battle, unique_ptr<blankCharacter> myCharacter, unique_ptr<blankEnemy> myEnemy, unique_ptr<Inventory> myInventory,unique_ptr<blankEnemy> myBoss)
有谁知道如何解决这个问题?
答案 0 :(得分:0)
std::unique_ptr
不是可复制构造的,因此您无法通过值将其传递给任何函数。尝试通过引用传递它:
int SecondPhase(std::unique_ptr<blankCharacter>& myCharacter)
有关更详细的答案,请参阅此处:How do I pass a unique_ptr argument to a constructor or a function?
但是我真的不明白你的代码。例如,Enemy
似乎是从blankEnemy
继承的,而名称表明blankEnemy
是Enemy
的特例,因此继承应该是相反的(如果有的话,因为空白的声音没有被初始化。)
您不一致的命名风格也无济于事。为什么有些类型以大写字母开头,有些以小写字母开头?