Advertisement

RPG Problems

Started by March 24, 2002 07:47 PM
41 comments, last by Quantrizi 22 years, 9 months ago
I am working on a text-RPG just like a lot of peoplej**, and am having trouble on a certain part, and I am using switches. I have a ninja attack, but when the attack sequence happens, it''ll say press any key to continue, i do have system("PAUSE"); in it, but my others work, here''s the code starting from where the fight sequence begins:
    cout << "A ninja walks in and trys to attack! What should you do?\n";
    cout << "1]Attack\n2]Run\n3]Defend\n";
    cin >> answer;
switch (answer)
{
    case 1:
        cout << "The ninja trys to stab you, but dodge the attack, and graze his face.\n";
break;
    case 2:
        cout << "You try to run away, but the ninja stabs you in the back with his sword.\n";
        cout << "You die..and GAME OVER!\n";
        return 0;
break;
    case 3:
        cout << "You are in defense!  You await the ninja to attack.\n";
break;
default:
    cout << "Invalid Input Value!\n";
}
if (answer == 3)
    cout << "Your defense is weak....the ninja runs at you and slices your leg."
            "  You scream in pain, then the ninja, standing over your sliced leg, "
            "stabs you in the chest, driving the sword right through the heart.  "
            "You faint, and die!  The end...and Game Over!  The Game will end in a few seconds.";
            system("PAUSE");
            return 0;
if (answer == 1)
    cout << "Ninja''s HP is now: 23/34.\nThe ninja runs to you, raising his sword high up in the "
            "sky,\nand strikes, causing major damage!  Your HP is now: 34/41\n";
            "  What to do now?\n";
            "Choices:\t1]Attack\n2]Run\n";
    cin >> answer;
switch (answer)
{
case 2:
    cout << "You ran away, but lost: 100 gold, 1 potion, and 40 experience points.\n";
break;
case 1:
    cout << "With some major damage done, you think to yourself....should I try to run, or fight.\n";
break;
default:
    cout << "Invalid Input Value!\n";
}
if (answer == 2)
    cout << "Nice job jack...all well....at least you have a weapon.\n";
if (answer == 1)
    cout << "Do you want to run, or no?\n";
    cout << "1©Yes\n2©No\n";
    cin >> answer;
switch (answer)
{
case 2:
    cout << "The ninja sneaks up behind you and stabs you in the back while you think....think faster!\n";
    system ("PAUSE");
break;
case 1:
    cout << "The ninja tries to sneak up behind you, but thinking quickly, you roundhouse him, and runs away.\n";
break;
default:
    cout << "Wrong Input Value!\n";
}    
  system("PAUSE");  
  return 0;
}
 
The output is: The ninja trys to stab you, but dodge the attack, and graze his face. Please press any key to continue..... Can anyone help me?? If you care about her/him, you''''ll listen If you love her/him, you''''ll heal his/her wounds If you like her/him, you''''ll do all of the above, and help her/him in need A person who cares is a person who never speaks
In the part where you check if answer == 3, was it your intent to have the return seperate like that? Because that will always return 0 no matter what when it reaches that point. You can join multiple expressions using braces ({ and }). Try this:


      if(answer == 3){  cout << " ... ";  return 0;}        


It looks like you might want to change this in a few other places as well.

[edited by - SilentCoder on March 24, 2002 9:06:30 PM]
Advertisement
Thanks. I was wanting the user be able to read it, and when your done, press any key to continue, but thanx. I''ll just do it that way.

If you care about her/him, you''''ll listen
If you love her/him, you''''ll heal his/her wounds
If you like her/him, you''''ll do all of the above, and help her/him in need

A person who cares is a person who never speaks
Ok, I just deleted the whole code where I was having problems on...hopefully it'll work now....Ok, and I have another problem...here it is: I have 4 classes, and have different HP and MP for each....but this is the problem....I have a fight*the ninja scene*, and want to have HP drop, and this is what I'm thinking on:

    int counter;int hp;int mp;if (counter == hp)counter--;if (counter < hp)counter--;if (counter > hp)    cout << "Cheater!";    

can anyone tell me if that'll work please



[edited by - Quantrizi on March 25, 2002 4:57:09 PM]

[edited by - Quantrizi on March 25, 2002 4:57:58 PM]
It''ll compile, if that is what you mean. What do you mean for the code to actually do.
When you said you have four classes do you mean class CPlayer, class CNinja or do you mean four classes/types of opponents such as ninja, mage, whatever. It would be way easier if you did make classes (OOP) for your fighters. Here is a way simplified example:


lets say you have class CFighter and two instances, ninja and player.

ninja.attack = 8; //numbers are completely arbitrary
ninja.defence = 7;
ninja.hp = 10;

player.attack = 9;
player.defence = 6;
player.hp = 12;

//now have the ninja attack
while(player.hp > 0)
{
player.hp = player.hp - (ninja.attack - player.defence);
}

Of course the player will always die in this case because he never gets a chance to fight back but I hope this gives you some ideas. Also, if you don''t go the OO route even a simple game like this will turn into a jumbled mess pretty quick because you will need variables all over the place (int ninja_attack; int ninja_defence; int ninja_hp; int player_attack, etc, etc)

Advertisement
Ok, thanx, I''ll extremely consider that....and this is what I ment by classes:
You get to pick 4 types of people to play as, Mage, Wizard, Monk, and Warrior. And enimies are pretty much random right now*although I have to type all of the stuff*
It''s the "typing all the stuff" part that will really suck and pretty fast. If you are pretty comfortable with your programming seriously consider trying out the OO side. It make take some time to get up to speed but I shudder to think how long it will take you to finish this game otherwise. Consider this, right now if you want to add a new character type you have to go in and add a whole new set of variables to keep track of hp, attack power and what not. With OOP you would just create a new instance of your Fighter class which already has all those attributes and you are ready to rock.
Also, something that will help you too is to declare your classess in arrays, and to use _FUNCTIONS_ and _ARRAYS_ this isn''t basic or pascal!
---START GEEK CODE BLOCK---GCS/M/S dpu s:+ a---- C++ UL(+) P(++) L+(+) E--- W++ N+ o K w(--) !O !M !V PS- PE+Y+ PGP+ t 5 X-- R tv+ b+ DI+ D G e* h! r-- !x ---END GEEK CODE BLOCK---
Ok...sorry if I sound dumb(i think I will anyways), but I don't know how to do the OO side....and everything's been in char, int, switch, if, and that's it. But if anyone can tell me how to switch to the "dark" side*kinda of a inside joke*, then please tell me if it'll make it easier, and classes ain't really my thing, but I'll work on it. And for the arrays, that might be used for some stuff, I'm learning as I go along, and while I'm reading my C++ beginners book*i'm pretty good for a newbie IMHO* But, I'll probably do the Arrays idea.

[edited by - Quantrizi on March 25, 2002 7:46:15 PM]

This topic is closed to new replies.

Advertisement