   Need help designing a combat class in C++
  I have been looking for some information on managing combat, but I have not found much information. Does anyone have something for the following explanation.There is a monster class and a player class. Each of the classes has an attack member function as well as two member variables (health and damage).I would like to implement a combat class that manages combat between an instance of the character class and the monster class.What suggestions does anyone have on implementing this. Code would be appreciated. Most certainly kept to a minimum if possible. I do not have much experience in game loops and etc. If anyone can help me solve this or has even better suggestions on how combat is handled, it would be really helpful to me. Interested especially on how the monster and character objects are passed in and out of the combat class.   
  I don't have a separate combat class in my game.I have a unit class which is used by both the player and the NPCs and this class has an attack method which takes as a parameter the target.Then this methods handles all combat,calculates hit chance deals damage etc.Here is some code : ..bool Unit::attack(Unit* target){ assert(target!=NULL); int chanceToHit = 50 + this->attackRating - target->defenseRating; int roll = rand()%100; //did we hit?  if(roll < chanceToHit || roll < 5) {    target->reduceHP(this->getWeaponDamage());    return true;  }  return false; }Depending on the return value the calling place checks if the target is dead and removes it from the map like : void Map::handleCombat(Unit* attacker,Unit* target){  if(attacker->attack(target))  {if(target->isDead()){  attacker->awardXPFor(target);  removeEntity(target);}   }}That's something like what I have,though I left out lots of code but it boils down to this.   ;  Oh yeah, that leaves me in confusion. Here is another way I would like to ask.Say I have the following:****************************************//monster.h#include <string>using namespace std;class Monster{public:   Monster(string n) { name = n; }   string name;   int damage;   void Attack();};****************************************//monster.cppMonster::Attack(){}****************************************//main.cppMonster monst1("goblin");Monster monst2("orc");int main(){   return 0;}****************************************How would I implement a Combat class and pass both monst1 and monst2 to it to attack each other. Or is there a better way to do this? I am looking to do this in as a most oop way as possible. I don't want to have random functions lying around. So far no success. Sorry for the code, I don't know how to post code blocks.   ;  You can use source tags check out the faq.//monster.h#include <string>#include <iostream>using std::string;using std::cout;class Monster{public:Monster(string n,int damage,int hp):name(n),damage(damage),hp(hp){ } string name;int damage;int hp;void Attack(Monster& target);};//monster.cppvoid Monster::Attack(Monster& target){cout<<name<<" attacked "<<target.name<<"\n";target.hp -= this->damage;cout<<target.name <<" is hit for "<<this->damage<<"\n";}//main.cppint main(){Monster monst1("goblin",10,100);Monster monst2("orc",4,50);monst1.Attack(monst2);return 0;};  I find it somewhat difficult to post a good answer to your questions because I keep thinking about 'the future of your game' and how the design should cater to that in the best way possible. I gave up on that though, because it would be too complicated and cover too many topics, so I'm just going to answer your question in the current setting (not thinking about how to extend this later).You can create a class that has an internal list (in this case I think a std::vector would be a good choice) over all the monsters you want to fight each other. The class can then add monsters to its internal lists with a public function (like AddMonster(Monster *monsterToAdd)), and perform combat between those with a public function (like Fight()). Here is an example of a class such as this:// Combat.h#include "monster.h"#include <vector>class Combat{public:  Combat();  ~Combat();    void AddMonster(Monster *monsterToAdd);  void Fight();private:  std::vector<Monster*> monsterVector;};// Combat.cpp#include "Combat.h"void Combat::AddMonster(Monster *monsterToAdd){  // Add the incoming monster to the vector:  monsterVector.push_back(monsterToAdd);}void Combat::Fight(){  // Make sure the vector has atleast one entry:  if (monsterVector.size() >= 1)  {    // Go through all the entries in the vector:    for (unsigned int i = 0; i < monsterVector.size(); i++)    { // Change this part to attacking the other monsters, however you set it up. monsterVector->Attack();    }  }}Note: I made this as simple as possible (at 8 in the morning :P) so it's only a suggestion of how you could accomplish grouping monsters together and having them attack each other (you have to define the exact attack in this code, though). If we take into consideration their positions, if they're enemies or players, etc. it should be set up differently.Good luck and have fun programming! :)EDIT: Changed from code-tags to source-tags to keep in thread with the, uhm.. thread.   ;  The way I was going to do things was just to give each creature entity a pointer to it's target creature.  Every frame an update method is called on all the creatures which takes a time increment parameter, if the creature is in an attacking state (and isn't stunned or similiar) and has a target which isn't null, dead or too far away then it increments it's attack cycle time. When it reaches the end of it's attack cycle it calls it's ResolveAttack method with it's target creature as an argument which works out the to hit roll and damage etc. The amount of time to complete an attack cycle is presumably linked in some way to the creatures animation, although in principle it doesn't need to be. If the target has moved out of sight, died or is null for some reason then the attacking state and animation are aborted. Setting the target creature in the first place would just be through input in the case of PC creatures, and a separate AI problem otherwise.   ;  Classes are for modelling things. Combat is an action. Only in special circumstances should you consider treating actions as things.   