Thread: makin progress

  1. #16
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    {
        string whattheytype;
        string whattheytype2;
        string Commands[] = {"theory", "exit", "game", "commands", "start"}; 
     // these match the index of Commands[]
        #define THEORY 0 // must be the index value from Commands[]
        #define EXIT 1
        #define GAME 2
        #define COMMANDS 2
        #define START 4
    
        //exits loop when they type the EXIT command
        while (whattheytype != Commands[EXIT])  
        {
            std::cin>>whattheytype;
            if (whattheytype == Commands[COMMANDS]) 
            {
                 functionCommands()
            }
            else 
            if (whattheytype == Commands[GAME]) 
            {
                functionGame()
            }
            else 
            if (whattheytype == Commands[THEORY]) 
            {
                functionTheory()
            }
            else 
            if (whattheytype == Commands[START]) 
            {
                 functionStartGame()
            }
            else 
            {
                std::cout<<"I dont understand your command\n";                       
            }
        }
        std::cout<<"goodbye\n";
        cin.ignore();
        cin.getline();
        return 0;
    }

    Now take all your other code and place it in functions. Makes your main routine easier to manage.

    Using the Commands[] array allows you to add commands as you need them.

    The #defines that follow make the if() statements easier to read. And if you change the command string you won't have to change it in many places. For example, if you want to change theory to help, all you need to change is the value in Commands[]. It will still be referenced by the THEORY define so your code stays intact.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  2. #17
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    do you mean like this?

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(void)
    {
        string whattheytype;
        string whattheytype2;
        string Commands[] = {"theory", "exit", "game", "commands", "start"}; 
     // these match the index of Commands[]
        #define THEORY 0 // must be the index value from Commands[]
        #define EXIT 1
        #define GAME 2
        #define COMMANDS 2
        #define START 4
    
        {
        std::cout<<"this game was ripped off from the choose your own adventure\n";
        
    std::cout<<" book called Undergound Kingdom by  Edward Packard\n";
        
    std::cout<<"ok this is a choose your own adventure game called\n";
        
    std::cout<<"Underground kingdom. you will read the page then you will be\n";
       
     std::cout<<"asked to choose which way you want to go and such\n";
        
    std::cout<<"sounds like fun huh? thought so. ok type commands to\n";
        
    std::cout<<"get a list of commands. and type exit to leave";/* all this is is the introductory for the game*/
        
    std::cout<<"\ntype start to start the game!\n"<<endl;
        
    std::cin>>whattheytype;/* beginning commands*/
        }
        
        //exits loop when they type the EXIT command
        
    while (whattheytype != Commands[EXIT])  
        {
            
    std::cin>>whattheytype;
     if (whattheytype == Commands[COMMANDS]) 
            
    {
           
     std::cout<<"the commands are exit and start\n"<<endl;/*insructions*/
    std::cin>>whattheytype;        }
            
    else 
    if (whattheytype == Commands[GAME]) 
            
    {
              
    std::cout << "Game goes here\n";
    system("pause");
           
     }
            
    else 
     if (whattheytype == Commands[THEORY]) 
            {
                
    std::cout<<"                         PROFESSOR\n";
                std::cout<<"                         BRUCKNER'S\n";
                std::cout<<"                           THEORY\n";
                std::cout<<"---------------------------------------------------------------\n";
               
     std::cout<<"The discovery of the Bottomless Crevasse in Greenland by Dr. Nera \n";
                
    std::cout<<"Vivaldi supports my therory that the earth is not solid, as has\n";
                
    std::cout<<"been thought, but that it is hollow.  The Bottomless Crevasse is\n";
                
    std::cout<<"probably the sole route from the earth's surface to a vast Underground\n";
                
    std::cout<<"Kingdom.  The only other possible link would be an underground river,\n";
               
     std::cout<<"flowing in alternating directions in response to the tides, but this \n";
                
    std::cout<<"seems unlikely.\n";
                
    std::cout<<"How you may ask, was the earth hollowed out?  My studies show that more\n";
                
    std::cout<<"than a billion years ago a tiny blck hole collided with out planet and\n";
                
    std::cout<<"lodged in its center, pulling the whole molten core into an incredibly\n";
                
    std::cout<<"massive sphere only a few hundred meter across.\n";
                
    std::cout<<"If you were to stand on the inner surface of the earth, like a fly on the\n";
                
    std::cout<<"shell of an enormous pumpkin, you would see the black hole directly overhead,\n";
                
    std::cout<<"press any key and hit enter for more of the theory\n";
                
    system("pause");
                
    std::cout<<"like a black sun.\n";
                
    std::cout<<"The Gravity of the earth's thick shell would hold you to the inner shell\n";
                
    std::cout<<"of the earth, though you would weigh much less than you would on the\n";
                
    std::cout<<"outer surface because the mass of the Black Sun would tend to pull \n";
                
    std::cout<<"you toward it. If there were a very tall mountain in the Underground\n";
                
    std::cout<<"Kingdom and you were to climb to the top of it, you might be pulled\n";
                
    std::cout<<"up into the Black Sun because gravity gets stronger as you approach\n";
                
    std::cout<<"a massive object.\n";
                
    std::cout<<"In all other respects the Black Sun would not be dangerous to any creatures\n";
                
    std::cout<<"in the Unerground Kingdom.  On the contrary, the Black Sun would be\n";
                
    std::cout<<"necessary to life in the underworld, but in the opposit way that the sun is\n";
                
    std::cout<<"necessary to life on the earth's surface.  Our sun give us heat and keeps us\n";
                
    std::cout<<"from freezing.  The Black Sun absorbs heat.  If there is an underground \n";
                
    std::cout<<"kingdom, it is the Black Sun that keep its inhabitants from being baked to\n";
                
    std::cout<<"death by the heat within the earth.\n";
                
    std::cout<<"type game to start the game\n";
                
    std::cin>>whattheytype2;
           
     }
            
    else 
           
     if (whattheytype == Commands[START]) 
            {
    std::cout<<"WARNING!!!!!!!!!!!!!\n";
       
     std::cout<<"\n";
        
    std::cout<<"The Underground Kingdom is not easy to reach. Many Players\n";
        
    std::cout<<"never get ther. Others never return.\n";
       
     std::cout<<"    Before starting out on your journey, you may want to read\n";
        
    std::cout<<"Professor Bruckner's theory, which is set fourth on the next block\n";
        
    std::cout<<"of text.\n";
        
    std::cout<<"    Professor Bruckner is a rather boring writer, and i wouldn't\n";
        
    std::cout<<"suggest that you bother read his theory exept that, if you ever\n";
        
    std::cout<<"get to the Underground Kingdom, it might save your life. Good luck!\n"<<endl;
        
    std::cout<<"type theory to read the theory type game to start the game\n";  
        
    std::cin>>whattheytype2;
            }
            else 
            {
                
    std::cout<<"I dont understand your command\n";                       
            }
        }
        
    std::cout<<"goodbye\n";
        cin.ignore();
        cin.getline();
        return 0;
    }
    Formatting fixed by moderator
    Last edited by sreetvert83; 01-17-2004 at 06:15 PM.

  3. #18
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    No one helping you, huh? While waiting, you coud learn how to use code tags properly, how to use preview button before you post, and how to edit your post. That's what might keep people away from helping you.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  4. #19
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    What part of
    Now take all your other code and place it in functions. Makes your main routine easier to manage.
    do you not understand?

    And what part of the blue and green text below is beyond your knowledge?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  5. #20
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    well there is purple there also lol and i dont understand what putting it in functions is ill read up on it tho

  6. #21
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    If you don't know functions you seriously need to learn more. It is almost impossible to write a good text based RPG if you don't use functions, without them it causes great difficulty.

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  7. #22
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by sreetvert83
    well there is purple there also lol and i dont understand what putting it in functions is ill read up on it tho
    Yes, there is purple too. But if you don't understand the blue and green, I know that the purple is a lost cause

    Definitely read up on functions. They are indespensible in any language.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Displaying Progress.
    By samus250 in forum C Programming
    Replies: 15
    Last Post: 04-11-2008, 03:56 PM
  2. Creating a progress window
    By Xzyx987X in forum Windows Programming
    Replies: 6
    Last Post: 10-06-2004, 04:02 PM
  3. progress bar newbie
    By WaterNut in forum Windows Programming
    Replies: 18
    Last Post: 08-09-2004, 01:42 PM
  4. Scaling Progress Steps :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2002, 03:30 PM
  5. Progress Bars
    By knight543 in forum Windows Programming
    Replies: 1
    Last Post: 08-21-2002, 10:45 AM