#### Archived

This topic is now archived and is closed to further replies.

# Need more help with my little prog.

This topic is 5145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok things are runing very smothly on my little rpg battle thingy im coding. Except for one little problem, when the ATB bar fills instead of the program halting and letting the user enter a selection it seams to enter one for you. This sometimes does not happen and I can make a selection but thats few and fare between. Also how would I make it so the program stops and waits for a press of a key instead of entering something then pressing enter with cin ?.

int Creature::CalculateATB()
{
if (this->itsATB > 65535)
{
this->setATB(0);
}
this->setATB(this->itsATB + (96 * (this->showSpd() + 20)) / 16);

if (this->itsATB >= 65535)
return 1;
return 0;
}

bool Battle(Creature Char, Creature Monster)
{
int Option = NULL;

while(true)
{

int defMode = 0;
int IsATBFull1 = 0;
int IsATBFull2 = 0;
cout << "NAME: Mainchar" << endl;
cout << "HP: " << Char.showHp() << "/" << Char.showMaxHp() << endl;
IsATBFull1 = Char.CalculateATB();
Char.showATB();
IsATBFull2 = Monster.CalculateATB();

cout << "__________________________________________________________" << endl;
cout << "VS!!!!!!!!!!" << endl;
cout << "__________________________________________________________" << endl;
cout << "NAME: Monster" << endl;
cout << "HP: " << Monster.showHp() << "/" << Monster.showMaxHp() << endl;
cout << "----------------------------------------------------------" << endl;
cout << endl;

if (IsATBFull1 == 1)
{
cout << "Please pick a command"<< endl;
cout << "1 = Attack" << endl;
cout << "2 = Defend" << endl;
cout << "3 = Run" << endl;
int Option = NULL;
cin >> Option;

switch (Option)
{
case 1:
{
int damage = Char.showAtk() - Monster.showDef();
if (damage <= 0)
damage = 1;
cout << "Main character attacks!!" << endl;
cout << "For..." << damage << endl;
int test;
cin >> test;
Monster.changeHp(Monster.showHp() - damage);
if (Monster.showHp() <= 0)
{
Monster.changeHp(0);
cout << "Monster has died!" << endl;
cout << "YOU WIN!!!!" << endl;

IsATBFull1 = 0;

return 0;
}
break;
}

case 2:
{
IsATBFull1 = 0;
defMode = 0;
break;
}

case 3:
{
IsATBFull1 = 0;
cout << "You run... You coward!";
return 0;
break;
}

default:
{
int damage = Char.showATB() - Monster.showDef();
if (damage <= 0)
damage = 1;
cout << "Main character attacks!!" << endl;
cout << "For..." << damage << endl;
Monster.changeHp(Monster.showHp() - damage);
if (Monster.showHp() <= 0)
{
Monster.changeHp(0);
cout << "Monster has died!" << endl;
cout << "YOU WIN!!!!" << endl;
IsATBFull1 = 0;

return 0;
}
break;
}

}

}

if (IsATBFull2 == 1)
{
int damage = NULL;
if(defMode == 1)
damage = (Monster.showAtk() - Char.showDef()) / 2;
else
damage = Monster.showAtk() - Char.showDef();

if (damage <= 0)
damage = 1;

cout << "The Monster did "<< damage << " to you!" << endl;
int test;
cin >> test;

Char.changeHp(Char.showHp() - damage);

if (Char.showHp() <= 0)
{
Char.changeHp(0);
cout << "You have died!";
return 0;
}
}

clrscr();

}

return true;

}


This isnt the whole of my source just what I think you need to solve my prob. If you need more just ask

##### Share on other sites
Hi Dko,

What does the program "enter for you"? Is it always the same option/value or does this vary?

It''s important to know exactly what the value is in order to debug.

##### Share on other sites
one thing that''s not the problem but is bad, don''t set int''s to NULL, set them to 0. NULL should be reserved to pointers. NULL resolves to 0, but it''s confusing in your code and bad practice.

-me

##### Share on other sites
when the "computer enters things for you" do you actually see the "Pick a command" selection menu? or does it not show that at all. if the latter, your problem is that CalculateATB isn''t doing what you think it''s doing. i think your problem is here:

if (this->itsATB > 65535)
{
this->setATB(0);
}

every time calculateATB is called, the first thing it does is reset it to zero if the number is greater than 65535. the problem is that if on the last iteration the number was slightly less than the number but on this frame it is more, it''ll reset it to zero and you''ll never see the selection menu. make sense? what you should do is remove that block of code and only after the character enters a command, set the character''s ATB to zero. it should work fine that way.

-me

##### Share on other sites
Ok did what you said and a few other things (replacing my cin''s with cin.get()) But know I beleave that now when I press enter after entering a comand it goes right past the get''s because my program runs so fast im still holding enter when it reaches the get''s. Is there any way to stop this? Oh and thanks for your erlier help

• 24
• 11
• 17
• 11
• 13