#include #include #include class Location; // The Exit Object class Exit { public: Exit(int = 0, char[] = "NONE", Location * = NULL); int exists; char direction[10]; Location *leads_to; }; //Default Constructor for the Exit class Exit::Exit(int x, char d[], Location * p) { exists = x; strcpy(direction, d); leads_to=p; } class Location { public: void set_title( char new_title[20] ); void set_description( char new_description[350] ); void print_title(); void print_description(); void set_exit( int side, Exit new_exit ); void print_exits(); int test_exit(int); private: char room_title[20]; char room_description[350]; public: Exit room_exits[5]; }; //Member functions for Location class void Location::set_title( char new_title[20] ) { strcpy(room_title, new_title); } void Location::set_description( char new_description[350] ) { strcpy(room_description, new_description); } void Location::print_title() { cout << room_title << endl; } void Location::print_description() { cout << room_description << endl; } void Location::set_exit( int side, Exit new_exit ) { room_exits[side] = new_exit; } void Location::print_exits() { for(int i = 0; i <= 4; i++) { if (room_exits[i].exists) { cout << room_exits[i].direction << endl; } } } int Location::test_exit(int move_to) { int x = room_exits[move_to].exists; return x; } // Main Program int main() { //Declarations char input[10]; //Input by player. int move_to; //Matches slot in exit array. int key = 0; //Changes to 1 when key is grabbed. Location *current_room; //Pointer to the current room. Location *new_room; //Introduction cout << "\n Welcome to David's Maze." << endl; cout << "To move about the maze type the name of an exit\n"; cout << "and Return. If you give up type QUIT." << endl; cout << "Please type commands in ALL CAPS in this version." << endl; //Set-up Maze Location room1; char title1[] = "Blue Chair Room"; char description1[] = "You are in a room where the stone walls are carved in a geometric pattern. A pillar stands in the center of the room. A carved stone chair with blue velvet cushions is in the center of the room, its back towards the pillar."; room1.set_title(title1); room1.set_description(description1); Location room2; char title2[] = "Night Sky Room"; char description2[] = "The ceiling of this room is arched. The ceiling is painted black. Mother-of-pearl stars are set in the ceiling mapping the night sky."; room2.set_title(title2); room2.set_description(description2); Location room3; char title3[] = "Entrance Room"; char description3[] = "You are in a room carved from stone to resemble the inside of a monster's mouth. Giant stone teeth project from the ceiling and floor. On the north wall, at the front of the mouth where the teeth meet, is a heavy door which was locked behind you when you entered."; room3.set_title(title3); room3.set_description(description3); Location room4; char title4[] = "Warrior Room"; char description4[] = "Statues of warriors stand in each corner of this room. Each figure is dressed in scale armor and a feathered headdress and carries a spear. On the wall are carvings of battle scenes."; room4.set_title(title4); room4.set_description(description4); Location room5; char title5[] = "Scroll Room"; char description5[] = "You are in a room with a table against the east wall. On the table are a pile of papyrus scrolls. All the scrolls are written in hieroglyphics you do not understand, except one, on which is written in your own language Seek the Key in the Center."; room5.set_title(title5); room5.set_description(description5); Location room6; char title6[] = "Eye Room"; char description6[] = "On the ceiling of this room is a tile mosaic of a giant eye. The walls of the room are covered with carvings of the ancient, animal-headed gods."; room6.set_title(title6); room6.set_description(description6); Location room7; char title7[] = "Red Room"; char description7[] = "You are in a room with walls painted deep red. Crimson tiles cover the floor. Statues of jaguars stand upright in each corner of the room."; room7.set_title(title7); room7.set_description(description7); Location room8; char title8[] = "Mosaic Room"; char description8[] = "A tile mosaic covers the walls, floor, and ceiling of this room. A disc representing the world covers the floor. In the center rises a pillar, carved to represent the tree of life, whose brances spead in a mosaic on the ceiling. A dragon of red and gold tiles winds around the walls of the room."; room8.set_title(title8); room8.set_description(description8); Location room9; char title9[] = "Yellow Room"; char description9[] = "The walls of this room are painted yellow. Golden tiles cover the floor. Statues of lions stand in each corner of the room."; room9.set_title(title9); room9.set_description(description9); Location room10; char title10[] = "Red Chair Room"; char description10[] = "The walls of this room are carved in a geometric pattern inlaid with red stones. A pillar stands in the center of the room. A carved stone chair with red velvet cushions is in the center of the room, its back against the pillar."; room10.set_title(title10); room10.set_description(description10); Location room11; char title11[] ="Hieroglyphics Room"; char description11[] = "The walls of this room are covered with heiroglyphics. You cannot read what they are saying. Two large eyes are carved high up on the south wall."; room11.set_title(title11); room11.set_description(description11); Location room12; char title12[] = "Sarcophagus Room"; char description12[] = "In the center of this room is a large stone sarcophagus. The heavy stone lid is carved with the image of a man in regal dress. The walls of the room are carved with scenes of the man on the lid -- his coronation, in battle, with his queen and child, and facing the gods."; room12.set_title(title12); room12.set_description(description12); Location room13; char title13[] = "Key Room"; char description13[] = "The stones in the wall of this room are arranged in a lattice pattern. In the center of the room is a stone pedestal. The pedestal is covered with carved heiroglyphics. On the pedestal is a shiny brass key."; room13.set_title(title13); room13.set_description(description13); Location room14; char title14[] = "Bird Room"; char description14[] = "You are in a room where the walls are covered with stone carvings of birds. The carvings are bightly painted in a multitude of plumage colors. You can hear birds singing, but you cannot tell from where it is coming."; room14.set_title(title14); room14.set_description(description14); Location room15; char title15[] = "Window Room"; char description15[] = "The east wall of this room has a window which looks out onto a garden of bright tropical flowers. The window is barred, and you cannot get out that way. Vines are growing into the room through the window."; room15.set_title(title15); room15.set_description(description15); Location room16; char title16[] = "Fountain Room"; char description16[] = "The floor of this room is tiled in soothing shades of blue abd green. In the center of the room is a fountain. Water splashes out of the central spire into a circular pool."; room16.set_title(title16); room16.set_description(description16); Location room17; char title17[] = "White Room"; char description17[] = "You are in a room whose walls are plastered white. White tiles cover the floor. Statues of griffens stand in the four corners of the room."; room17.set_title(title17); room17.set_description(description17); Location room18; char title18[] = "Altar Room"; char description18[] = "On the north side of this room stands a stone altar on a raised platform. The altar is carved with heiroglyphics and stained dark red. The walls are carved with pictures of ancient gods."; room18.set_title(title18); room18.set_description(description18); Location room19; char title19[] = "Blue Room"; char description19[] = "You are in a room with the walls painted deep blue. The floor is covered with azure tiles. In the corners of the room stand upright statues of crocodiles."; room19.set_title(title19); room19.set_description(description19); Location room20; char title20[] = "Water Room"; char description20[] = "The floor of this room is covered with blue tiles and the tops of the walls are painted with a pattern representing rain clouds. A table is pushed against the west wall. On the table is a pitcher of water and a cup."; room20.set_title(title20); room20.set_description(description20); Location room21; char title21[] = "Stone Head Room"; char description21[] = "In the center of this room is a large stone head, about 6 feet around. The head is raised low platform a few inches above the floor. The walls a covered with heiroglyphics and pictures of a person who the stone head resembles."; room21.set_title(title21); room21.set_description(description21); Location room22; char title22[] = "Stella Room"; char description22[] = "On the south wall of this room is a carved stone slab. It is covered with heiroglyohics and the image of a man in elaborate regal dress."; room22.set_title(title22); room22.set_description(description22); Location room23; char title23[] = "Exit Room"; char description23[] = "Near the top of the walls in this room are carved with grinning faces. The faces' large hooked noses stick out from the walls. In the south wall is a heavy door, similar to the one at the entrance."; room23.set_title(title23); room23.set_description(description23); Location room24; char title24[] = "Cobra Room"; char description24[] = "A statue of a cobra rises from the center of this room. The floor is tiled in a pattern that suggests entwining snakes. The walls a carved with snakes."; room24.set_title(title24); room24.set_description(description24); Location room25; char title25[] = "Skull Room"; char description25[] = "On the walls of this room are carved hundreds of skulls, staring out of the walls at you. The floor is covered with a tile mosaic of a skeleton."; room25.set_title(title25); room25.set_description(description25); Location grab_key; char title_key[] = "Take the Key"; char description_key[] = "You now have the shinny brass key. Now if only you had a lock to open with it."; grab_key.set_title(title_key); grab_key.set_description(description_key); Location sitting; char title_sit[] = "Spinning"; char description_sit[] = "When you sit down you feel yourseflf spinning. The world becomes a blur. After a few seconds your senses clear, and you find yourself in a different room."; sitting.set_title(title_sit); sitting.set_description(description_sit); Location seat; char title_seat[] = "Sitting in Chair"; char description_seat[] = "The chair is very comfortable, and you have a nice rest."; seat.set_title(title_seat); seat.set_description(description_seat); Location drinking; char title_drink[] = "Drink of Water"; char description_drink[] = "The water is cool and refreshing. As you drink it you think you hear the sound of running water. The world goes dark and you feel like you are falling. You come to kneeling in front of a fountain, which makes the splashing water sounds you heard."; drinking.set_title(title_drink); drinking.set_description(description_drink); Location fountain; char title_fount[] = "The Fountain"; char description_fount[] = "As you look into the fountain you see this pattern shimering on the surface of the water. * - * * - * - * | | | | * - * - * * - * | | | * * - * * - * | | | * * - * - * * | | | | | * * * * - *"; fountain.set_title(title_fount); fountain.set_description(description_fount); Location locked; char title_lock[] = "Locked"; char description_lock[] = "The door is locked. You must find the key to exit this way."; locked.set_title(title_lock); locked.set_description(description_lock); Location out; char title_out[] = "You're Out"; char description_out[] = "You open the door with your shinny brass key. Congradulations, you've made it out of the maze. "; out.set_title(title_out); out.set_description(description_out); Exit east01(1, "EAST", &room2); room1.set_exit(1, east01); Exit south01(1, "SOUTH", &room6); room1.set_exit(2, south01); Exit chair01(1, "CHAIR", &seat); room1.set_exit(4, chair01); Exit seat01(1, "OK", &room1); seat.set_exit(4, seat01); Exit west02(1, "WEST", &room1); room2.set_exit(3, west02); Exit south02(1, "SOUTH", &room7); room2.set_exit(2, south02); Exit east03(1, "EAST", &room4); room3.set_exit(1, east03); Exit south03(1, "SOUTH", &room8); room3.set_exit(2, south03); Exit east04(1, "EAST", &room5); room4.set_exit(1, east04); Exit south04(1, "SOUTH", &room9); room4.set_exit(2, south04); Exit west04(1, "WEST", &room3); room4.set_exit(3, west04); Exit west05(1, "WEST", &room4); room5.set_exit(3, west05); Exit north06(1, "NORTH", &room1); room6.set_exit(0, north06); Exit east06(1, "EAST", &room7); room6.set_exit(1, east06); Exit south06(1, "SOUTH", &room11); room6.set_exit(2, south06); Exit north07(1, "NORTH", &room2); room7.set_exit(0, north07); Exit east07(1, "EAST", &room8); room7.set_exit(1, east07); Exit south07(1, "SOUTH", &room12); room7.set_exit(2, south07); Exit west07(1, "WEST", &room6); room7.set_exit(3, west07); Exit north08(1, "NORTH", &room3); room8.set_exit(0, north08); Exit west08(1, "WEST", &room7); room8.set_exit(3, west08); Exit north09(1, "NORTH", &room4); room9.set_exit(0, north09); Exit east09(1, "EAST", &room10); room9.set_exit(1, east09); Exit west10(1, "WEST", &room9); room10.set_exit(3, west10); Exit south10(1, "SOUTH", &room15); room10.set_exit(2, south10); Exit chair10(1, "CHAIR", &sitting); room10.set_exit(4, chair10); Exit sitting10(1, "OK", &room1); sitting.set_exit(4, sitting10); Exit north11(1, "NORTH", &room6); room11.set_exit(0, north11); Exit south11(1, "SOUTH", &room16); room11.set_exit(2, south11); Exit north12(1, "NORTH", &room7); room12.set_exit(0, north12); Exit east12(1, "EAST", &room13); room12.set_exit(1, east12); Exit west13(1, "WEST", &room12); room13.set_exit(3, west13); Exit key13(1, "KEY", &grab_key); room13.set_exit(4, key13); Exit got_key(1, "OK", &room13); grab_key.set_exit(4, got_key); Exit east14(1, "EAST", &room15); room14.set_exit(1, east14); Exit south14(1, "SOUTH", &room19); room14.set_exit(2, south14); Exit north15(1, "NORTH", &room10); room15.set_exit(0, north15); Exit south15(1, "SOUTH", &room20); room15.set_exit(2, south15); Exit west15(1, "WEST", &room14); room15.set_exit(3, west15); Exit north16(1, "NORTH", &room11); room16.set_exit(0, north16); Exit south16(1, "SOUTH", &room21); room16.set_exit(2, south16); Exit fountain16(1, "FOUNTAIN", &fountain); room16.set_exit(4, fountain16); Exit seen_fount(1, "OK", &room16); fountain.set_exit(4, seen_fount); Exit east17(1, "EAST", &room18); room17.set_exit(1, east17); Exit south17(1, "SOUTH", &room22); room17.set_exit(2, south17); Exit east18(1, "EAST", &room19); room18.set_exit(1, east18); Exit south18(1, "SOUTH", &room23); room18.set_exit(2, south18); Exit west18(1, "WEST", &room17); room18.set_exit(3, west18); Exit north19(1, "NORTH", &room14); room19.set_exit(0, north19); Exit south19(1, "SOUTH", &room24); room19.set_exit(2, south19); Exit west19(1, "WEST", &room18); room19.set_exit(3, west19); Exit north20(1, "NORTH", &room15); room20.set_exit(0, north20); Exit south20(1, "SOUTH", &room25); room20.set_exit(2, south20); Exit water20(1, "WATER", &drinking); room20.set_exit(4, water20); Exit drink20(1, "OK", &room16); drinking.set_exit(4, drink20); Exit north21(1, "NORTH", &room16); room21.set_exit(0, north21); Exit north22(1, "NORTH", &room17); room22.set_exit(0, north22); Exit north23(1, "NORTH", &room18); room23.set_exit(0, north23); Exit south23(1, "SOUTH", &locked); room23.set_exit(2, south23); Exit lock23(1, "OK", &room23); locked.set_exit(4, lock23); Exit north24(1, "NORTH", &room19); room24.set_exit(0, north24); Exit east24(1, "EAST", &room25); room24.set_exit(1, east24); Exit north25(1, "NORTH", &room20); room25.set_exit(0, north25); Exit west25(1, "WEST", &room24); room25.set_exit(3, west25); current_room = &room3; //Entrance to Maze cout << "\n Traversing the Maze did not seem such a daunting prospect when"; cout << "\n you were boasting to impress the chief. That was when you first"; cout << "\n arrived amoung these people. They told you that the thing outsiders"; cout << "\n must do to gain acceptance is travel the Maze. It didn't sound that"; cout << "\n hard. But that was before the chief accepted your offer and you were"; cout << "\n with actually doing it." << endl; cout << "\n The Maze is under a pyramid in the ruins of a city of the ancients."; cout << "\n The entrance to the maze through a carved stone monster head at the"; cout << "\n base of the pyramid. A heavy door is set in the monster's mouth."; cout << "\n The natives give you a torch to light your way in the dark passages."; cout << "\n You step into the monster's mouth and the door slams shut behind you.\n" << endl; while(strcmp("OK", input)) { cout << "Type OK to continue." << endl; cin.getline(input, 10, '\n'); } //Main Operational Loop //Print Description and Exits, Read Input, Point to next Location while(current_room!=&out) { //Print Current Room Description cout << "\n"; current_room->print_title(); cout << "\n"; current_room->print_description(); //Print Exits from Current Room cout << "\n Availible Exits:" << endl; current_room->print_exits(); //Read Input cin.getline(input, 10, '\n'); // format_input(input); // Input tests if (!strcmp("QUIT", input)) return 0; // Calculate move_to number if (!strcmp("NORTH", input)) move_to = 0; else if (!strcmp("EAST", input)) move_to = 1; else if (!strcmp("SOUTH", input)) move_to = 2; else if (!strcmp("WEST", input)) move_to = 3; else if (!strcmp("KEY", input)) move_to = 4; else if (!strcmp("CHAIR", input)) move_to = 4; else if (!strcmp("WATER", input)) move_to = 4; else if (!strcmp("FOUNTAIN", input)) move_to = 4; else if (!strcmp("OK", input)) move_to = 4; else move_to = 99; if (move_to == 99) { cout << "Improper direction." << endl; continue; } // Test that exit exists. if (current_room->test_exit(move_to) == 0) { cout << "No exit in that direction." << endl; continue; } // Update current location to show move through exit. new_room = (current_room->room_exits[move_to]).leads_to; //Pick Up Key if (new_room == &grab_key) { key = 1; char key_gone[] = "The stones in the wall of this room are arranged in a lattice pattern. In the center of the room is a stone pedestal. The pedestal is covered with carved heiroglyphics."; room13.set_description(key_gone); (current_room->room_exits[4]).exists = 0; } //Test for Key to get out. if ((new_room == &locked) && (key == 1)) { new_room = &out; } current_room = new_room; } cout << "\n"; current_room->print_title(); cout << "\n"; current_room->print_description(); return 0; }