Making text adventures (begginer)

This is a discussion on Making text adventures (begginer) within the C++ Programming forums, part of the General Programming Boards category; I am a real begginer programming in Visual C++ 6.0. I want to make a text adventure game and I ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    249

    Cool Making text adventures (begginer)

    I am a real begginer programming in Visual C++ 6.0.

    I want to make a text adventure game and I don't know how to start. Knowing me and my types of questions, it's probably some really easy solution ...but here's the only code I have to give you an idea of what I want to do:

    #include <iostream.h>
    int main()
    {
    char direction;
    cout<<"Type 'right', 'left', 'up', or 'down' to move";
    cin>>direction;
    if (direction == "right")
    //?
    cout<<"You moved right";
    return 0;
    }


    I want it so that when the user types "right" it will displaly "You moved right". If the user types "Left" if will display "You moved left" ...etc.

    Thanks,

    Funky

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    here is a possible solution

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main(void)
    {
        char c;
    
        cout<<"Type 'right', 'left', 'up', or 'down' to move"; 
       // Use whatever method you need to get the keys
       // getch is just a function that gets the arrow keys so i use it here
        c = getch();
        if(c == 'M') // Right Arrow Key
            cout<<"You moved right"; 
        if(c == 'K') // Left Arrow Key
            cout<<"You moved left"; 
        if(c == 'H') // Up Arrow Key
            cout<<"You moved up"; 
        if(c == 'P') // Down Arrow Key
            cout<<"You moved down"; 
        return 0;
    }
    please note that getch functions differently on different compilers so you may need to find an alternate input method. but it should work as needed here in MSVC.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Im trying to make a text RPG too.
    And i'm wondering... how would i do to make a "Press enter to continue"?
    If u just use cin >> on a char you first have to enter a letter for anything to happen.

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    well once again this is a compiler dependant thing but most of the time it can be solved like so, this works with MSVC by the way.

    Code:
    #include <conio.h>
    #include <iostream.h>
    
    void pause(void)
    {
        cout << "Press any key to continue." << endl;
        while(!_kbhit())
            ;
        getch();	// clear the key from the input
    }
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Unregistered
    Guest
    you may need to look into character arrays (strings), although you might be able to code around their use.

    i also like the switch statement
    it only uses integers, BUT characters are converted to integers using the ascii code so they also work


    to pause you COULD use system("pause") which will display a pause messege, something like "Press any key to continue", and waits for any key to be pressed.
    OR use cin.get(character) in a loop until enter (\n) is recieved

    *note* cin >> recieves input upto the first whitespace character, thus that whitespace chacter has a way of causing annoying problems. So, when changing from input with cin >> to cin.get, you may need to remove the space or return character happily waiting to ruin your input. cin.ignore() will "ignore" the next character, and cin.ignore(x) will "ignore" the next x number of integers

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    grrr i AM registered!!! Login problems :/

    anyway, yes kbhit() is another way of creating a pause
    But as you said, it's compiler dependent. I tried it once and it didnt seem to work properly for me (MSVC++ 6.0). I'm sure the problem was i coded it wrong *shrug*

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    About the original problem:

    Code:
    char dir[9];
    cin >> dir;
    if(strcmp(dir, "left"))
        move left
    kooma - t.h@iki.fi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A begginer writing a text based dungeon game.
    By deadherorising in forum C Programming
    Replies: 55
    Last Post: 11-10-2007, 05:16 PM
  2. Making text scroll downwards
    By DevEight in forum C++ Programming
    Replies: 1
    Last Post: 10-23-2007, 05:23 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  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
  5. Making a text editor
    By neandrake in forum C++ Programming
    Replies: 5
    Last Post: 02-26-2002, 10:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21