本文整理汇总了C++中PhysicalObject::getDescription方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicalObject::getDescription方法的具体用法?C++ PhysicalObject::getDescription怎么用?C++ PhysicalObject::getDescription使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicalObject
的用法示例。
在下文中一共展示了PhysicalObject::getDescription方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initCommands
void Player::initCommands() {
std::function<void (std::vector<std::string> commandWords, std::function<bool(const std::vector<std::string> &)>)> addCommands = [this](std::vector<std::string> commandWords, std::function<bool(const std::vector<std::string> &)> operation){
if(commandWords.size() < 1) {
throw std::invalid_argument("You must at least have one word associated with the command");
}
uniqueCommands.push_back(commandWords.front());
for(std::string word: commandWords){
if(commands.find(word) != commands.end()) {
throw std::invalid_argument("The word: " + word + " is associated with more than one command");
}
commands[word] = operation;
}
};
std::function<bool (const std::vector<std::string> & commands, const std::string & helpText, const std::string & usageCommands)> isHelp = [](const std::vector<std::string> & commands, const std::string & helpText, const std::string & usageCommands){
if(commands.size() != 2){ return false; };
if(commands[1] != "help"){ return false; };
std::cout << TEXT_DIVIDER << " HELP: " << commands[0] << " " << TEXT_DIVIDER << std::endl;
if(helpText != "") {
std::cout << helpText << std::endl;
}
std::cout << "Usage: " << commands[0] << " " << usageCommands << std::endl;
return true;
};
addCommands({"go", "move", "goto"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
if(isHelp(commands, "Used for navigating through the world.", "LOCATION")) { return false; }
if(commands.size() != 2) {
std::cout << "You forgot to write where you wanna go." << std::endl;
return false;
}
int num = -1;
try {
num = atoi(commands[1].c_str()) - 1;
} catch(int) {
std::cout << "That is not an option. Write one of the numbers given as option." << std::endl;
return false;
}
auto dirs = getEnvironment()->getDirections();
if(num >= dirs.size()) {
std::cout << "That is not an option. Write one of the numbers given as option." << std::endl;
return false;
}
if(!this->move(dirs[num])) {
std::cout << "That is not an option. Write one of the numbers given as option." << std::endl;
return false;
}
return true;
});
addCommands({"look"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
if(isHelp(commands, "Look for example at different characters or on items to get more information. You can look at almost anything in the world.", "[CONTAINER] [OBJECT]")) { return false;}
Environment * env = getEnvironment();
if(commands.size() == 1) {
printUpdateInfo();
} else if(commands.size() == 2) {
if(isCommandInventory(commands[1])) {
std::cout << getInventory()->getDescription() << std::endl;
return false;
}
if(isCommandEquipment(commands[1])) {
std::cout << getEquipment()->getDescription() << std::endl;
return false;
}
PhysicalObject * physicalObject = env->find(commands[1]);
if(physicalObject == NULL) {
std::cout << "Found no item named: " << commands[1] << std::endl;
} else {
std::cout << physicalObject->getDescription() << std::endl;
}
} else if(commands.size() == 3) {
Item * item = NULL;
if(isCommandInventory(commands[1])) {
Inventory * inv = getInventory();
item = inv->find(commands[2]);
if(item == NULL) {
std::cout << "Found no item named: " << commands[2] << " in your inventory." << std::endl;
return false;
}
} else if(isCommandEquipment(commands[1])) {
Equipment * eq = getEquipment();
item = eq->find(commands[2]);
if(item == NULL) {
std::cout << "Found no item named: " << commands[2] << " in your equipment." << std::endl;
return false;
}
} else {
Container * con = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[2]);
if(con == NULL) {
//.........这里部分代码省略.........