[SOLVED]...functions being run when I haven't called them?
Posted: Mon Mar 22, 2010 5:19 pm
Ok, I've tried to figure this one out for about 30 minutes to an hour now and couldn't come up with a solution.
Basically, in my main file, I'm including a file(game.h) that has functions to retrieve members of instances in my classes. The problem is that the functions are being run, and the instances of the class' members are being edited when I don't want them to yet. I'm sorry if this sounds confusing.
main.cpp:
game.h:
The Output:
Thank you!
EpicAsian
Basically, in my main file, I'm including a file(game.h) that has functions to retrieve members of instances in my classes. The problem is that the functions are being run, and the instances of the class' members are being edited when I don't want them to yet. I'm sorry if this sounds confusing.
main.cpp:
Code: Select all
#include <iostream>
#include "game.h"
int main(int argc, char *args[])
{
using namespace std;
cin.get();
return 0;
}
Code: Select all
//game.h functions
#include "enemy.h"
#include "player.h"
#include <iostream>
#include <string>
using namespace std;
player newPlayer;
enemy newEnemy;
int *enemyHealth = newEnemy.ptrToHP();
int *playerHealth = newPlayer.ptrToHP();
int *playerPotions = newPlayer.getPotions();
int *enemyPotions = newEnemy.getPotions();
int enemyAttack = newEnemy.attack(newPlayer.ptrToHP());
int checkHP();
int playerAttack = newPlayer.attack(enemyHealth);
string choice;
int playerChoice()
{
cout << "Type 'attack' to attack or 'heal' to use a potion..." << endl;
cin >> choice;
if(choice == "attack")
{newPlayer.attack(enemyHealth);
cout << endl << *enemyHealth;}
else if(choice == "heal")
{cout << endl << "The choice was heal";}
}
int enemyAttackTurn()
{
cout << "\nNameless' Turn:\n";
newEnemy.attack(newPlayer.ptrToHP());
checkHP();
}
int enemyHealTurn()
{
cout << "\nNameless attempts to use a potion...\n";
srand(time(NULL));
int randomNumber = rand() % 10;
if (randomNumber <= 60 && newEnemy.getPotions()== 0)
{cout << "but has no potions left!";}
else if (randomNumber <= 60)
{cout << "and heals 10 HP";
enemyHealth = enemyHealth + 10;}
else
{cout << "and it fails!";}
}
int startBattle()
{
enemyAttackTurn();
playerChoice();
}
int checkHP()
{
if(newPlayer.ptrToHP() <= 0)
{
cout << "Press any key to exit...";
cin.get();
abort();
}
}
Code: Select all
Nameless is attacking and dealt 7 damage!
Player is attacking and dealt 57 damage!
EpicAsian