rpg ?'s

This is a discussion on rpg ?'s within the Game Programming forums, part of the General Programming Boards category; I'm making a MUD. Code: #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { char namen[100]; ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    465

    Question rpg ?'s

    I'm making a MUD.
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        char namen[100];
        int initial;
        
        cout<<"1.New game\n2.Load game\n3.Exit\n";
        cin>>initial;
        switch (initial){
        case 1:
        cout<<"                        Welcome to naushmien\n\n*Dramatic Music*\n\nPlease enter your name:";
        cin.getline(namen,100,'\n');
        cout<<namen<<" is it, alright then!";
        break;
        case 2:
        cout<<"Not availiable yet.";
        break;
        case 3:
        return 0;
        break;
        case 4:
        cout<<"n/a";
        break;
        default:
        cout<<"Unexpected error";
        }
    
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }

    Code:
        case 1:
        cout<<"                        Welcome to naushmien\n\n*Dramatic Music*\n\nPlease enter your name:";
        cin.getline(namen,100,'\n');
        cout<<namen<<" is it, alright then!";
        break;
    I can't get it to stop for the user to input their name. It skips directly to the end of the switch statment after it displays that. I still don't see how you can make the program interpret the saved game file.
    In the "RPG" post I asked how you could make a shop keeper give a random response without having to generate random numbers. I don't have any clue how to make monsters encounters random.
    Could you guys please clear some of this up for me?
    My computer is awesome.

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    In the "RPG" post I asked how you could make a shop keeper give a random response without having to generate random numbers. I don't have any clue how to make monsters encounters random.
    Could you guys please clear some of this up for me?
    If you want to actually make it a random mechanism, you're going to have to use random numbers. What is your problem with using random numbers? The only other way I can think of to simulate this behavior is to cycle through an array of strings containing greetings. It wouldn't be random (the sequence would be repetitive), but you would get a variety of greetings. The same goes for monster encounters, unless there's some other unique timing point in your program at which you could initiate a "monster encounter".

    I still don't see how you can make the program interpret the saved game file.
    Care to elaborate?

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Unless I'm missing something wouldn't you have to generate a massive amount of random numbers to keep the shop keepers response random not to mention the huge switch statement. You can only generate random numbers at the beginning of the program right?
    About loading is there some command like if file says? or contains?


    How would you make the program respond to keys through the entire thing so you can save whenever you want?
    What I would really like right now though is help with the code I posted and I can address the other problems later.
    My computer is awesome.

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    1
    Hey now, I'm completely new to C++ (after finally finding a compiler that works with my pc) but back in the day I used Python.

    I don't know if there is any equivalent in cpp (like I said, I'm new) but in Python at least they have something called modules that contains a list of variables or functions and can be easily invoked with a command (and I dont recall the commands used, sorry)

    So perhaps your save system could use something along these lines?

    (Python's help file to get an idea of what I'm talking about: http://www.python.org/doc/2.3.5/tut/node8.html )

    Also, I have a friend at school who was making a game where he used Microsoft Access to create databases that he could then use c++to access.

    Sorry for bothering anyone; just throwing out ideas ^-^;;

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    >>Also, I have a friend at school who was making a game where he used Microsoft Access to create databases

    XML is also a good idea.

    >>About loading is there some command like if file says? or contains?

    strstr() ?

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You can only generate random numbers at the beginning of the program right?
    No. You have to seed the random number generator at the beginning of your program, and do this ONCE (srand()). You can then use this to get random numbers whenever you want using rand(). Just use one variable and assign it a new time-based random value every time you need one.

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Just use one variable and assign it a new time-based random value every time you need one.
    Heh Heh I'm not exactly sure how to do that, but I did google and found some useful looking code sorry for the >'s.
    Code:
    > const int N = 4;
    > srand((unsigned)time(NULL)+minute);
    > numArrivals = (rand() % N);
    >
    > switch(numArrivals)
    > {
    > case 0:
    > case 3: break;
    > case 1: custQ.enqueue(minute); break;
    > case 2: custQ.enqueue(minute); custQ.enqueue(minute); break;
    I was thinking about writing it to a text file. Where can I store the saved game data without it dissappearing when you exit the game?
    I still can't get my code from my first post to work how its supposed to.
    My computer is awesome.

  8. #8
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Heh I guess I forgot to tell you what is wrong with my code. I doesn't let you input your name it just goes to the next bit of code.
    My computer is awesome.

  9. #9
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    I still have the same problem with that first bit of code, but I have another question.
    It is about how combat would work. In order to keep the amount you hit on a monster and vice versu random you would have have one or more variable that change each time. My quesiton is what would those variables be?
    My computer is awesome.

  10. #10
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154
    Sorry for butting in, but here's how I would do it:

    Code:
     int x = rand()%256; 
    if(x < 32) string="Hello";
    else if(x < 64) string="How are you";
    Etc, Etc.

    Let me know if this helps.

    Plus, shouln't you be using cin instead of cin.getline?

  11. #11
    email for MystWind avatar MystWind's Avatar
    Join Date
    Feb 2005
    Location
    Holland , The Hague
    Posts
    88
    yes kawk i think your right about that cin instead of get line , but that piece of code you written down there : I suspect it will only pick a random number once , then NOT EVER change it back again , thats how it works with the rand() code. to be honest I think rand is ussless because int x ; cout << x ; would do Xactly the same; pick a number random then not ever change it.
    PLay MystWind beta , within two years

  12. #12
    email for MystWind avatar MystWind's Avatar
    Join Date
    Feb 2005
    Location
    Holland , The Hague
    Posts
    88

    Red face my code

    however hmm maybe my chat programm will help some :


    Code:
    #include <iostream>
    using namespace std ;
    #include <string>
    #include <windows.h>
    
    
    int main ( int , char** )
    {
    unsigned char x = 4 ;
    char pname[64] ;
    unsigned char z = 0 ;
    unsigned char a = 2;
    char says[64] ;
    
    
    // --------------------colour-----------------------//
    
    //( removed this for the Xample to make it more simple )//
    //-------------ask for username-------------------//
    Sleep (  x ) ;
    cout << endl << "username: " ;
    
    if ( pname != 0 ) {
    
      gets(pname);  
      
    //-------------------chat-----------------------//
    string message;
    
    while ( true ) { 
         cout << endl ;
        getline(cin,message);
        if( !message.length() ) break;
        cout  << pname << " says : " << message << endl;
    }
    
    
    //-----------when out of chat loop------------//
    cin.ignore();
    
    return 0 ;
    
    }
    }
    PLay MystWind beta , within two years

  13. #13
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    No Mystwind actually earlier in this post somebody said that I can generate random numbers throughout the life of the program. I have yet to figure out how to do that.
    My computer is awesome.

  14. #14
    email for MystWind avatar MystWind's Avatar
    Join Date
    Feb 2005
    Location
    Holland , The Hague
    Posts
    88
    alright then good luck with your MUD.
    PLay MystWind beta , within two years

  15. #15
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    Hello.

    Forgive me for bieng wierd , but what does MUD stand for ?

    I can't quite work it out.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem
    By ExDHaos in forum C++ Programming
    Replies: 12
    Last Post: 05-22-2009, 04:50 AM
  2. (dev) C++ Ascii Rpg
    By kevinawad in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 08-10-2008, 11:10 AM
  3. Need Help With an RPG Style Game
    By JayDog in forum Game Programming
    Replies: 6
    Last Post: 03-30-2003, 07:43 PM
  4. Char Variable Probelm
    By Krak in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2003, 11:34 AM
  5. Try out my newest RPG game called DOOM LORD
    By Leeman_s in forum Game Programming
    Replies: 16
    Last Post: 09-13-2002, 01:31 PM

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