Thread: Reviving the dead on Text RPG

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    Reviving the dead on Text RPG

    I'm still a newbie programmer of C++. I can use rand(), if, else if, strings, chars, ints, floats, structs. A bunch of other stuff. Even fout.
    I am making a pretty nice text rpg on a 6x6x6 cube. I have the x and y coordinates down, z is not in yet.
    I have 2 enemies that walk around randomly, a zombie, and a mummy. The liche is stationary.
    I want it that every 15 moves, it revives the zombie to 15 health.
    Im doing this by every turn, the program adds one to a counter, called int revive.
    [code]
    while (revive != 15)
    {
    revive ++;
    }
    if (revive == 15)
    {
    revive = 0;
    zombie_health = 15;
    cout << "\nThe Reviver of the Dead sets the zombies health to 15.\n";
    }
    [code]

    Every move, it revives the zombie, unless you are battling it. What is wrong with the code?
    This war, like the next war, is a war to end war.

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Once your program goes into the while loop, it will add one to revive untill it's 15. The check afterwards revives it.
    Try with this:
    Code:
    if(revive == 15)
    {
       revive = 0;
       zombie_health = 15;
       cout<<"The zombie has been rivived\n";
    }
    else revive++;
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  3. #3
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    OMG! WHY DIDN"T I SEE THAT!?!?
    Well, i had code that looked like this:
    Code:
    rivive++
    if (revive == 15)
    {
    revive = 0;
    zombie_health = 15;
    cout << "The Reviver of the Dead revived the zombie.\n";
    }
    and that still didn't work. why?
    This war, like the next war, is a war to end war.

  4. #4
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    >>and that still didn't work. why?
    Do you have an alive or dead status for the zombie? Does your code execute displaying the cout or do you have to fight the zombie? Check for any outer loops that might cause the code to repeat.
    If that doesn't work, I've no idea Anybody else?
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  5. #5
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    my code is attached

    *edit*
    Sorry, its a mess, i know. But it works.
    This war, like the next war, is a war to end war.

  6. #6
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    How did that code work for you? I had to #include <windows.h> for it to work. Anyway it works fine but the zombie is revived even if it's already revived which is really strange even for a zombie. Somehting like this should work.
    Code:
    BOOL ZombieAlive = FALSE; //this should be outside the loop for this to work
    if(revive == 15)
    {
      revive = 0;
      if(ZombieAlive == FALSE)
      {
         cout<<"The zombie is alive\n";
         ZombieAlive = TRUE;
       }
    }
    Also, set the colour of the text back to white when you close the program. Dunno how many people still use the command line for anything but if you access it from it, when the prog finishes it leaves the colour of the text cyanide (or whatever you call it).
    One last thing. Indent!!
    Last edited by -=SoKrA=-; 03-02-2003 at 11:35 AM.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  7. #7
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    thanks man, or gal, whichever you are. That bool i had to edit a little bit, because it didn't add to revive, but i got it working. Im trying to learn sound input right now, so i can spice up my game with music and battle sounds.

    Hows the game look right now?
    Last edited by Blizzarddog; 03-02-2003 at 11:47 AM.
    This war, like the next war, is a war to end war.

  8. #8
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    >>Hows the game look right now?
    Looks promising. You should tell the user the keys at the start. I had to look through the code to see them.
    One thing that's annoying is having to press a key to be able to enter the key for the movement. You should have it so you just read the key, without having to press enter.
    Maybe some error checking in the input?
    Keep up the good work!
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  9. #9
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    thanks, like i said, im still a newbie. I just learned how to do key inputs without hitting enter today. But that still has a halt. I was using
    Code:
    getch();
    char ent;
    ent = getch();
    I designed the battle engine myself, and the random hit damage. Though im not real sure on how to use defense and strength depending on level.
    This war, like the next war, is a war to end war.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. text rpg help
    By xxwerdxx in forum Game Programming
    Replies: 1
    Last Post: 11-26-2005, 08:16 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. mygets
    By Dave_Sinkula in forum C Programming
    Replies: 6
    Last Post: 03-23-2003, 07:23 PM
  4. Text Rpg Of Courseee
    By Paninaro in forum Game Programming
    Replies: 6
    Last Post: 06-24-2002, 01:54 PM
  5. Check out My Text Rpg Game
    By knight543 in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2002, 10:40 PM