Hey guys! I know some of you might comment saying this should be in the game programming section, but my question isn't specifically related to a game function, but the C++ function of classes in general.
Here is my program so far, just to let you guys know, this program was purely made fast and simple to see if my first two classes would work:
Code:
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
class CPlayer {
int Hp;
int Att;
int Str;
public:
void set_values ( int,int,int);
};
void CPlayer::set_values (int Hp, int Att, int Str) {
Hp = 100;
Str = 10;
Att = 10 + Str;
}
class CMonster {
public:
int Hp;
int Att;
int Str;
public:
void set_values (int, int, int);
};
void CMonster::set_values(int HP, int Att, int Str) {
Hp = 50;
Str = 5;
Att = 10 + Str;
}
int main ()
{
string Input;
int PHealth;
int MHealth;
cout << "Watch out warrior, a monster is behind you!";
cin.get();
cout << "(A monster jumps out and attacks you!";
getline (cin, Input);
cout << "Would you like to attack?";
cout << "(y) for Yes, (n) for No: ";
cin >> Input;
if ( Input == "y") {
cout << "You attack the monster!";
Sleep(3000);
(CMonster.Hp - CPlayer.Att = PHealth);
}
else {
cout << "Oh no! Since you didn't attack him, he attacked you!";
(CPlayer.Hp - CMonster.Att = MHealth);
}
}
Now, first off I did not use pointers in this. 'PHealth' is the variable for players health that will be changed and out putted.. same thing goes for MHealth, except its for monster. I am extremely new to classes, and haven't really concepted how every part of it works, such as private, public, and protected. I do know what they are for, but somethings about 'em I don;t understand. Anyway thats not my problem here... my problem is at the very end where I want to subtract my monsters health variable from my players attack variable.. The program will not compile.. I think it has to do with the fact that "CMonster.Hp" isn't the way you tell the program you want to use the variable "Hp" from the class 'CMonster".. can any one point me in the right direction on what to do for that?? Maybe the right way is "CMonster::Hp" but that still wouldn't compile the program....