Question about large objects
I have been writing games and I also read about good programming
techniques. I tend to create large objects that do lots of things. A
good example I have is a unit object. The object controls and holds
everything a unit in my game is supposed to do. What are some some
cures for this kind of large object or are they OK because they
represent one thing. If not what are better ways to design objects
that behave the same way. Would it be better to use inheritance or
friends and where can I look to be able to do the same thing in a
better way?
Here is a unit from a completed game I created. The header file at
least to give an idea of one of my larger objects.
#include<fstream>
#include<vector>
#include<cmath>
#include<map>
#include"coord.h"
#include"color.h"
#include"graphics.h"
#include"tbox.h"
#ifndef UNIT_H
#define UNIT_H
class unit{
protected:
HWND hwnd;
coord loc;
coord currentLoc;
graphics * gr;
tbox * combatBox;
std::vector<color>colors;
std::map<char, coord> keys; //movement engine
coord n; //directions
coord s;
coord e;
coord w;
char kind;
float attack;
float dattack;
float defence;
int move;
int moved;
int dmove;
int range;
bool canmove;
bool selected;
bool mark;
bool disburse;
int col;
void create();
void displayBox(HDC, coord);
int convert(const int n){return n * 16;}
public:
unit();
unit(HWND,graphics*,int,int,int);
unit(HWND,graphics*,int,int,int,int,int);
unit(HWND,graphics*,DWORD,float, float, int, int, int);
unit(HWND,graphics*,DWORD,float, float, int, int, int, bool);
unit(unit*);
~unit();
DWORD sideColor(){return colors[0].getCode();}
int intAttack(){return attack;}
int intDefence(){return defence;}
float Attack(){return attack;}
float Defence(){return defence;}
int Moved(){return moved;}
void display(HDC); //display at crrent loc
void display(HDC, int, int); //display at specific loc
void display(HDC, int); //display with offset for stacking
void displayBig(HDC, int, int);
void change(HWND);
void update(HWND, coord);
coord nextCoord(char);
void mover(coord&, int);
void reset();
void tomark(); //marks unit for death;
bool marked(){return mark;}
coord getCoord(){return loc;}
coord getCurrent(){return currentLoc;}
bool canMove(){return canmove;}
bool isSelect(){return selected;}
bool inRange(coord);
void selectOn(){selected = true;}
void selectOff(){selected = false;}
void isArt(){range = 12;}
void cBoxOn(){combatBox = new tbox;};
void disbersed();
void unDisberse(){disburse = false;}
void write(std::ofstream&);
void load(std::ifstream&);
void addk(char k){kind = k;}
};
#endif