Below you will see two header files and an implementation file(the one that has errors). I have included the error messages I am recieving below the two files. I don't know what I am doing wrong, so if you have and questions, just ask.
-also included the systemhlp.h file, just in case you wanna try and compile it; all the files are there for you.
thanks.
Code:
//enemy.h
#ifndef _enemy_h_
#define _enemy_h_
#include "player.h"
class Player;//forward declaration
using namespace std;
class Enemy
{
public:
void stats();
void bStats();
int attack(Enemy& enemyN, Player* playerN);
Enemy(int num);
private:
int m_hp;//=======================LINE 19======================
int m_mp;
int m_str;
int m_exp;
int m_level;
string m_name;
};
#endif
Code:
//player.h
#ifndef _player_h_
#define _player_h_
#include "enemy.h"
class Enemy;//forward declaration
using namespace std;
class Player
{
public:
Player(int gClass);
void levelUp();
bool canLevelUp();
void stats();
void bStats();
int attack(Enemy* enemyN, Player& playerN);
void inventory();
int heal(Player playerN);
//int mag(Player* playerN, Enemy* enemyN, string spell);
private:
int MAX_HP;
int MAX_MP;
int m_level;
int m_hp;
int m_str;
int m_mp;
int m_exp;
int m_mPow;
char m_name[12];//Player's name
};
#endif
Code:
//player.cpp
#include<iostream>
#include<string>
#include <stdio.h>
#include <stdlib.h>
#include "systemhlp.h"
#include "player.h"
#include "enemy.h"
using namespace std;
Player::Player(int gClass)
{
if(gClass == 1)
{
m_level = 1;
m_hp = 100;
m_str = 20;
m_mp = 50;
MAX_HP = m_hp;
MAX_MP = m_mp;
}
if(gClass == 2)
{
m_level = 1;
m_hp = 80;
m_str = 10;
m_mp = 100;
MAX_HP = m_hp;
MAX_MP = m_mp;
}
if(gClass == 3)
{
m_level = 1;
m_hp = 90;
m_str = 15;
m_mp = 75;
MAX_HP = m_hp;
MAX_MP = m_mp;
}
};
bool Player::canLevelUp()
{
if(m_level == 1 && m_exp >= 32)
{
return true;
}
else if(m_level == 2 && m_exp >= 96)
{
return true;
}
else if(m_level == 3 && m_exp >= 208)
{
return true;
}
else if(m_level == 4 && m_exp >= 400)
{
return true;
}
else if(m_level == 5 && m_exp >= 672)
{
return true;
}
else if(m_level == 6 && m_exp >= 1056)
{
return true;
}
else if(m_level == 7 && m_exp >= 1552)
{
return true;
}
else if(m_level == 8 && m_exp >= 2184)
{
return true;
}
else if(m_level == 9 && m_exp >= 2976)
{
return true;
}
else if(m_level == 10 && m_exp >= 3936)
{
return true;
}
else if(m_level == 11 && m_exp >= 5080)
{
return true;
}
else if(m_level == 12 && m_exp >= 6432)
{
return true;
}
else if(m_level == 13 && m_exp >= 7992)
{
return true;
}
else if(m_level == 14 && m_exp >= 9784)
{
return true;
}
else if(m_level == 15 && m_exp >= 11840)
{
return true;
}
else if(m_level == 16 && m_exp >= 14152)
{
return true;
}
else if(m_level == 17 && m_exp >= 16736)
{
return true;
}
else if(m_level == 18 && m_exp >= 19616)
{
return true;
}
else if(m_level == 19 && m_exp >= 22832)
{
return true;
}
else
{
return false;
}
}
void Player::levelUp()
{
m_level++;
if(m_level <= 10 && canLevelUp() == true)
{
m_hp += 50;
m_str += 5;
m_mp += 50;
MAX_HP = m_hp;
MAX_MP = m_mp;
}
if(m_level <= 15 && canLevelUp() == true)
{
m_hp += 45;
m_str += 4;
m_mp += 45;
MAX_HP = m_hp;
MAX_MP = m_mp;
}
if(m_level <= 20 && canLevelUp() == true)
{
m_hp += 35;
m_str += 3;
m_mp += 35;
MAX_HP = m_hp;
MAX_MP = m_mp;
}
}
void Player::stats()
{
cout<<".~-Stats-~."<<endl;
cout<<"Level: "<<m_level<<endl;
cout<<m_name<<endl;
cout<<"HP: "<<m_hp<<endl;
cout<<"MP: "<<m_mp<<endl;
cout<<"Strength: "<<m_str<<endl;
cout<<"Exp: "<<m_exp<<endl;
system("pause");
}
void Player::bStats()
{
cout<<m_name<<endl;
cout<<"HP: "<<m_hp<<endl;
cout<<"MP: "<<m_mp<<endl;
cout<<"\n"<<endl;
}
int Player::heal(Player playerN)
{
if(playerN.m_mp >= 5)
{
int x = ((playerN.m_level*playerN.MAX_MP)/128) + ((rand() % 6) + 4);
system("cls");
cout<<"You gain "<<x<<" points of health!\n"<<endl;
system("pause");
playerN.m_hp = playerN.m_hp + x;
playerN.m_mp = playerN.m_mp - 5;
if(playerN.m_hp > playerN.MAX_HP)
{
playerN.m_hp = playerN.MAX_HP;
}
return playerN.m_mp, playerN.m_hp;
}
}
int Player::attack(Enemy* enemyN, Player& playerN)
{
cls();
int x = 20 * (playerN.m_str/100) * 20;
int criticalHit = x * (2/10);
if(((rand() % 6) + 1) == 3)
{
x += criticalHit;
cout<<"Critical Hit!"<<endl;
}
enemyN->m_hp = enemyN->m_hp - x;//=========LINE 304==============
cout<<"You hit for "<<x<<" points of damage!\n"<<endl;
pause();
cls();
if(enemyN->m_hp < 0)//==================LINE 308================
{
enemyN->m_hp = 0;//=================LINE 310===============
}
return enemyN->m_hp; //==================LINE 313==============
}
Code:
Line Message File
19 `int enemy.h
304 within player.cpp
19 `int enemy.h
304 within player.cpp
19 `int enemy.h
308 within player.cpp
19 `int enemy.h
310 within player.cpp
19 `int enemy.h
313 within player.cpp
Code:
//systemhelp.h
#include <iostream>
#include <stdlib.h>
void pause()
{
std::cout<<"\n\n==>"<<std::endl;
std::cin.ignore(std::cin.rdbuf()->in_avail() + 1);
}
void cls()
{
system("cls");
}