本文整理汇总了C++中Option::setNextState方法的典型用法代码示例。如果您正苦于以下问题:C++ Option::setNextState方法的具体用法?C++ Option::setNextState怎么用?C++ Option::setNextState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option::setNextState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addAnomalyState
void addAnomalyState(map<int, State*> & states){
State* state = states.at(8);
Option* option = new Option();
option->setChoice("Watch her to see what she will do");
option->setNextState(states.at(7));
state->addOption(option);
}
示例2: readInStory
void readInStory(map<int, State*> &statesMap){
ifstream myReadFile;
string storyLine;
smatch match;
regex numberPattern("(\\d+)");
regex statePattern("^STATE");
regex descPattern("^DESCRIPTION");
regex noOfOptionsPattern("^NO_OF_CHOICES");
regex stringPattern("\"([^\"]*)\"");
myReadFile.open("story.txt");
State* state;
Option* option;
int noOfChoices;
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
//retrieve the next line in the text file.
getline(myReadFile,storyLine);
//If the line is a state, then create a new state.
if(isMatch(storyLine, statePattern)){
int value = atoi(showMatch(storyLine, numberPattern, match).c_str());
state = new State();
statesMap[value] = state;
//Else if the line is a description, add it to the current state.
}else if(isMatch(storyLine, descPattern)){
string description = showMatch(storyLine, stringPattern, match);
state->setDescript(description);
}
//Else if the line gives the number of options for the state, then create that many choices.
else if(isMatch(storyLine, noOfOptionsPattern)){
noOfChoices = atoi(showMatch(storyLine, numberPattern, match).c_str());
for(int i = 0; i < noOfChoices; i++){
option = new Option();
//Each option has a choice, consequence, and nextStateNumber, so we read all 3 of these in for each option.
getline(myReadFile,storyLine);
string choice = showMatch(storyLine, stringPattern, match);
option->setChoice(choice);
getline(myReadFile,storyLine);
string consequence = showMatch(storyLine, stringPattern, match);
option->setConsequence(consequence);
getline(myReadFile,storyLine);
int nextStateNumber = atoi(showMatch(storyLine, numberPattern, match).c_str());
option->setNextState(statesMap.at(nextStateNumber));
state->addOption(option);
}
}
}
}
myReadFile.close();
}