Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ADVENTURE CODE CSCI40
#include <iostream> #include <string> #include <vector> #include <cctype> #include <algorithm> using namespace std; // names instead of numbers are established to make coding easier to understand enum en_DIRS {NORTH, SOUTH, EAST, WEST, UP, DOWN}; enum en_ROOMS {ISLAND, BOW, GROVE, TOP_DECK, BOTTOM_DECK, GALLEY, BRIG, CAPTAIN_QUARTERS, CARGO, CAVE, SHORE}; enum en_VERBS {GET, LOOK, GIVE, EAT, CUT, CLIMB, USE, OPEN, UNLOCK, SAIL, GO, TALK, READ, YELL, FISH}; // Added code enum en_NOUNS {DOOR, GORILLA, NATIVE, KNIFE, BANANA, TREASURE, CELL, TRUNK, PARROT, SHIP, WHEEL, KEYS, ROOM, LADDER, TREE, TRAPDOOR, BOOK, BACKPACK, PRISONER, MAN, FISHING_ROD}; // .... // constants for number of enums established to make for loops work, they must be accurate const int NONE = -1; const int DIRS = 6; const int ROOMS = 11; const int VERBS = 15; // Added code const int NOUNS = 21; // .... struct word { string word; int code; string synonym; string synonym2; }; struct room { string description; string longDescription; int exits_to_room[DIRS]; bool first_time; }; // Added code struct noun { string word; string description; int code; int location; bool can_carry; bool inventory; bool blocking; bool free; int num_of; }; // .... // ------------------------------------------------------------------------------------------------- void set_rooms(room *rms) // sets the room { rms[ISLAND].description.assign("island"); rms[ISLAND].longDescription.assign("The island is forested with banana trees. Most of the bananas are green, but one tree to your west might have ripe bananas. There are ominous drums in the background. There is a ship to your east with a gangplank to the shore."); rms[ISLAND].exits_to_room[NORTH] = GROVE; rms[ISLAND].exits_to_room[EAST] = TOP_DECK; rms[ISLAND].exits_to_room[SOUTH] = NONE; rms[ISLAND].exits_to_room[WEST] = SHORE; rms[ISLAND].exits_to_room[UP]= NONE; rms[ISLAND].exits_to_room[DOWN]= NONE; rms[ISLAND].first_time=false; rms[TOP_DECK].description.assign("top deck"); rms[TOP_DECK].longDescription.assign("The top deck has a wheel at the north end of the ship, and the south end of the ship has a ladder down to the lower deck. There is a large gorilla by the ship's wheel."); rms[TOP_DECK].exits_to_room[NORTH] = BOW; rms[TOP_DECK].exits_to_room[EAST] = NONE; rms[TOP_DECK].exits_to_room[SOUTH] = CAPTAIN_QUARTERS; rms[TOP_DECK].exits_to_room[WEST] = ISLAND; rms[TOP_DECK].exits_to_room[UP]= NONE; rms[TOP_DECK].exits_to_room[DOWN]= BOTTOM_DECK; rms[TOP_DECK].first_time=true; rms[GROVE].description.assign("grove"); rms[GROVE].longDescription.assign("There are many trees growing in the grove. Among them stands a banana tree."); rms[GROVE].exits_to_room[NORTH] = CAVE; rms[GROVE].exits_to_room[EAST] = NONE; rms[GROVE].exits_to_room[SOUTH] = ISLAND; rms[GROVE].exits_to_room[WEST] = NONE; rms[GROVE].exits_to_room[UP]= NONE; rms[GROVE].exits_to_room[DOWN]=NONE; rms[GROVE].first_time=true; rms[BOW].description.assign("There is a wheel"); rms[BOW].longDescription.assign("There is an angry Harambe and a wheel"); rms[BOW].exits_to_room[NORTH] = NONE; rms[BOW].exits_to_room[EAST] = NONE; rms[BOW].exits_to_room[SOUTH] = TOP_DECK; rms[BOW].exits_to_room[WEST] = NONE; rms[BOW].exits_to_room[UP]= NONE; rms[BOW].exits_to_room[DOWN]= NONE; rms[BOW].first_time=true; rms[BOTTOM_DECK].description.assign("bottom deck"); rms[BOTTOM_DECK].longDescription.assign("The deck below is dimly lit, and smells musty. You can make out three doors. One is to the east, one is to the west, and one is a trapdoor below you."); rms[BOTTOM_DECK].exits_to_room[NORTH] = NONE; rms[BOTTOM_DECK].exits_to_room[EAST] = GALLEY; rms[BOTTOM_DECK].exits_to_room[SOUTH] = NONE; rms[BOTTOM_DECK].exits_to_room[WEST] = CARGO; rms[BOTTOM_DECK].exits_to_room[UP]= TOP_DECK; rms[BOTTOM_DECK].exits_to_room[DOWN]= BRIG; rms[BOTTOM_DECK].first_time=true; rms[GALLEY].description.assign("galley"); rms[GALLEY].longDescription.assign("This is the galley. It is mostly empty, but in a shadowy corner you see a parrot sitting on a perch."); rms[GALLEY].exits_to_room[NORTH] = NONE; rms[GALLEY].exits_to_room[EAST] = NONE; rms[GALLEY].exits_to_room[SOUTH] = NONE; rms[GALLEY].exits_to_room[WEST] = BOTTOM_DECK; rms[GALLEY].exits_to_room[UP]= NONE; rms[GALLEY].exits_to_room[DOWN]= NONE; rms[GALLEY].first_time=true; rms[BRIG].description.assign("brig"); rms[BRIG].longDescription.assign("In this room there is a prisoner in a locked cell. He says, 'Jack, I'm so glad you're alive. The captain locked me up for cheating at cards, which is the only reason the islanders didn't capture me. They killed everyone else. Now I guess we're the only two left, which makes you captain since you were first mate. Go find the keys to unlock this door, and we can sail out of here.'"); rms[BRIG].exits_to_room[NORTH] = NONE; rms[BRIG].exits_to_room[EAST] = NONE; rms[BRIG].exits_to_room[SOUTH] = NONE; rms[BRIG].exits_to_room[WEST] = NONE; rms[BRIG].exits_to_room[UP]= BOTTOM_DECK; rms[BRIG].exits_to_room[DOWN]= NONE; rms[BRIG].first_time=true; rms[CAPTAIN_QUARTERS].description.assign("captain's quarters"); rms[CAPTAIN_QUARTERS].longDescription.assign("There is a bed and a table in this room. There is a knife and book on the table."); rms[CAPTAIN_QUARTERS].exits_to_room[NORTH] = TOP_DECK; rms[CAPTAIN_QUARTERS].exits_to_room[EAST] = NONE; rms[CAPTAIN_QUARTERS].exits_to_room[SOUTH] = NONE; rms[CAPTAIN_QUARTERS].exits_to_room[WEST] = NONE; rms[CAPTAIN_QUARTERS].exits_to_room[UP]= NONE; rms[CAPTAIN_QUARTERS].exits_to_room[DOWN]= NONE; rms[CAPTAIN_QUARTERS].first_time=true; rms[CARGO].description.assign("cargo room"); rms[CARGO].longDescription.assign("You've entered the cargo hold. There are barrels, a pile of tools, and a trunk."); rms[CARGO].exits_to_room[NORTH] = NONE; rms[CARGO].exits_to_room[EAST] = BOTTOM_DECK; rms[CARGO].exits_to_room[SOUTH] = NONE; rms[CARGO].exits_to_room[WEST] = NONE; rms[CARGO].exits_to_room[UP]= NONE; rms[CARGO].exits_to_room[DOWN]= NONE; rms[CARGO].first_time=true; rms[CAVE].description.assign("cave"); rms[CAVE].longDescription.assign("You find a cave. Fortunately, it isn't too dark inside. There is a man sleeping. He has a name tag that reads 'Greg Jamison.'"); rms[CAVE].exits_to_room[NORTH] = NONE; rms[CAVE].exits_to_room[EAST] = NONE; rms[CAVE].exits_to_room[SOUTH] = GROVE; rms[CAVE].exits_to_room[WEST] = NONE; rms[CAVE].exits_to_room[UP]= NONE; rms[CAVE].exits_to_room[DOWN]= NONE; rms[CAVE].first_time=true; rms[SHORE].description.assign("shore"); rms[SHORE].longDescription.assign("You arrive at a shore. The shore is brare but the sand is white as salt and the sound of the water brings you great ease."); rms[SHORE].exits_to_room[NORTH] = NONE; rms[SHORE].exits_to_room[EAST] = ISLAND; rms[SHORE].exits_to_room[SOUTH] = NONE; rms[SHORE].exits_to_room[WEST] = NONE; rms[SHORE].first_time=true; } // ------------------------------------------------------------------------------------------------- void set_directions(word *dir) { dir[NORTH].code = NORTH; dir[NORTH].word = "NORTH"; dir[EAST].code = EAST; dir[EAST].word = "EAST"; dir[SOUTH].code = SOUTH; dir[SOUTH].word = "SOUTH"; dir[WEST].code = WEST; dir[WEST].word = "WEST"; dir[UP].code=UP; dir[UP].word="UP"; dir[DOWN].code=DOWN; dir[DOWN].word="DOWN"; } // ------------------------------------------------------------------------------------------------- void set_verbs(word *vbs) { // {GET, LOOK, GIVE, EAT, CUT, CLIMB, USE, OPEN, UNLOCK, SAIL, GO} vbs[GET].code=GET; vbs[GET].word="GET"; vbs[GET].synonym="TAKE"; vbs[LOOK].code=LOOK; vbs[LOOK].word="LOOK"; vbs[GIVE].code=GIVE; vbs[GIVE].word="GIVE"; vbs[EAT].code=EAT; vbs[EAT].word="EAT"; vbs[CUT].code=CUT; vbs[CUT].word="CUT"; vbs[CLIMB].code=CLIMB; vbs[CLIMB].word="CLIMB"; vbs[USE].code=USE; vbs[USE].word="USE"; vbs[OPEN].code=OPEN; vbs[OPEN].word="OPEN"; vbs[UNLOCK].code=UNLOCK; vbs[UNLOCK].word="UNLOCK"; vbs[SAIL].code=SAIL; vbs[SAIL].word="SAIL"; vbs[GO].code=GO; vbs[GO].word="GO"; vbs[GO].synonym="ENTER"; vbs[GO].synonym2="BOARD"; vbs[TALK].code=TALK; vbs[TALK].word="TALK"; vbs[TALK].synonym="SPEAK"; vbs[TALK].synonym2="TELL"; vbs[READ].code=READ; vbs[READ].word="READ"; vbs[YELL].code=YELL; vbs[YELL].word="YELL"; vbs[FISH].code=FISH; vbs[FISH].word="FISH"; } // ------------------------------------------------------------------------------------------------- // Added code void set_nouns(noun *nns) { //enum en_NOUNS {DOOR, GORILLA, KNIFE, BANANAS, TREASURE, DOOR, CELL, TRUNK, PARROT, SHIP, WHEEL, KEYS, ROOM, LADDER, TREE, TRAPDOOR, BOOK, PEARS, APPLES, ORANGES}; nns[DOOR].word = "DOOR"; nns[DOOR].code = DOOR; nns[DOOR].description = "a door"; nns[DOOR].can_carry = false; nns[DOOR].location = BRIG; nns[DOOR].inventory=false; nns[GORILLA].word = "GORILLA"; nns[GORILLA].code = GORILLA; nns[GORILLA].description = "a gorilla"; nns[GORILLA].can_carry = false; nns[GORILLA].location = WHEEL; nns[GORILLA].inventory=false; nns[GORILLA].blocking = true; nns[NATIVE].word = "NATIVE"; nns[NATIVE].code = NATIVE; nns[NATIVE].description = "a group of natives"; nns[NATIVE].can_carry = false; nns[NATIVE].location = ISLAND; nns[NATIVE].inventory=false; nns[NATIVE].blocking = true; nns[KNIFE].word = "KNIFE"; nns[KNIFE].code = KNIFE; nns[KNIFE].description = "a knife"; nns[KNIFE].can_carry = true; nns[KNIFE].location = CAPTAIN_QUARTERS; nns[KNIFE].inventory=false; nns[BANANA].word = "BANANA"; nns[BANANA].code = BANANA; nns[BANANA].description = "some bananas"; nns[BANANA].can_carry = false;//changed to false, when the knife is used at the banana tree then change to true, have a line display that a bunch of bananas has been cut and has fallen on the ground nns[BANANA].location = NONE;//use function will have to change this to GROVE after the knife is used. nns[BANANA].inventory=false; nns[TREASURE].word = "TREASURE"; nns[TREASURE].code = TREASURE; nns[TREASURE].description = "some treasure"; nns[TREASURE].can_carry = true; nns[TREASURE].location = NONE; nns[TREASURE].inventory=false; nns[CELL].word = "CELL"; nns[CELL].code = CELL; nns[CELL].description = "a cell"; nns[CELL].can_carry = false; nns[CELL].location = BRIG; nns[CELL].inventory=false; nns[TRUNK].word = "TRUNK"; nns[TRUNK].code = TRUNK; nns[TRUNK].description = "a trunk"; nns[TRUNK].can_carry = false;//just state that the trunk is in the room; have the trunk be able to be oppened; when oppened display line that says the theres treasure inside nns[TRUNK].location = CARGO; nns[TRUNK].inventory=false; nns[PARROT].word = "PARROT"; nns[PARROT].code = PARROT; nns[PARROT].description = "a parrot"; nns[PARROT].can_carry = false; nns[PARROT].location = GALLEY; nns[PARROT].inventory=false; nns[SHIP].word = "SHIP"; nns[SHIP].code = SHIP; nns[SHIP].description = "a ship"; nns[SHIP].can_carry = false; nns[SHIP].location = BRIG; nns[SHIP].inventory=false; nns[WHEEL].word = "WHEEL"; nns[WHEEL].code = WHEEL; nns[WHEEL].description = "the wheel"; nns[WHEEL].can_carry = false; nns[WHEEL].location = TOP_DECK; nns[WHEEL].inventory=false; nns[KEYS].word = "KEYS"; nns[KEYS].code = KEYS; nns[KEYS].description = "some keys"; nns[KEYS].can_carry = true; nns[KEYS].location = NONE; nns[KEYS].inventory=false; nns[ROOM].word = "ROOM"; nns[ROOM].code = ROOM; nns[ROOM].description = "a room"; nns[ROOM].can_carry = false; nns[ROOM].location = NONE; nns[ROOM].inventory=false; nns[LADDER].word = "LADDER"; nns[LADDER].code = LADDER; nns[LADDER].description = "a ladder"; nns[LADDER].can_carry = false; nns[LADDER].location = TOP_DECK; nns[LADDER].inventory=false; nns[TREE].word = "TREE"; nns[TREE].code = TREE; nns[TREE].description = "a tree among the grove with lush, ripe bananas ready to be picked"; nns[TREE].can_carry = false; nns[TREE].location = GROVE; nns[TREE].inventory=false; nns[TRAPDOOR].word = "TRAPDOOR"; nns[TRAPDOOR].code = TRAPDOOR; nns[TRAPDOOR].description = "a trapdoor"; nns[TRAPDOOR].can_carry = false; nns[TRAPDOOR].location = BOTTOM_DECK; nns[TRAPDOOR].inventory=false; nns[BACKPACK].word = "BACKPACK"; nns[BACKPACK].code = BACKPACK; nns[BACKPACK].description = "it's where your items are"; nns[BACKPACK].can_carry = false; nns[BACKPACK].location = NONE; nns[BACKPACK].inventory=false; nns[BOOK].word = "BOOK"; nns[BOOK].code = BOOK; nns[BOOK].description = "a book"; nns[BOOK].can_carry = true; nns[BOOK].location = CAPTAIN_QUARTERS; nns[BOOK].inventory=false; nns[PRISONER].word="PRISONER"; nns[PRISONER].code=PRISONER; nns[PRISONER].can_carry=false; nns[PRISONER].location=NONE; nns[PRISONER].inventory=false; nns[PRISONER].free=false; nns[MAN].word = "MAN"; nns[MAN].code = MAN; nns[MAN].can_carry=false; nns[MAN].description = "a sleeping man."; nns[MAN].location=CAVE; nns[MAN].inventory=false; nns[FISHING_ROD].word = "FISHING ROD"; nns[FISHING_ROD].code = FISHING_ROD; nns[FISHING_ROD].description = "a fishing rod"; nns[FISHING_ROD].can_carry = false; nns[FISHING_ROD].location = SHORE; nns[FISHING_ROD].inventory = false; } // .... // ------------------------------------------------------------------------------------------------- void Title() { cout << "*********** ********* *** *** ********** ****** *** ************ *** *** ********* ********** \n"; cout << "*********** ********** *** *** ********** ******* *** ************ *** *** ********** ********** \n"; cout << "*** *** *** *** *** *** *** *** *** *** **** *** *** *** *** *** \n"; cout << "*** *** *** *** *** *** *** *** *** *** **** *** *** *** *** *** \n"; cout << "*********** *** *** *** *** ********** *** *** *** **** *** *** ********** ********** \n"; cout << "*********** *** *** *** *** ********** *** ****** **** *** *** ********** ********** \n"; cout << "*** *** *** *** ******* *** *** ***** **** **** **** *** *** *** \n"; cout << "*** *** ********** ***** ********** *** **** **** *********** *** *** ********** \n"; cout << "*** *** ********* *** ********** *** *** **** ******* *** *** ********** \n"; cout << " \n"; cout << "*********** ********** *** *********** ****** *** ********* \n"; cout << "*********** ********** *** *********** ******* *** ********** \n"; cout << " ***** *** *** *** *** *** *** *** *** *** \n"; cout << " ***** ********** *** *** *** *** *** *** *** *** \n"; cout << " ***** ********** *** *********** *** *** *** *** *** \n"; cout << " ***** *** *** *********** *** ****** *** *** \n"; cout << " ***** *** *** *** *** *** ***** *** *** \n"; cout << "*********** ********** ********** *** *** *** **** ********** \n"; cout << "*********** ********** ********** *** *** *** *** ********* \n"; } string pigLatin(string word) { //pigLatWord holds word translated in pig latin. //pigLatSentence holds entire translated sentence. string pigLatWord, pigLatSentence = ""; int length = 0, index = 0; while (word[index] != '\0'){ // .find returns -1 if no match is found if (word.find(' ', index) != -1){ length = word.find(' ', index); length -= index;//length - index = the number of characters in a word pigLatWord = word.substr(index, length); pigLatWord.insert(length, "ay"); pigLatWord.insert(length, 1, word[index]);//first letter is inserted at the end of the string pigLatWord.erase(0, 1);// erase first letter in string index += length + 1;//adding one moves index from 'space' to first letter in the next word } else{ pigLatWord = word.substr(index); length = pigLatWord.length(); pigLatWord.insert(length, "ay"); pigLatWord.insert(length, 1, word[index]); pigLatWord.erase(0, 1); index = word.length(); } pigLatSentence += (pigLatWord + " "); transform(pigLatSentence.begin(), pigLatSentence.end(), pigLatSentence.begin(), ::tolower); } return pigLatSentence; } void section_command(string Cmd, string &wd1, string &wd2) { string sub_str; vector<string> words; char search = ' '; size_t i, j; // Split Command into vector for(i = 0; i < Cmd.size(); i++) { if(Cmd.at(i) != search) { sub_str.insert(sub_str.end(), Cmd.at(i)); } if(i == Cmd.size() - 1) { words.push_back(sub_str); sub_str.clear(); } if(Cmd.at(i) == search) { words.push_back(sub_str); sub_str.clear(); } } // Clear out any blanks // I work backwords through the vectors here in order to not to invalidate the iterator for(i = words.size() - 1; i > 0; i--) { if(words.at(i) == "") { words.erase(words.begin() + i); } } // Make words upper case // Right here is where the functions from cctype are used for(i = 0; i < words.size(); i++) { for(j = 0; j < words.at(i).size(); j++) { if(islower(words.at(i).at(j))) { words.at(i).at(j) = toupper(words.at(i).at(j)); } } } // only want the first to words at most (verb / noun) if(words.size() == 0) { cout << "No command given" << endl; } if(words.size() == 1) { wd1 = words.at(0); } if(words.size() == 2) { wd1 = words.at(0); wd2 = words.at(1); } if(words.size() > 2) { cout << "Command too long. Only type one or two words (direction or verb and noun)" << endl; } } // ---------------------------------------------------------------------------------------- void look_around(int loc, room *rms, word *dir, /* Added parameter */ noun *nns) { int i; cout << "You are in a " << rms[loc].description << "." << endl; for(i = 0; i < DIRS; i++) { if(rms[loc].exits_to_room[i] != NONE) { cout << "There is an exit " << dir[i].word << " to a " << rms[rms[loc].exits_to_room[i]].description << "." << endl; } } // Added code // The look command should check which objects (nouns) are in the current room and report them to the player. for(i = 0; i < NOUNS; i++) { if(nns[i].location == loc) { cout << "You see " << nns[i].description << "." << endl; } } } //----------------------------------------------------------------------------------------- void inventory(noun*nns) { int i, numItems; numItems=0; cout<<endl; cout<<"These items are in your inventory."<<endl; for(i=0;i<NOUNS;i++) { if(nns[i].inventory==true) { cout<<nns[i].word<<endl; numItems++; } } if(numItems==0) { cout<<"Actually,there seems to be nothing here."<<endl; cout<<"Why don't you go explore and see what you can find."<<endl; cout<<endl; } } //----------------------------------------------------------------------------------------- void get_item(int loc,noun*nns,string wd2) { int i; for(i=0;i<NOUNS;i++) { if(nns[i].location==loc and nns[i].word==wd2)// this conditional makes sure that the function only cycles once to get what you typed in { if(nns[i].can_carry!=false) { nns[i].inventory=true; cout<<"Obtained "<<nns[i].word<<endl; } else cout<<"You can't get that."<<endl; } } } //----------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------- bool parser(int &loc, string wd1, string wd2, word *dir, word *vbs, room *rms, /* Added parameter */ noun *nns) { // Added code static bool door_state = false; // false is a closed door. // .... int i; for(i = 0; i < DIRS; i++) { if(wd1 == dir[i].word) { if(rms[loc].exits_to_room[dir[i].code] != NONE) { loc = rms[loc].exits_to_room[dir[i].code]; if(rms[loc].first_time==true) { cout << rms[loc].longDescription << endl; rms[loc].first_time=false; } else cout<<rms[loc].description<<endl; // Added code. A special case for the corridor storeroom door. if(loc == GALLEY || loc == BOTTOM_DECK) { nns[DOOR].location = loc; } // .... return true; } else { cout << "No exit that way." << endl; return true; } } } // Added code int NOUN_MATCH = NONE; // .... int VERB_ACTION = NONE; for(i = 0; i < VERBS; i++) { if(wd1 == vbs[i].word or wd1==vbs[i].synonym or wd1==vbs[i].synonym2) { VERB_ACTION = vbs[i].code; break; } } // Added code if(wd2 != "") { for(i = 0; i < NOUNS; i++) { if(wd2 == nns[i].word) { NOUN_MATCH = nns[i].code; break; } } } if(VERB_ACTION == NONE) { cout << "No valid command entered." << endl; return true; } if(VERB_ACTION == LOOK) { look_around(loc, rms, dir, /* Added parameter nns */ nns); return true; } // Added code // Actions for usage of VERB OPEN if(VERB_ACTION == OPEN) { switch(NOUN_MATCH) { case DOOR: if(loc == GALLEY || loc == BOTTOM_DECK) { if(door_state == false) { door_state = true; rms[BOTTOM_DECK].exits_to_room[EAST] = GALLEY; rms[GALLEY].exits_to_room[WEST] = BOTTOM_DECK; nns[DOOR].description.clear(); nns[DOOR].location=NONE; cout << "I have opened the door." << endl; return true; } else if(door_state == true) { cout << "The door is already open." << endl; return true; } } else { cout << "There is no door to open here." << endl; return true; } break; case BACKPACK: inventory(nns); break; case TRUNK: cout<<"You oppened the trunk to reveal some treasure inside."<<endl; nns[TREASURE].location=CARGO; break; default: cout<<"You cant open that."<<endl; } } // .... if(VERB_ACTION == TALK) { switch(NOUN_MATCH) { case PARROT: if(loc == GALLEY) { string sentence; string str1 ("HELLO"); string str2 ("POLLY"); string str3 ("CRACKER"); cout << "What would you like to say to the parrot?\n"; getline(cin, sentence); transform(sentence.begin(), sentence.end(), sentence.begin(), ::toupper); if(sentence.find(str1) != string::npos and sentence.find(str2) != string::npos and sentence.find(str3) != string::npos) { cout << "The parrot says: 'Rawk! There is a secret comparment in the captains quarters! Rawk!'\n"; nns[KEYS].location=CAPTAIN_QUARTERS; } else { sentence = pigLatin(sentence); cout << sentence << endl; } } else { cout << "There doesn't seem to be a parrot in this room. \n"; } break; case MAN: if(loc == CAVE) { cout<<"The man jolts awake."<<endl; cout<<"The man stutters, 'Er...uh..WELCOME TO COLLOSAL CAVE!!...'"<<endl; cout<<"Not impressed, you stand there silently. You already know Adventure Island is a better game. ;)"<<endl; } else { cout<<"There is no man here."<<endl; } break; case PRISONER: if(loc == BRIG){ cout<<"What are ye doing mate? Go on and get the keys."<<endl; } else { cout<<"Who are you talking to..? Nobody is here.."<<endl; } break; default: cout<<"You can't talk to that."<<endl; } } if(VERB_ACTION == READ) { if(NOUN_MATCH == BOOK) { if(loc == CAPTAIN_QUARTERS) { cout << "The book reads: 'I got a Glock in my rari, 17 shots, no .38 '"<<endl; } else { cout << "There doesn't seem to be a book in this room. \n"; } } else { cout << "Unfortunately you can't read that object. \n"; } } if(VERB_ACTION==GET) { get_item(loc,nns,wd2); } if(VERB_ACTION == FISH) { if(loc == SHORE) { srand((unsigned)time(0)); int m; m = (rand()%6)+1; switch(m) { case 1: cout << "You caught a ball. It has read smears on it that resemble a face. The ball reads Wilson. \n"; cout << "You let it back to sea \n"; break; case 2: cout << "You caught a botle that contains a note. You you open the bottle and read the note.\n"; cout << "It reads: 'Mary, you really are a great person. I hope we can keep in correspondence. I said I would write. Your friend always, Jonathon, Nova Scotia, 1985.' \n"; cout << "You let it back to sea \n"; case 3: cout << "You caught a botle that contains a note. You you open the bottle and read the note.\n"; cout << "It reads: 'My name is Frank, and I'm five years old. My dad and I are travelling on a ship to Denmark. If you find this letter, please write back to me, and I will write back to you.' \n"; cout << "You let it back to sea \n"; break; case 4: cout << "Nothing seems to be biting. \n"; break; case 5: cout << "You caught a fish. It's orange with large white stripes and beedy black eyes.\n"; cout << "Argh! Unforuantley it slipped out of your fingers making its way back to sea.\n"; break; case 6: cout << "You caught a botle that contains a document. You you open the bottle and read the document.\n"; cout << "It reads: 'C Sci 40 Assignments 1: Volume.cpp) Write a program that reads a radius and prints...' \n"; cout << "Ehh..boring..You toss it back to sea \n"; break; } } else { cout << "You can't fish here. \n"; } } if(VERB_ACTION == YELL) { if(loc == CAVE) { string words; cout << "What would you like to yell? \n"; cin >> words; cout << "'" << words << " " << words << " " << words << "... ' " << "echoed through the cave \n"; } else { cout << "Unfortunatley no one can hear you. \n"; } } if(VERB_ACTION==GO) { int i; for(i = 0; i < DIRS; i++) { if(wd2 == dir[i].word) { if(rms[loc].exits_to_room[dir[i].code] != NONE) { loc = rms[loc].exits_to_room[dir[i].code]; cout << "You are now in a " << rms[loc].description << "." << endl; // Added code. A special case for the corridor storeroom door. if(loc == GALLEY || loc == BOTTOM_DECK) { nns[DOOR].location = loc; } // .... return true; } else { cout << "No exit that way." << endl; return true; } } } } if(VERB_ACTION==USE) { switch(NOUN_MATCH){ case KNIFE: if(nns[KNIFE].inventory== true){ if(loc == GROVE){ cout<<"You take the knife and cut down the bananas."<<endl; cout<<"You now have the bananas."<<endl; nns[BANANA].inventory=true; } else{ cout<<"There ain't nothing to cut here dawg."; } } else { cout<<"You don't have a knife."<<endl; } break; case BANANA: { if(nns[GORILLA].blocking = true){ if(nns[BANANA].inventory == true){ if(loc==BOW) { cout<<"You give banana."<<endl; nns[BANANA].inventory=false; nns[GORILLA].blocking=false; } else{ cout<<"gorilla not here."<<endl; } } else { cout<<"You no have banana."<<endl; } } else{ cout<<"The gorilla is gone."<<endl; } } break; case KEYS: { if(loc==BRIG) cout<<"You open the cell and let the prisoner out. He rejoices."<<endl; nns[PRISONER].free=true; cout<<"The prisoner tells you that you could possibly set sail now."<<endl; cout<<endl; } break; case TREASURE: { if(nns[NATIVE].blocking == true) { if(loc==TOP_DECK) { cout<<"You give the trasue to the native in order to gain passage back to the Island."<<endl; //find a way to stop acces to the island and then restore it after giving the treasure. } } else { cout<<"You cannot cross without an offering."; } } break; case WHEEL: { if(loc==BOW) { if(nns[PRISONER].free==true) { cout<<"With the former prisoner set free and manning the sails, you take hold of the wheel and sail away into the sunset."<<endl; cout<<"Congratulations"<<endl; } else { cout<<"You cant possibly set sail without having someone man the sails."<<endl; cout<<endl; } } } break; } } return false; } // ---------------------------------------------------------------------------------------- int main() { string command; string word_1; string word_2; room rooms[ROOMS]; set_rooms(rooms); word directions[DIRS]; set_directions(directions); word verbs[VERBS]; set_verbs(verbs); // Added code noun nouns[NOUNS]; set_nouns(nouns); // .... int location = ISLAND; Title(); cout << "Hi! You've just awakened on a strange island with a terrible headache and you can't seem remember anything about yourself or where you are.\n"; while(word_1 != "QUIT") { command.clear(); cout << "What shall I do? "; getline(cin, command); word_1.clear(); word_2.clear(); section_command(command, word_1, word_2); if(word_1 != "QUIT") { parser(location, word_1, word_2, directions, verbs, rooms, /* Added parameter */ nouns); } } return 0; }
run
|
edit
|
history
|
help
0
C++ state machine prototype
ContainerVector2
Zscore
Web Browser History
Hello
BadCastAllExcept
TwoANOVA
Splitwise Problem - 1
MoveBubble
Programa 3(Creo que ya esta)