Hey all, I’m pretty noob at C++. I’m hoping I have some semblance of a program built though. I basically want to take 2 players, using at least 2 classes; a player class and a weapons and/or armor subclass. I want to show their stats after each battle when they gain exp. The numbers don’t even really need to make much sense. I just need to get out of compile error hell at this point. Can anyone help me figure out how to debug this? I’m getting some compile errors, but have no idea where to start. In my subclasses I am basically making one static weapon and armor and assuming they are both using it.
// MCrowley.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Player
{
public:
Player();
Player(string, int, int, int, int, int);
void setPlayer(string, int, int, int, int, int);
string getPlayer(int& lvl, int& exp, int& hp, int& str, int& def);
void printPlayer();
Player operator+(const Player&) const;
private:
string playerName;
int level, experiencePoints, hitPoints, strength, defence;
};
class PlayerArmor: public Player //child (inherited) class
{
public:
PlayerArmor();
PlayerArmor(string, int, int, int, int, int, string);
void setStatusDefence(string);
void printPlayer() const; //overries parent class print function
private:
string armorName, statusDefence;
};
class PlayerWeapon: public Player //child (inherited) class
{
public:
PlayerWeapon();
PlayerWeapon(string, int, int, int, int, int string);
void setStatusInflict(string);
void printPlayer() const; //overries parent class print function
private:
string weaponName, statusInflict;
};
void Player::setPlayer(string name, int lvl, int exp, int hp, int str, int def) //set data for player
{
playerName = name;
level = lvl;
experiencePoints = exp;
hitPoints = hp;
strength = str;
defence = def;
}
Player::Player() //default constructor
{
setPlayer(" ", 1, 0, 100, 1, 1);
}
Player::Player(string name, int lvl, int exp, int hp, int str, int def) //overloaded constructor
{
setPlayer(name, lvl, exp, hp, str, def);
}
string Player::getPlayer(int& lvl, int& exp, int& hp, int& str, int& def)
{
lvl = level;
exp = experiencePoints;
hp = hitPoints;
str = strength;
def = defence;
return playerName;
}
void Player::printPlayer()
{
string name;
int lvl, exp, hp, str, def;
name = getPlayer(lvl, exp, hp, str, def);
cout << name << ": " << "lvl: " << lvl << " " << "exp: "<< exp << " " << "hp: "<< hp << " " << "str: "<< str << " " << "def: "<< def << endl;
}
Player Player::operator+(const Player& otherPL) const
{
Player tempPL;
tempPL.playerName = playerName;
tempPL.experiencePoints = experiencePoints + otherPL.experiencePoints;
if (tempPL.experiencePoints > 1000 * level)
{
tempPL.level++;
}
if (tempPL.level > level)
{
tempPL.hitPoints = tempPL.hitPoints * 2;
tempPL.strength = tempPL.strength * 2;
tempPL.defence = tempPL.defence * 2;
}
return tempPL; // return object containing totals
}
//Player::~Player()
//{
//}
PlayerArmor::PlayerArmor()
{
armorName = "Burning Armor";
statusDefence = "Fire Immune";
}
PlayerArmor::PlayerArmor(string armorName, int lvl, int exp, int hp, int str, int def, string StatusDefence):Player(lvl, exp, hp, str, def)
{
setStatusDefence(statDef);
hp = hp + 100;
def = def + 5;
}
void PlayerArmor::setStatusDefence(string statDef)
{
statusDefence = statDef;
}
void PlayerArmor::printPlayer()
{
Player::printPlayer();
cout<< "Armor Name: " << armorName; << endl;
cout<< "Status Defence: " << statusDefence; << endl;
}
//PlayerArmor::~PlayerArmor()
//{
//}
PlayerWeapon::PlayerWeapon()
{
weaponName = "Frigid Blade";
statusInflict = "Blizzaga";
}
PlayerWeapon::PlayerWeapon(string armorName, int str, string statusInflict)
{
setStatusInflict(statInf);
str = str + 10;
}
void PlayerWeapon::setStatusInflict(string statInf)
{
statusInflict = statInf;
}
void PlayerWeapon::printPlayer()
{
Player::printPlayer();
cout<< "Weapon Name: " << weaponName << endl;
cout<< "Status Inflict: " << statusInflict << endl;
}
//PlayerWeapon::~PlayerWeapon()
//{
//}
void main()
{
string stats1, stats2;
int totalLevel1, totalLevel2, totalExperiencePoints1, totalExperiencePoints2, totalHitPoints1, totalHitPoints2, totalStrength1, totalStrength2, totalDefence1, totalDefence2;
Player battle1("Zidane", 1, 900, 100, 1, 1); //set battle stats
Player battle2("Zidane", 1, 100, 100, 1, 1);
Player battle3("Zidane", 2, 1100, 200, 2, 2);
Player battle4("Vaan", 2, 200, 200, 2, 2);
Player battle5("Vaan", 2, 400, 200, 2, 2);
Player battle6("Vaan", 2, 700, 200, 2, 2);
battle1.printPlayer(); //print out battle stats
battle2.printPlayer();
battle3.printPlayer();
battle4.printPlayer();
battle5.printPlayer();
battle6.printPlayer();
cout << endl << endl << "Totals:" << endl;
Player zidaneStats = battle1 + battle2 + battle3;
zidaneStats.printPlayer(); // print totals
Player vaanStats = battle4 + battle5 + battle6;
vaanStats.printPlayer(); // print totals
stats1 = zidaneStats.getPlayer(totalLevel1, totalExperiencePoints1, totalHitPoints1, totalStrength1, totalDefence1); //get total battle data for each fighter
stats2 = vaanStats.getPlayer(totalLevel2, totalExperiencePoints2, totalHitPoints2, totalStrength2, totalDefence2);
if(totalLevel1 > totalLevel2) // determine and print the fighter with the highest total level
cout << endl << endl << stats1 << " gained the highest total lvl." << endl;
else if(totalLevel1 < totalLevel2)
cout << stats2 << " gained the highest total lvl." << endl;
else
cout << stats1 << " and " << stats2 << " gained the same total levels" << endl;
if(totalExperiencePoints1 < totalExperiencePoints2) // determine and print the fighter with the lowest hit points(HP)
cout << endl << endl << stats1 << " gained the lowest experience points." << endl;
else if(totalExperiencePoints1 > totalExperiencePoints2)
cout << stats2 << " gained the lowest experience points." << endl;
else
cout << stats1 << " and " << stats2 << " gained the same experience points" << endl;
cin.ignore(2);
}
Thanks in advance!