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); }
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(); }