Few things...

This is a discussion on Few things... within the A Brief History of Cprogramming.com forums, part of the Community Boards category; ok i am a new C++ dos program, and i am very intertesed in persuiong at it more. I take ...

  1. #1
    LouDu
    Guest

    Few things...

    ok i am a new C++ dos program, and i am very intertesed in persuiong at it more. I take a class in schoola nd work at my house, and read books about programing, and am starting to build my own TEXT RPG, i am not having to many problems yet, but i jsut encouintered one.

    For example you playing the game and exploring aound, and i want to have it so say for exampke at ANY time you hit 'kkkkkkkkkkkkkkkkkkkkkkkkkk' and hit <enter> a map of the town were you are comes up and fromt aht you can cchoose were to go useing if else statements how do you do it so the menu can popup at any time? thats is my question. Thanks alot all

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You poll for command strings:
    Code:
    // disclaimer: pseudocode may cause cancer
    
    while ( true ) { // Game loop type deal
      if ( kbhit() ) {
        cmd_str = get_cmd_str();
        process ( cmd_str );
      }
    }
    kbhit() is often placed in the conio.h header, but since it isn't a standard header it may be somewhere else.

    -Prelude
    My best code is written with the delete key.

  3. #3
    loudu
    Guest
    thanks alot, bnut as a i said i'm a major newb lol and i dont really understand to mcuh can you elaborate

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    > i dont really understand to mcuh can you elaborate
    There is nothing complicated in the code I gave you, perhaps you should start working with something easier than a game.

    -Prelude
    My best code is written with the delete key.

  5. #5
    LouDu
    Guest
    can you elaborate on the code and help me understand it more...?

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >can you elaborate on the code and help me understand it more...?
    It loops forever, checks to see if a key on the keyboard was hit, then processes input if it was.

    -Prelude
    My best code is written with the delete key.

  7. #7
    |<o>| <--cyclopse LouDu's Avatar
    Join Date
    Mar 2003
    Posts
    137
    i may sound like a broken record, but i'm so lost.


    this is what i know:

    i know basic cin cout statements, if else staements intergers, chars, floats, do while staements, and a few other little things and i am trying to work wiht what i haveso if i have no idea what you are talking about
    Languages <> C++, HTML

    /*The Ledgend of Ludlow Coming to a PC Near
    You intro Cinenmatic Needed email me of
    Reply to one of my threads if you can make
    one, thats decent. */

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    This uses what you've learned so far:
    Code:
    #include <iostream>
    #include <conio.h>
    
    int main()
    {
      do {
        if ( kbhit() ) { // If a key is hit
          int cmd;
    
          if ( std::cin>> cmd ) // Read an integer
            // If cin succeeds, print it
            std::cout<<"You entered: "<< cmd <<std::endl;
        }
      } while ( true ); // Loop forever, condition always true
    }
    -Prelude
    My best code is written with the delete key.

  9. #9
    |<o>| <--cyclopse LouDu's Avatar
    Join Date
    Mar 2003
    Posts
    137
    thanks alot any other tips or suggestions for gettign started making a text rpg i would greatly appericate thanks again

  10. #10
    |<o>| <--cyclopse LouDu's Avatar
    Join Date
    Mar 2003
    Posts
    137
    Ok i implemented the code, and well its not what i am looking for, or i am doing something wrong this is what i have..

    Code:
    #include <iostream>
    #include <conio.h>
    #include <iomanip.h>
    
    
    int cmd;
    
    
    int main()
    {
    
            cout << "hello world..... " ;
    
            do {
            if ( kbhit() )
    
            {
            if ( std::cin>> cmd )
            std::cout<< "blah blah blah " << cmd <<std::endl;
            }
    
            } while ( true );
    }
    Languages <> C++, HTML

    /*The Ledgend of Ludlow Coming to a PC Near
    You intro Cinenmatic Needed email me of
    Reply to one of my threads if you can make
    one, thats decent. */

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    73

    Lightbulb

    Yeah, I know this is an old message an you probably figured it out, but if you didn't.. you could use "getch()" or "getche()"

    getch() = get character
    getche() = same but echo's it back to the screen.

    Syntax goes something like this:
    Code:
    #include <conio.h> //I'm pretty sure it's in this header.
    #include <stdlib.h> //this is for the system command and printf
    
    int main()
    {
      char variable;   //defines variable as type character
      variable = getch();  //get character and throw it into variable
      printf("%c\n",variable); //prints it out (also can be done with cout)
      
      system("PAUSE");  //press any key 
      return 0;  //exit
    }
    Using this you can have it set with if statements and loops so that when someone enters a "k" display the map.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Suggestions for things to study
    By Mastadex in forum Windows Programming
    Replies: 5
    Last Post: 08-18-2008, 10:23 AM
  2. Plants that eat things
    By StinkyRyan in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 07-05-2004, 04:41 PM
  3. How are things looking
    By cyberCLoWn in forum C++ Programming
    Replies: 8
    Last Post: 01-15-2004, 02:53 PM
  4. Selecting things on the canvas
    By Barjor in forum Windows Programming
    Replies: 0
    Last Post: 08-30-2001, 03:10 PM
  5. Help with these three things...
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 08-26-2001, 08:05 AM

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