Anything bad so far? :/

Pages: 12
Thanks so much!

Here's what I got and seems like what I want. I'll improve this of course :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>

using namespace std;

class CCharacter {
public:
	CCharacter (int h, int aL, int dL) : health (h), attackLevel (aL), defenceLevel (dL) {
	}
	CCharacter () : health (100), attackLevel (1), defenceLevel (1) {
	}
	~CCharacter () {
	}
	int getHealth () const { return health; }
	int getAttackLevel () const { return attackLevel; }
	int getDefenceLevel () const { return defenceLevel; }
	void increaseHealth (unsigned int iH) { health += iH; }
	void decreaseHealth (unsigned int dH) { health -= dH; }
	void setAttackLevel (int aL) { attackLevel = aL; }
	void setDefenceLevel (int dL) { defenceLevel = dL; }
	virtual void attack (CCharacter &target) = 0;
private:
	int health;
	int attackLevel;
	int defenceLevel;
	string name;
};


class CPlayer : public CCharacter {
public:
	CPlayer () : CCharacter (100, 1, 1) { }
	void attack (CCharacter &target) {
		cout << "You attack the monster with " << getAttackLevel() << " attack!" << endl;
		target.decreaseHealth (getAttackLevel());
		cout << "The monster got hit by a " << getAttackLevel() << ", his health is now at : " << target.getHealth() << endl;
	}
};

class CNPC : public CCharacter {
public:
	CNPC () : CCharacter (100, 1, 1) { }
	void attack (CCharacter &target) {
		cout << "The monster attacks you with " << getAttackLevel() << " attack!" << endl;
		target.decreaseHealth (getAttackLevel());
		cout << "You got hit by a " << getAttackLevel() << ", your health is now at : " << target.getHealth() << endl;
	}
};

int main ()
{
	CPlayer player;
	CNPC npc;

	player.attack (npc);
	return 0;
}


Well thanks for helping me with all of this, once I'm comfortable with c++ i'm going to be moving on to a graphics/input library, probably SDL first not sure which to start with but i'll see but again thank you so much Athar :D
Topic archived. No new replies allowed.
Pages: 12