Ok, first the name - CCharacter would have been OK, but it is too long. CActor has the same meaning.
You are right the Attack & RecvAttack functions could go into CActor class, so they will be inherited to the CPlayer & CEnemy and derivatives of those.
I would overload the Attack function like this:
1 2 3
|
virtual bool Attack(CPlayer *, CEnemy *, CWeapon *); //Player vs Enemy
virtual bool Attack(CEnemy *, CPlayer *, CWeapon *); // Enemy vs Player
|
A pointer to the object doing the attacking is included, so that the object being attacked knows who to fight back to.
If there was just one Attack function with CActor and CWeapon as the arguments, then this could mean a free for all - Player vs Player and Enemy vs Enemy. I am guessing this is not what you want.
Looks as though I need to straighten out your terminology a little bit:
could hold pointers in the constructor which point to the players current health and enemies health. |
Constructors are functions (you can have more than one in a class) that initialise member variables, they don't hold anything.
One class to hold variables and actions for the characters. |
We need to have the derived classes so that we can create objects from them - having just CActor class would mean that we couldn't create a Hero (CPlayer) or say a Troll (CTroll). Well you could, but we want them to be different types of objects, so they can have different behaviours.
The CActor class is there to hold info that is common to all the Players & Enemies. An example of this is the m_Health member variable. This class could also hold other common actions (member functions) such as Move() .
Just going back to the Quality attribute - could we come up with a better name than that? Some thing along the lines of Newness or Used etc that might have a more obvious meaning.
With that, I would have some more variables. A step value which is subtracted each time the weapon is used. A minimum value such BrokenVal which means that when the UsedVal gets down to this number the weapon is broken. Also a bool IsBroken that is set to true when UsedVal == BrokenVal. These could all go into the Weapons class. You could have a virtual function, so that each weapon could have it's own step value and BrokenVal.
A final thing about types - I like to include the stdint.h file :
#include <stdint.h>
so that I can have types like
uint16_t
instead of
unsigned short
. In my mind this is easier for several reasons:
You know what you are getting -
uint16_t
is a 16 bit unsigned int, depending on the system short might be the same as int for example;
It is more concise when it comes to using qualifier like const etc think of
const unsigned long long
as opposed to
const uint64_t
;
int8_t is less confusing than char for an 8 bit number.
I would be inclined to make damage & health uint16_t. It would be best to have them the same, and 8 bits is only goes up to 255 which might be a bit restrictive.
I am going to have a go at creating this code myself, so we can compare.
Also, about your question of using maps. This becomes tricky because it varies so much from system to system. You use Visual Studio, right? Hmmm, I don't know anything about Windows Programming, which is what you would have to do to have visual maps. There all kinds of different systems out there, but unless we had the same, that's probably where my help to you would end.
Now you can do whatever you like, and you could most likely find someone to help you that is much more knowledgeable than me, for whichever system / technology you choose.
I use Qt Creator, although I confess to not knowing much about that either, but it does have these advantages:
Available on Windows, Linux and Mac;
Can cross compile to other OS. I am not sure but I have heard it might be a bit tricky to have 1 code set that can be compiled to work on Windows or Linux - I might be wrong there - great if I was!! ;
Can make Windows apps with windows code;
Can make apps for phones etc - you could make one for your android tablet;
Has access to all kinds of technologies Animation, Mobile, graphics, networking, OpenGL, plus heaps more. There are hundreds of example demo apps that come with it.
Now I should point out that learning a GUI system is generally a lot more involved than merely learning a programming language.
One other thing - there is a beginners problem on this site that is to make a Dungeon Crawler program. Use the search button at the top of this page to find the question and also various peoples attempts at it - Some better than others I suspect.
There you go - a whole lot more to think about !!!