ok, i'm reading through this now, but first something caught my eye.
don't use "goto" statements. it's just bad form....
i'll edit this post with whatever else i find...
EDIT:
ok, all of your defined blocks of code (Attack, Wait, Defend) should be methods. i see you have a method prototype at the top for an int attack() method, but it's never defined. i would also make a method for all of your "do you want to continue?" and "what do you want to do next?" parts. it can be pretty easily done, and save you a little bit of code.
methods are defined outside of main. you can either put them above or below main (or even in seperate files) but if you put them below main, they have to have a prototype above main. a prototype basically says "there will be a method called this" (just like you have 'int attack()' above your main).
one problem i also noticed is that in your goto blocks, you're checking the variable action, but it looks like it's only being read in once (in the beginning).
ok, let's make your methods.
first input:
the idea here is to type this out once, and be able to use it again and again so that it doesn't require more typing. whenever you need to do this input you just call it.
- Code: Select all
// the input method
void input()
{
int action
cout << "What would you like to do?\n";
cout << "(A - attack, D - defend, W - wait, Q - quit).\n";
cin >> action;
if((action == 'A') || (action == 'a'))
{
// you had: goto Attack;
attack(); // we'll define this method in a bit.
}
if((action == 'D') || (action == 'd'))
{
// you had: goto Defend;
defend();
}
if((action == 'W') || (action == 'w'))
{
// you had: goto Wait;
wait();
}
if((action == 'Q') || (action == 'q'))
{
//quit the game.
return 0;
}
}
another thing i noticed is that you don't check for correct input.
for example you ask the user:
"Do you wish to continue? Y or N."
if the user says yes, you ask:
"What would u like to do next?"
"A = Attack."
"D = Defend."
"W = Wait."
but here, if the user accidentally types another character (other than a, d, or w) the program quits. you should include a subroutine here that checks the input to be sure it's valid. after all, they DID tell you they wish to continue.
something like this added to the bottom of your input method might do the trick:
- Code: Select all
if ((action != 'A') && (action != 'a')
&& (action != 'D') && (action != 'd')
&& (action != 'W') && (action != 'w'))
{
cout << "your input was invalid, please try again.\n";
input();
}
now for your attack / defend / wait methods:
we don't want to check if action is equal to 'A', 'D', or 'W' here, because if the attack method gets called, then we know for sure we want to attack. the same is true of the defend and wait methods. i think if you take all the code inside those if checks and put it in your methods, it should work. unfortunately i get off work right now and don't have time to look through all the lines individually. try it out and post if you still have trouble