Thread: my text adventure

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    12

    my text adventure

    this is my text adventure i talked about in earlier posts. its still kinda buggy but its not too bad.
    Code:
    #include <iostream.h>//needed for printouts
    #include <string.h>//needed to compare strings
    #include <windows.h>//used for text colors
    
    	struct puzzles//variables used throughout the game
    	{
    		int flashlight;
    		int keycard;
    		int chisel;
    		int ring;
    		int jewel;
    		int key;
    
    	};
    puzzles roomONE;//datatypes for reach room
    puzzles roomTWO;
    puzzles roomTHREE;
    puzzles roomFOUR;
    puzzles roomFIVE;
    puzzles roomSIX;
    
    char choice [30];//cin used to enter look, take, use, or move
    char look [30];
    char use [30];
    char move [30];
    char take [30];
    char item1[30];
    char item2 [30];
    char direction;
    int loop=0;
    
    HANDLE hOut;//used for text colors
    
    void room1();//function for each room
    void room2();
    void room3();
    void room4();
    int room5();
    void room6();
    
    main()
    {
    	hOut = GetStdHandle(STD_OUTPUT_HANDLE);//used for text colors
    
    	SetConsoleTitle("Can you escape?");//sets console title to "can you escape?"
    	char name[31];//stores players name
    
    	cout << "whats your name? ";
    	cin.get(name, 31);
    	cin.ignore(80, '\n');//gets and stores user name for welcome
    
    	    SetConsoleTextAttribute(hOut,
                                FOREGROUND_GREEN | 
                                FOREGROUND_BLUE |
                                FOREGROUND_INTENSITY);//makes text cyan
    		//intro and instructions
    	cout << "Welcome to my text adventure " << name << ".\n";
    	cout << "the last thing you remember is Chad Wolferd chasing you \n";
    	cout << "with his bottle of Chloroform\n";
    	cout << "now, you are in an unknown location and your goal is to escape.\n";
    	cout << "if you get into the look, use, or take functions and dont want to be, type cancel\n";
    	cout << "if you get into the move function and dont want to be leave and re-enter the room\n";
    	cout << "To move to a different room type a upper or lowercarse LETTER representing\n";
    	cout << "the direction you want to travel. EX: if you want to go north type N or n.\n";
    	cout << "NOT north, North, or NORTH! Now that we cleared that up lets begin. " << flush <<"\n";
    
    	room2();//call to room2 function and starts game
    
    	return 0;
    }
    
    void room1()//function for room1
    {
    	
    	    SetConsoleTextAttribute(hOut,
                                FOREGROUND_BLUE | 
                                FOREGROUND_RED |
                                FOREGROUND_INTENSITY);//makes text purple
    
    	int x=0;//used to kick out of for/switch
    	int combo=0;//used for puzzle in this room
    	int loop=0;
    	int light=0;
    
    	cout << '\n';//adds space that makes text easier to read
    	cout << "You enter a room that seems devoid of light, you cant see anything\n";
    	cout << "doors are to the east and south\n";
    
    	while (loop!=1)//loops until user moves to different room, this loop is basiclly the same
    	{		//in each functions. the only changes are to make the loop specific for each room
    	int moveNum=0;//used in move sub-loop
    	int lookNum=0;//used in look sub-loop
    	int takeNum=0;//used in take sub-loop
    	int useNum=0;//used in use sub-loop
    	int x=0;//used to see if valid answer was given in the loops, if x!=1 it tells the user they entered an invlid answer
    	cout << "what do you want to do? (look, take, use, or move) ";
    	cin >> choice;
    	cin.ignore(80, '\n');
    	/////////LOOK//////////
    	if (strcmp(choice, "look")==0)//if user enters look, enters look sub-loop
    		{
    		while (lookNum!=1)
    			{
    				cout << "look at what? ";
    				cin >> look;
    				cin.ignore(80, '\n');
    			if ((strcmp(look, "room")==0) && light==0)
    				{
    					cout << "You enter a room that seems devoid of light, you cant see anything\n";
    					cout << "doors are to the east and south\n";
    					lookNum=1;
    					x=1;
    				}
    			if (strcmp(look, "room")==0 && light==1)
    				{
    					cout << "with the light from the flashlight you can see the room.\n";
    					cout << "its not much, just doors are to the east and south\n";
    					cout << "and a heavy metal chest along the wall.\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "keycard")==0) && combo==568)
    				{
    					cout << "Its a keycard, a key in card form\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "flashlight")==0) && roomTWO.flashlight==1)
    				{
    					cout << "Its a flashlight, what more do you want to know?\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "chisel")==0) && roomTWO.chisel==1)
    			{
    				cout << "its a chisel WOOOOO!\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.ring==1 && roomTHREE.jewel!=1)
    			{
    				cout << "its a pretty golden ring with a large jewel in it\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.ring==1 && roomTHREE.jewel==1)
    			{
    				cout << "its a pretty golden ring, the jewel is missing\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "jewel")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a large, shiny jewel\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "key")==0) && roomFOUR.key==1)
    			{
    				cout << "its an old rusty key\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "chest")==0) && light==1 && combo!=568)
    			{
    				cout << "its a heavey metal chest with combination lock on it\n";
    				cout << "it looks like you need three numbers for the combination\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "chest")==0) && light==1 && combo==568)
    			{
    				cout << "its a heavey metal chest with combination lock on it\n";
    				cout << "its open\n";
    				lookNum=1;
    				x=1;
    			}
    			if (strcmp(look, "cancel")==0)
    			{
    				lookNum=1;
    				x=1;
    			}
    			if (x!=1)
    				cout << "you see no such thing\n";
    		
    			}
    		}
    	/////////TAKE////////////	
    	if (strcmp(choice, "take")==0)//if user enters take, enters take sub-loop
    		{
    			while (takeNum!=1)
    			{
    				cout << "what do you want to take? ";
    				cin >> take;
    				cin.ignore(80, '\n');
    				if ((strcmp(take, "keycard")==0) && combo==568)
    				{
    					cout << "you pick up the keycard\n";
    					roomONE.keycard=1;
    					takeNum=1;
    					x=1;
    				}
    				if (strcmp(take, "chest")==0)
    				{
    					cout << "HAHAHAHAHAHAHAHA no\n";
    					takeNum=1;
    					x=1;
    				}
    				if (strcmp(take, "cancel")==0)
    				{
    					takeNum=1;
    					x=1;
    				}
    				if (x!=1)
    					cout << "you dont see that thing to take it\n";
    			}
    		}
    
    	//////USE//////
    	if (strcmp (choice, "use")==0)//use sub-loop
    	{
    		while (useNum!=1)
    		{
    			cout << "what do you want to use?(if you only want to use one item use it with self) ";
    			cin >> item1;
    			cin.ignore(80, '\n');
    			cout << "use " << item1 << " with what? ";
    			cin >> item2;
    			cin.ignore(80, '\n');
    			if (roomTHREE.ring=1 && roomTHREE.jewel!=1 && roomTWO.chisel==1)
    			{
    				if ((strcmp(item1, "ring")==0) && (strcmp(item2, "chisel")==0) || (strcmp(item1, "chisel")==0) && (strcmp(item2, "ring")==0))
    				{
    					cout << "you use the chisel with the ring and pop the jewel out\n";
    					roomTHREE.jewel=1;
    					useNum=1;
    				}
    				else
    				{
    				cout << "nothing happens\n";
    				useNum=1;
    				}
    			}
    			if ((strcmp(item1, "flashlight")==0) && (strcmp(item2, "self")==0) && roomTWO.flashlight==1)
    			{
    				light=1;
    				cout << "you use the flashlight to light up the room.\n";
    				cout << "you can now see a metal chest along the wall\n";
    				useNum=1;
    			}
    			if ((strcmp(item1, "chest")==0) && (strcmp(item2, "self")==0) && light==1)
    			{
    				cout << "Enter the number you think will open the chest ";
    				cin >> combo;
    				cin.ignore(80, '\n');
    				if (combo==568)//if user enters 568, chest opens
    				{
    					cout << "you entered the right number, the chest opens!\n";
    					cout << "theres a keycard inside\n";
    					useNum=1;
    				}
    				else
    				{
    					cout << "WRONG!\n";
    					useNum=1;
    				}
    			}
    		}
    	}//use
    	/////////MOVE/////////
    	if (strcmp (choice, "move")==0)//move sub-loop
    		{
    			while (moveNum!=1)
    				{
    					cout << "where do you want to go? "<< flush;
    					cin >> direction;
    					cin.ignore(80, '\n');
    				switch(direction)//moves user to other rooms
    					{
    					case 'e':
    					case 'E':
    						loop=1;
    						moveNum=1;
    						room2();
    						break;
    
    					case 's':
    					case 'S':
    						loop=1;
    						moveNum=1;
    						room4();
    						break;
    
    					default:
    						cout << "not a choice\n";
    					}//switch
    				}
    		}//move
    	}//loop
    }//room
    
    
    void room2()//function for room2
    {
    	SetConsoleTextAttribute(hOut,
                                FOREGROUND_RED | 
                                FOREGROUND_GREEN |
                                FOREGROUND_INTENSITY);//makes text yellow
    	int loop=0;
    	
    	cout << '\n';//space
    	cout << "there are three ways out of this room.\n";
    	cout << "to the east there is a door with bright light shining through\n";
    	cout << "to the south a strange red glow is coming through the door\n";
    	cout << "the door to the west reveals nothing but blackness.\n";
    	if (roomTWO.flashlight!=1)
    		cout << "there is a flashlight on the floor\n";
    	if (roomTWO.chisel!=1 && roomTHREE.ring==1)//checks that user has ring and didnt use chisel
    	{
    		cout << "as you walk into the room again you trip and fall on your face\n";
    		cout << "struggling to your feet you notice a chisel on the floor\n";
    	}
    		
    	while (loop!=1)
    	{
    	int moveNum=0; 
    	int lookNum=0;
    	int takeNum=0;
    	int useNum=0;
    	int x=0;
    	cout << "what do you want to do? (look, take, use, or move) ";
    	cin >> choice;
    	cin.ignore(80, '\n');
    	/////////LOOK//////////
    	if (strcmp(choice, "look")==0)
    		{
    		while (lookNum!=1)
    			{
    				cout << "look at what? ";
    				cin >> look;
    				cin.ignore(80, '\n');
    			if (strcmp(look, "room")==0)
    				{
    					cout << "there are three ways out of this room.\n";
    					cout << "to the east there is a door with bright light shining through\n";
    					cout << "to the south a strange red glow is coming through the door\n";
    					cout << "the door to the west reveals nothing but blackness.\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "keycard")==0) && roomONE.keycard==1)
    				{
    					cout << "Its a keycard, a key in card form\n";
    					lookNum=1;
    					x=1;
    				}
    			if (strcmp(look, "flashlight")==0)
    				{
    					cout << "Its a flashlight, what more do you want to know?\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "chisel")==0) && roomTWO.chisel==1)
    			{
    				cout << "its a chisel WOOOOO!\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.ring==1 && roomTHREE.jewel!=1)
    			{
    				cout << "its a pretty golden ring with a large jewel in it\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.ring==1 && roomTHREE.jewel==1)
    			{
    				cout << "its a pretty golden ring, the jewel is missing\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "jewel")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a large, shiny jewel\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "key")==0) && roomFOUR.key==1)
    			{
    				cout << "its an old rusty key\n";
    				lookNum=1;
    				x=1;
    			}
    			if (strcmp(look, "cancel")==0)
    			{
    				lookNum=1;
    				x=1;
    			}
    			if (x!=1)
    				cout << "you see no such thing\n";
    		
    			}
    		}
    	/////////TAKE////////////	
    	if (strcmp(choice, "take")==0)
    		{
    			while (takeNum!=1)
    			{
    				cout << "what do you want to take? ";
    				cin >> take;
    				cin.ignore(80, '\n');
    				if ((strcmp(take, "flashlight")==0) && roomTWO.flashlight!=1)
    				{
    					cout << "you pick up the flashlight\n";
    					roomTWO.flashlight=1;
    					takeNum=1;
    					x=1;
    				}
    				if ((strcmp(take, "chisel")==0) && roomTWO.chisel!=1 && roomTHREE.ring==1)
    				{
    					cout << "you pick up the chisel\n";
    					roomTWO.chisel=1;
    					takeNum=1;
    					x=1;
    				}
    				if (strcmp(take, "cancel")==0)
    				{
    					takeNum=1;
    					x=1;
    				}
    				if (x!=1)
    					cout << "you dont see that thing to take it\n";
    			}
    		}
    	////////USE//////////
    	if (strcmp(choice, "use")==0)
    	{
    		while (useNum!=1)
    		{
    			cout << "what do you want to use?(if you only want to use one item use it with self) ";
    			cin >> item1;
    			cin.ignore(80, '\n');
    			cout << "use " << item1 << " with what? ";
    			cin >> item2;
    			cin.ignore(80, '\n');
    			
    			if (roomTHREE.ring==1 && roomTHREE.jewel!=1 && roomTWO.chisel==1)
    			{
    				if ((strcmp(item1, "ring")==0) && (strcmp(item2, "chisel")==0) || (strcmp(item1, "chisel")==0) && (strcmp(item2, "ring")==0))
    				{
    					cout << "you use the chisel with the ring and pop the jewel out\n";
    					roomTHREE.jewel=1;
    					useNum=1;
    				}
    				else
    				{
    				cout << "nothing happens\n";
    				useNum=1;
    				}
    			}
    			else
    			{
    				cout << "nothing happens\n";
    				useNum=1;
    			}
    			
    		}
    	}
    	/////////MOVE/////////
    	if (strcmp (choice, "move")==0)
    		{
    			while (moveNum!=1)
    				{
    					cout << "where do you want to go? "<< flush;
    					cin >> direction;
    					cin.ignore(80, '\n');
    				switch(direction)
    					{
    
    					case 's':
    					case 'S':
    						loop=1;
    						moveNum=1;
    						room5();
    						break;
    
    					case 'e':
    					case 'E':
    						loop=1;
    						moveNum=1;
    						room3();
    						break;
    
    					case 'w':
    					case 'W':
    						loop=1;
    						moveNum=1;
    						room1();
    						break;
    
    					default:
    						cout << "not a choice\n";
    					}//switch
    				}
    		}//move
    	}//while loop!=1
    }
    
    void room3()//function for room 3
    {
    	    SetConsoleTextAttribute(hOut,
                                FOREGROUND_BLUE |
                                FOREGROUND_INTENSITY);//makes text blue
    	int loop=0;
    
    	cout << '\n';
    	cout << "upon entering this room you feel like you're outside.\n";
    	cout << "there are clouds overhead and an ocean before you.\n";
    	cout << "leaning against one of the trees you see a well dressed skeleton.\n";
    	while (loop!=1)
    	{
    	int moveNum=0; 
    	int lookNum=0;
    	int takeNum=0;
    	int useNum=0;
    	int x=0;
    	cout << "what do you want to do? (look, take, use, or move) ";
    	cin >> choice;
    	cin.ignore(80, '\n');
    	/////////LOOK//////////
    	if (strcmp(choice, "look")==0)
    		{
    		while (lookNum!=1)
    			{
    				cout << "look at what? ";
    				cin >> look;
    				cin.ignore(80, '\n');
    			if (strcmp(look, "room")==0)
    				{
    					cout << "upon entering this room you feel like you're outside.\n";
    					cout << "there are clouds overhead and an ocean before you.\n";
    					cout << "leaning against one of the trees you see a well dressed skeleton.\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "keycard")==0) && roomONE.keycard==1)
    				{
    					cout << "Its a keycard, a key in card form\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "flashlight")==0) && roomTWO.flashlight==1)
    				{
    					cout << "Its a flashlight, what more do you want to know?\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "chisel")==0) && roomTWO.chisel==1)
    			{
    				cout << "its a chisel WOOOOO!\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.jewel!=1)
    			{
    				cout << "its a pretty golden ring with a large jewel in it\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a pretty golden ring, the jewel is missing\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "jewel")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a large, shiny jewel\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "key")==0) && roomFOUR.key==1)
    			{
    				cout << "its an old rusty key\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "skeleton")==0) && roomTHREE.ring!=1)
    			{
    				cout << "a well dressed skeleton\n";
    				cout << "he has a very expensive looking ring on his finger with a large jewel\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "skeleton")==0) && roomTHREE.ring==1)
    				{
    					cout << "a well dressed skeleton\n";
    					cout << "his ring finger is broken, looks like someone stole his ring\n";
    					cout << "dirty theives!\n";//shame on you!!
    					lookNum=1;
    					x=1;
    				}
    			if (strcmp(look, "cancel")==0)
    			{
    				lookNum=1;
    				x=1;
    			}
    			if (x!=1)
    				cout << "you see no such thing\n";
    		
    			}
    		}
    	////////TAKE/////////
    	if (strcmp(choice, "take")==0)
    		{
    			while (takeNum!=1)
    			{
    				cout << "what do you want to take? ";
    				cin >> take;
    				cin.ignore(80, '\n');
    				if ((strcmp(take, "ring")==0) && roomTHREE.ring!=1)
    				{
    					cout << "have a little more respect for the dead! hope your ring make you happy!\n";
    					roomTHREE.ring=1;
    					takeNum=1;
    					x=1;
    				}
    				if (strcmp(take, "cancel")==0)
    				{
    					takeNum=1;
    					x=1;
    				}
    				if (x!=1)
    					cout << "you dont see that thing to take it\n";
    			}
    		}
    	////////USE//////////
    	if (strcmp(choice, "use")==0)
    	{
    		while (useNum!=1)
    		{
    			cout << "what do you want to use?(if you only want to use one item use it with self) ";
    			cin >> item1;
    			cin.ignore(80, '\n');
    			cout << "use " << item1 << " with what? ";
    			cin >> item2;
    			cin.ignore(80, '\n');
    			
    			if (roomTHREE.ring==1 && roomTHREE.jewel!=1 && roomTWO.chisel==1)
    			{
    				if ((strcmp(item1, "ring")==0) && (strcmp(item2, "chisel")==0) || (strcmp(item1, "chisel")==0) && (strcmp(item2, "ring")==0))
    				{
    					cout << "you use the chisel with the ring and pop the jewel out\n";
    					roomTHREE.jewel=1;
    					useNum=1;
    				}
    				else
    				{
    				cout << "nothing happens\n";
    				useNum=1;
    				}
    			}
    			else
    			{
    				cout << "nothing happens\n";
    				useNum=1;
    			}
    			
    		}
    	}
    	/////////MOVE/////////
    	if (strcmp (choice, "move")==0)
    		{
    			while (moveNum!=1)
    				{
    					cout << "where do you want to go? "<< flush;
    					cin >> direction;
    					cin.ignore(80, '\n');
    				switch(direction)
    					{
    
    						case 's':
    						case 'S':
    							x=1;
    							room6();
    							break;
    
    						case 'w':
    						case 'W':
    							x=1;
    							room2();
    							break;
    
    						default:
    							cout << "not a choice\n";
    					}//switch
    				}
    		}//move
    	}//loop
    }
    
    void room4()//function for room4
    {
    	    SetConsoleTextAttribute(hOut,
                                FOREGROUND_GREEN |
                                FOREGROUND_INTENSITY);//makes text green
    
    	int box=0;
    	int loop=0;
    	
    	cout << '\n';
    	cout << "there is a pedestal in the center of the room with a small black box on it\n";
    	cout << "there is a dark doorway to the north and a door with a red glow to the east\n";
    		
    	while (loop!=1)
    	{
    	int moveNum=0; 
    	int lookNum=0;
    	int takeNum=0;
    	int useNum=0;
    	int x=0;
    	cout << "what do you want to do? (look, take, use, or move) ";
    	cin >> choice;
    	cin.ignore(80, '\n');
    	/////////LOOK//////////
    	if (strcmp(choice, "look")==0)
    		{
    		while (lookNum!=1)
    			{
    				cout << "look at what? ";
    				cin >> look;
    				cin.ignore(80, '\n');
    			if (strcmp(look, "room")==0)
    				{
    					cout << "there is a pedestal in the center of the room with a small black box on it\n";
    					cout << "there is a dark doorway to the north and a door with a red glow to the east\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "keycard")==0) && roomONE.keycard==1)
    				{
    					cout << "Its a keycard, a key in card form\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "flashlight")==0) && roomTWO.flashlight==1)
    				{
    					cout << "Its a flashlight, what more do you want to know?\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "chisel")==0) && roomTWO.chisel==1)
    			{
    				cout << "its a chisel WOOOOO!\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.jewel!=1)
    			{
    				cout << "its a pretty golden ring with a large jewel in it\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a pretty golden ring, the jewel is missing\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "jewel")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a large, shiny jewel\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "key")==0) && roomFOUR.key==1)
    			{
    				cout << "its an old rusty key\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "key")==0) && box==1)
    			{
    				cout << "its an old rusty key\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "box")==0) && box==0)
    			{
    				cout << "its a black box with a recess on the top\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "box")==0) && box==1)
    			{
    				cout << "its a black box with a recess on the top, its open\n";
    				lookNum=1;
    				x=1;
    			}
    			if (strcmp(look, "cancel")==0)
    			{
    				lookNum=1;
    				x=1;
    			}
    			if (x!=1)
    				cout << "you see no such thing\n";
    		
    			}
    		}
    	////////USE//////////
    	if (strcmp(choice, "use")==0)
    	{
    		while (useNum!=1)
    		{
    			cout << "what do you want to use?(if you only want to use one item use it with 'self') ";
    			cin >> item1;
    			cin.ignore(80, '\n');
    			cout << "use " << item1 << " with what? ";
    			cin >> item2;
    			cin.ignore(80, '\n');
    			
    			if (roomTHREE.jewel==1 && roomFOUR.key!=1)
    			{
    				if ((strcmp(item1, "jewel")==0) && (strcmp(item2, "box")==0) || (strcmp(item1, "box")==0) && (strcmp(item2, "jewel")==0))
    				{
    					cout << "you place the jewel into the recess in the box\n";
    					cout << "it fits in perfectly and the box opens. theres a rusty key inside\n";
    					box=1;
    					useNum=1;
    				}
    				else
    				{
    				cout << "nothing happens\n";
    				useNum=1;
    				}
    			}
    			if (roomTHREE.jewel==1 && roomFOUR.key==1)
    			{
    				if ((strcmp(item1, "jewel")==0) && (strcmp(item2, "box")==0) || (strcmp(item1, "box")==0) && (strcmp(item2, "jewel")==0))
    				{
    					cout << "you place the jewel into the recess in the box\n";
    					cout << "it fits in perfectly and the box opens. its empty\n";
    					box=1;
    					useNum=1;
    				}
    				else
    				{
    				cout << "nothing happens\n";
    				useNum=1;
    				}
    			}
    			if (roomTHREE.ring==1 && roomTHREE.jewel!=1 && roomTWO.chisel==1)
    			{
    				if ((strcmp(item1, "ring")==0) && (strcmp(item2, "chisel")==0) || (strcmp(item1, "chisel")==0) && (strcmp(item2, "ring")==0))
    				{
    					cout << "you use the chisel with the ring and pop the jewel out\n";
    					roomTHREE.jewel=1;
    					useNum=1;
    				}
    				else
    				{
    				cout << "nothing happens\n";
    				useNum=1;
    				}
    			}
    			else
    			{
    				cout << "nothing happens\n";
    				useNum=1;
    			}
    			
    		}
    	}
    	////////TAKE/////////
    	if (strcmp(choice, "take")==0)
    		{
    			while (takeNum!=1)
    			{
    				cout << "what do you want to take? ";
    				cin >> take;
    				cin.ignore(80, '\n');
    				if ((strcmp(take, "key")==0) && roomFOUR.key!=1 && box==1)
    				{
    					cout << "you got yourself a old, rusty key\n";
    					roomFOUR.key=1;
    					takeNum=1;
    					x=1;
    				}
    				if (strcmp(take, "box")==0)
    				{
    					cout << "its bolted to the pedestal\n";
    					takeNum=1;
    					x=1;
    				}
    				if (strcmp(take, "cancel")==0)
    				{
    					takeNum=1;
    					x=1;
    				}
    				if (x!=1)
    					cout << "you dont see that thing to take it\n";
    			}
    		}
    /////////MOVE/////////
    	if (strcmp (choice, "move")==0)
    		{
    			while (moveNum!=1)//same
    				{
    					cout << "where do you want to go? " << flush;
    					cin >> direction;
    
    					switch(direction)
    						{
    							case 'e':
    							case 'E':
    								loop=1;
    								moveNum=1;
    								room5();
    								break;
    
    							case 'n':
    							case 'N':
    								loop=1;
    								moveNum=1;
    								room1();
    								break;
    
    							default:
    								cout << "not a choice\n";
    						}
    				}
    		}//move
    	}//loop
    }
    
    int room5()//function for room5
    {
    	    SetConsoleTextAttribute(hOut,
                                FOREGROUND_RED |
                                FOREGROUND_INTENSITY);//makes text red
    	int loop=0;
    
    	cout << '\n';
    	cout << "there is a large security door to the south, there is a place to enter a key card\n";
    	cout << "the security door is surrounded by red lights lighting up the whole room an eery red\n";
    	cout << "there are open doors to the east, west, and north\n";
    	while (loop!=1)
    	{
    	int moveNum=0; 
    	int lookNum=0;
    	int takeNum=0;
    	int useNum=0;
    	int x=0;
    	cout << "what do you want to do? (look, take, use, or move) ";
    	cin >> choice;
    	cin.ignore(80, '\n');
    	/////////LOOK//////////
    	if (strcmp(choice, "look")==0)
    		{
    		while (lookNum!=1)
    			{
    				cout << "look at what? ";
    				cin >> look;
    				cin.ignore(80, '\n');
    			if (strcmp(look, "room")==0)
    				{
    					cout << "there is a large security door to the south, there is a place to enter a key card\n";
    					cout << "the security door is surrounded by red lights lighting up the whole room an eery red\n";
    					cout << "there are open doors to the east, west, and north\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "keycard")==0) && roomONE.keycard==1)
    				{
    					cout << "Its a keycard, a key in card form\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "flashlight")==0) && roomTWO.flashlight==1)
    				{
    					cout << "Its a flashlight, what more do you want to know?\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "chisel")==0) && roomTWO.chisel==1)
    			{
    				cout << "its a chisel WOOOOO!\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.jewel!=1)
    			{
    				cout << "its a pretty golden ring with a large jewel in it\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a pretty golden ring, the jewel is missing\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "jewel")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a large, shiny jewel\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "key")==0) && roomFOUR.key==1)
    			{
    				cout << "its an old rusty key\n";
    				lookNum=1;
    				x=1;
    			}
    			if (strcmp(look, "door")==0)
    			{
    				cout << "its a large security door with a keycard reader built in.\n";
    				cout << "the bright red lights tell you that its locked\n";
    				lookNum=1;
    				x=1;
    			}
    			if (strcmp(look, "cancel")==0)
    			{
    				lookNum=1;
    				x=1;
    			}
    			if (x!=1)
    				cout << "you see no such thing\n";
    		
    			}
    		}
    		////////USE//////////
    	if (strcmp(choice, "use")==0)
    	{
    		while (useNum!=1)
    		{
    			cout << "what do you want to use?(if you only want to use one item use it with 'self') ";
    			cin >> item1;
    			cin.ignore(80, '\n');
    			cout << "use " << item1 << " with what? ";
    			cin >> item2;
    			cin.ignore(80, '\n');
    			
    			if (roomTHREE.ring==1 && roomTHREE.jewel!=1 && roomTWO.chisel==1)
    			{
    				if ((strcmp(item1, "ring")==0) && (strcmp(item2, "chisel")==0) || (strcmp(item1, "chisel")==0) && (strcmp(item2, "ring")==0))
    				{
    					cout << "you use the chisel with the ring and pop the jewel out\n";
    					roomTHREE.jewel=1;
    					useNum=1;
    				}
    				else
    				{
    				cout << "nothing happens\n";
    				useNum=1;
    				}
    			}
    			if (roomONE.keycard==1)
    			{
    				if ((strcmp(item1, "keycard")==0) && (strcmp(item2, "door")==0) || (strcmp(item1, "door")==0) && (strcmp(item2, "keycard")==0))
    				{
    					cout << "the lights turn green and the door slides back into the wall\n";
    					cout << "beyond the door is freedom! you have won!\n";
    					cout << "I must conradulate you, you have solved the adventure \n";
    					cout << "do not relax just yet tho....\n";
    					cout << "for the freedom you just earned is soon to be lost for upon exiting this\n";
    					cout << "room the door slams behind you and you find yourself in another room with\n";
    					cout << "what seems to be another adventure, much like the last but harder,\n";
    					cout << "streched out before you. yours is a never ending quest for freedom!\n";
    					return 0;
    				}
    			}
    		}
    	}
    	////////TAKE/////////
    	if (strcmp(choice, "take")==0)
    		{
    			while (takeNum!=1)
    			{
    				cout << "what do you want to take? ";
    				cin >> take;
    				cin.ignore(80, '\n');
    				
    				if (strcmp(take, "cancel")==0)
    				{
    					takeNum=1;
    					x=1;
    				}
    				if (x!=1)
    					cout << "you dont see that thing to take it\n";
    			}
    		}
    	/////////MOVE/////////
    	if (strcmp (choice, "move")==0)
    		{
    			while (moveNum!=1)//same
    				{
    					cout << "where do you want to go? " << flush;
    					cin >> direction;
    					switch(direction)
    						{
    							case 'e':
    							case 'E':
    								moveNum=1;
    								loop=1;
    								room6();
    								break;
    
    							case 'n':
    							case 'N':
    								moveNum=1;
    								loop=1;
    								room2();
    								break;
    
    							case 'w':
    							case 'W':
    								moveNum=1;
    								loop=1;
    								room4();
    								break;
    
    								default:
    									cout << "not a choice\n";
    						}
    				}
    		}//move
    	}
    }
    
    void room6()
    {
    	    SetConsoleTextAttribute(hOut,
                                FOREGROUND_RED | 
                                FOREGROUND_GREEN | 
                                FOREGROUND_BLUE |
                                FOREGROUND_INTENSITY);//makes text white
    	int drawer=0;
    	int loop=0;
    
    	cout << '\n';
    	cout << "nothing unusual about this room, doors to the north and west\n";
    	cout << "theres a desk against the wall\n";
    	while (loop!=1)
    	{
    	int moveNum=0; 
    	int lookNum=0;
    	int takeNum=0;
    	int useNum=0;
    	int x=0;
    	cout << "what do you want to do? (look, take, use, or move) ";
    	cin >> choice;
    	cin.ignore(80, '\n');
    	/////////LOOK//////////
    	if (strcmp(choice, "look")==0)
    		{
    		while (lookNum!=1)
    			{
    				cout << "look at what? ";
    				cin >> look;
    				cin.ignore(80, '\n');
    			if (strcmp(look, "room")==0)
    				{
    					cout << "nothing unusual about this room, doors to the north and west\n";
    					cout << "theres a desk against the wall\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "keycard")==0) && roomONE.keycard==1)
    				{
    					cout << "Its a keycard, a key in card form\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "flashlight")==0) && roomTWO.flashlight==1)
    				{
    					cout << "Its a flashlight, what more do you want to know?\n";
    					lookNum=1;
    					x=1;
    				}
    			if ((strcmp(look, "chisel")==0) && roomTWO.chisel==1)
    			{
    				cout << "its a chisel WOOOOO!\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.jewel!=1)
    			{
    				cout << "its a pretty golden ring with a large jewel in it\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "ring")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a pretty golden ring, the jewel is missing\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "jewel")==0) && roomTHREE.jewel==1)
    			{
    				cout << "its a large, shiny jewel\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "key")==0) && roomFOUR.key==1)
    			{
    				cout << "its an old rusty key\n";
    				lookNum=1;
    				x=1;
    			}
    			if (strcmp(look, "desk")==0)
    			{
    				cout << "a wooden desk against the wall\n";
    				lookNum=1;
    				x=1;
    			}
    			if ((strcmp(look, "paper")==0) && drawer==1)
    			{
    				cout << "its a piece of paper that says '568', wonder what that means\n";
    				lookNum=1;
    				x=1;
    			}
    			if (strcmp(look, "cancel")==0)
    			{
    				lookNum=1;
    				x=1;
    			}
    			if (x!=1)
    				cout << "you see no such thing\n";
    		
    			}
    		}//look
    		////////USE//////////
    		if (strcmp(choice, "use")==0)
    		{
    			while (useNum!=1)
    			{
    				cout << "what do you want to use?(if you only want to use one item use it with 'self') ";
    				cin >> item1;
    				cin.ignore(80, '\n');
    				cout << "use " << item1 << " with what? ";
    				cin >> item2;
    				cin.ignore(80, '\n');
    			
    				if (roomFOUR.key==1)
    				{
    					if ((strcmp(item1, "key")==0) && (strcmp(item2, "desk")==0) || (strcmp(item1, "desk")==0) && (strcmp(item2, "key")==0))
    					{
    						cout << "you use the key to unlock a drawer in the desk\n";
    						cout << "it opens and you see a piece of paper inside\n";
    						drawer=1;
    						useNum=1;
    					}
    					else
    					{
    					cout << "nothing happens\n";
    					useNum=1;
    					}
    				}
    				if (roomTHREE.ring==1 && roomTHREE.jewel!=1 && roomTWO.chisel==1)
    				{
    				if ((strcmp(item1, "ring")==0) && (strcmp(item2, "chisel")==0) || (strcmp(item1, "chisel")==0) && (strcmp(item2, "ring")==0))
    				{
    					cout << "you use the chisel with the ring and pop the jewel out\n";
    					roomTHREE.jewel=1;
    					useNum=1;
    				}
    				else
    				{
    				cout << "nothing happens\n";
    				useNum=1;
    				}
    			}
    				else
    				{	
    					cout << "nothing happens\n";
    					useNum=1;
    				}
    			
    			}
    		}
    	////////TAKE/////////
    	if (strcmp(choice, "take")==0)
    		{
    			while (takeNum!=1)
    			{
    				cout << "what do you want to take? ";
    				cin >> take;
    				cin.ignore(80, '\n');
    				if ((strcmp(take, "paper")==0) && drawer==1)
    				{
    					cout << "you cant take it, its glued to the bottom of the drawer\n";
    					takeNum=1;
    					x=1;
    				}
    				if (strcmp(take, "desk")==0)
    				{
    					cout << "oh what a big man you must be, wanting to pick up the whole desk\n";
    					takeNum=1;
    					x=1;
    				}
    				if (strcmp(take, "cancel")==0)
    				{
    					takeNum=1;
    					x=1;
    				}
    				if (x!=1)
    					cout << "you dont see that thing to take it\n";
    			}
    		}
    	/////////MOVE/////////
    	if (strcmp (choice, "move")==0)
    		{
    			while(moveNum!=1)
    				{
    					cout << "where do you want to go? ";
    					cin >> direction;
    					switch(direction)
    						{
    							case 'n':
    							case 'N':
    								loop=1;
    								moveNum=1;
    								room3();
    							break;
    
    							case 'w':
    							case 'W':
    								loop=1;
    								moveNum=1;
    								room5();
    							break;
    
    							default:
    								cout << "not a choice\n";
    						}
    				}
    		}//move
    	}//loop
    }

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    One thing...I wasn't able to compile it because of the first two lines. It needs to be
    Code:
    #include <iostream>//needed for printouts
    #include <string>//needed to compare strings
    #include <windows.h>//used for text colors
    
    using namespace std;

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    <string> is for the string container object. <cstring> is for the C-style NULL-terminated character array related function prototypes such as strcmp. The OP doesn't appear to be using C++ string containers anywhere (though probably should) but does appear to be using the strcmp function. I'd pick <cstring> over <string>.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 05:13 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. Replies: 3
    Last Post: 05-25-2005, 01:50 PM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM