Witam mam oto następujący programik:
MAIN.CPP
#include "stdafx.h"
#include <iostream>
#include "Postacie.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a;
Mag m;
MagOgnia mo;
m.show();
cout << endl << endl;
mo.show();
cout << endl << "Kto ma atakowac ? [1/2]: ";
cin >> a;
if (a==1){
m.atak();
}else if(a==2){
mo.atak();
}
return 0;
}
POSTACIE.H
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Mag
{
private:
int HP;
float DMG;
public:
string NAME;
Mag(string KNAME="Mag", int KHP=500, float KDMG=50)
{
NAME=KNAME;
HP=KHP;
DMG=KDMG;
}
void show();
int atak();
};
class MagOgnia :public Mag
{
private:
float MAGDMG;
public:
MagOgnia(string KNAME="MagOgnia", int KHP=350, float KDMG=70, float KMAGDMG=90)
:Mag(KNAME, KHP, KDMG)
{
MAGDMG = KMAGDMG;
}
void show();
int atak();
};
POSTACIE.CPP
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Postacie.h"
using namespace std;
void Mag::show()
{
cout << "Nazwa Mag: " << NAME << endl;
cout << "HP: " << HP << endl;
cout << "DMG: " << DMG << endl;
}
int Mag::atak()
{
cout << "Zadaje: " << DMG << " obrazen do " << MagOgnia::NAME; // Jak tu wyświetlić nazwe MagOgnia z klasy MagOgnia?
}
void MagOgnia::show()
{
Mag::show();
cout << "ATAKDMG: " << MAGDMG << endl;
}
int MagOgnia::atak()
{
cout << "Zadaje: " << MAGDMG << " obrazen do " << Mag::NAME << endl; // Jak tu wyświetlić nazwe Mag z klasy Mag?
}
A potem bym chciał by wartość DMG odjęła się od HP danego Maga. Nie wiem w jaki sposób to wykonać czy w Main ? Czy metoda przekazywać zmienne, wskaźnik, referencja przez maina ? Czy jakoś między klasami, a może muszę metodę przekazującą ?