#include #include #include #include int stringfind(const std::string original, std::string lookfor, int size); void area0(const std::string original, const int quitcondition); std::vector itemnames; std::vector itemstatus; std::vector areadescriptions; int main() { itemnames.push_back("mug of coffee"); itemnames.push_back("stapler"); itemstatus.push_back(0); itemstatus.push_back(0); areadescriptions.push_back("you are a software engineer. you are at work coding a database for a new upstart company when your boss comes in to tell you that you are fired."); int currentarea = 0; int wincondition = 0; int quitcondition = 0; std::string temp; std::cout << "Dunderware presents - Bad Day at the Office\n" << std::endl; std::cout << "Instructions:\nUse the following commands - look, take, open, throw to interact with the environment. Use quit to quit and inventory to view your inventory." << std::endl; std::cout << "\nWould you like to load the saved game? (y or n)"; std::getline(std::cin,temp); if( stringfind(temp,"y",temp.size()) ) { //load variables from saved file } else { //load standard variables currentarea = 0; } //the game loop - begins with initial area description, then prompts for input, followed by an output, then repeats the i/o procedure until game end //condition is met or quit condition is met std::cout << std::endl << areadescriptions[currentarea] << std::endl; while(!quitcondition) { std::getline(std::cin,temp); if(stringfind(temp,"quit",temp.size())) quitcondition = 1; if(currentarea==0) area0(temp,quitcondition); } if(wincondition) { //results of winning the game } return 0; } void area0(const std::string original, const int quitcondition) { if(!quitcondition) { if(stringfind(original,"look",original.size()) && stringfind(original,"desk",original.size()) ){ std::cout<< "\nYour desk has a mug of cold drip coffee on it and a stapler.\n"; } else if(stringfind(original,"look",original.size()) && ( stringfind(original,"mug",original.size()) || stringfind(original,"coffee",original.size()) ) ){ std::cout<< "\nThe coffee is dark and looks unappetizing. It is excellent at staining shirts and leaving rings on papers.\n"; } else if(stringfind(original,"look",original.size()) && stringfind(original,"stapler",original.size()) ){ std::cout<< "\nThe stapler is a red swingline. Staples can cause serious puncture wounds.\n"; } else if(stringfind(original,"look",original.size()) ){ std::cout<< "\nYou are in front of your desk, which has several items of interest on it. Your boss is standing in front of the desk, leering at you in his brand new armani suit.\n"; } else if(stringfind(original,"throw",original.size()) && ( stringfind(original,"coffee",original.size()) || stringfind(original,"mug",original.size()) )){ if(itemstatus[0]==1){ std::cout<< "\nYour boss watches in horror as the contents of the mug empties onto his freshly pressed dress shirt and expensive silk tie. He curses and says \"what the hell is wrong with you? GET OUT NOW!\"\n"; itemstatus[0]=3; } else std::cout << "\nYou don't have the mug of coffee.\n"; } else if(stringfind(original,"take",original.size()) && stringfind(original,"stapler",original.size()) ){ if(itemstatus[1]==0){ std::cout<< "\nYou grab the stapler.\n"; itemstatus[1]=1; } else std::cout<< "\nYou already have the stapler\n"; } else if(stringfind(original,"take",original.size()) && ( stringfind(original,"mug",original.size()) || stringfind(original,"coffee",original.size()) )){ if(itemstatus[0]==0){ std::cout<< "\nYou grab the mug of coffee.\n"; itemstatus[0]=1; } else if(itemstatus[0]==1) std::cout<< "\nYou already have the mug of coffee.\n"; } else if(stringfind(original,"inventory",original.size()) ){ std::cout<< "\nYou are currently holding:\n"; for(unsigned int i=0; i=lookfor.size()) { ind = 1; } } } return ind; }