Thread: Problems with Newbie Text-RPG

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    15

    Problems with Newbie Text-RPG

    I'm making this game while I learn C++ it helps me learn, and its fun.

    Anyway, couple bugs, i've tried and tried again to fix, but can't seem to do it.

    I attached the entire code, so you can compile it and see what i'm talking about first hand.

    First off, Battle System, semi-works. I can't stop it from using negative numbers. For example, the player has 45 Armor, the Monster does only 20 damage, 20 - 45 = -25, so the monster does -25 Damage, and thus Hitpoints are Added to the Player. I tried an if statement to set Damage Dealt to 0 if it is <= 0. Apparently the program just ignores this part.

    Second, after a victory in the battle system, your taken back to the town. Now if you try to quit at the moment, immediatley after coming back to town, it displays the quit message, but then jumps back into the battle system, i can't figure out why or how. Any help would be appreciated.

    As I said, I'm basicly a newb, i still haven't grasped Classes and Objects yet.

    Thanx,
    Darkflame

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    i haven't looked at your code but problem 1 can be solved by this simple algo...

    if ( HitPoints - DamageDone < 0) DamageDone=HitPoints;

    that way any damage that would go neg will now only go to 0.

    I guess id need to look at your code to fix problem 2...
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    ok ive looked at your code and there are MANY errors!

    main should return an int and in some possible paths you have a return 0 yet main is declared as void. Declare main to return an int and make sure all possible paths return an int.

    do not call main recursively. Only the operating system calls main not you!

    use = as an assignment operator not == which is an is equal to comparison operator.code such as :-

    if (blah < foo)
    {playerdamage==20;}

    has no effect whatsoever.

    In your battle system you lose data convering a float to an int....

    also you have many functions supposed to return an int without return statements....
    and that is what i saw from just a quick glance there are prolly more errors too.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    here ive fixed it up a little but i left you the problem 1 to sort out on your own......
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    Ok I cleaned up the code, those functions that were declard int but returned no number are from previous code where they did, which i changed without changing them, i think i got em all now,

    Also I did manage to get the battle system not to show negative numbers. Thanx to your first post, i modified it for my code. And it worked.

    Took out main, declared a new function in its place, let main alone.

    The only thing i didn't understand is the converting float to int in the battle system, i think i know where you're talking about, when i divide enemy armor by 2, but i know no other way to accomplish this.

    New Code is attached. With Fixes.

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    in your battle function make this change....

    if (playercurrentlife <= 0)
    {
    death();
    return;
    }
    if (enemylife <= 0)
    {
    victory();
    return ;
    }

    that will sort out your second problem....
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    the battles always go the same way so you need to seed the random number generator....

    add :-

    #include<time.h>

    and first line of main should be ....

    srand((unsigned)time(NULL));

    as for the loss of data you can live with it its not too great a problem but your compiler will warn you about it and to get rid of those warnings explicitly cast to an int..... like i did in the fixed code...
    Last edited by Stoned_Coder; 09-12-2001 at 09:42 PM.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    Ahh Thanx.

    Thanx alot, this helped greatly.

    Right now, i'm trying to get the system to run solidly every time, before i generate some randomess to it.

    Thanx for all the help,
    Darkflame

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. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  3. Reviving the dead on Text RPG
    By Blizzarddog in forum Game Programming
    Replies: 8
    Last Post: 03-02-2003, 12:06 PM
  4. Text RPG
    By coolazz0 in forum Game Programming
    Replies: 17
    Last Post: 02-21-2003, 03:57 PM
  5. my text based RPG!
    By Leeman_s in forum Game Programming
    Replies: 11
    Last Post: 05-13-2002, 08:24 AM