COMBAT: Classes


Object

class Object // Essentially a Circle
{
protected:
    double xpos,ypos,radius,angle;
    Player *creator;
public:
    Object(double x, double y, double r, double a, Player *p);
    Player *Creator();


    virtual void Move() = 0;
    virtual void Unmove() = 0;
    virtual void Draw(Player *p) = 0;
    
    void Undraw(Player *p);
    bool Contained( double x, double y, double w, double h);
    friend bool Intersect(Object *obj1, Object *obj2);
};

Rock

class Rock : public Object
{
public:
    Rock(double x, double y, double r);
    void Draw(Player *p);
    void Move();
    void Unmove();    
};

Tank

class Tank : public Object
{
public:
    Tank(double x, double y, double a, Player *p);
    void Draw(Player *p);
    void Move();
    void Unmove();
};

Shot

class Shot : public Object
{
public:
    Shot(double x, double y, double r, double a, Player *p);
    Shot( Object& obj );
    void Draw(Player *p );
    void Move();
    void Unmove();
};

ObjectStack

class ObjectStack
{
protected:
    Object *ObjectList[256];
    int     nObjects;
public:
    ObjectStack();
    Object *Peek(int pos);
    int Size();
    int Push(Object *obj);
    void Kill(int pos);
    void Draw(Player *p);
    void Undraw(Player *p);
    int FindCollisions(Object *obj);
};

Player

lass Player : public Console
{
protected:
    bool            forward;
    bool            backward;
    bool            left;
    bool            right;
    bool            hide;

    int             invisibility;    
    int             lives;
    int             shots;

    Tank           *tank;
public:    
    ~Player();
    Player(char *displaystring, int w, int h);

    bool hasShots();
    bool isAlive();
    bool isActive();
    bool isHidden();

    bool turnLeft();
    bool turnRight();
    bool moveForward();
    bool moveBackward();

    void EventHandler();

    void ShotKilled();
    void TankKilled();

    void UpdateTitle();
};

Rectangle

class Rectangle
{
protected:
	double x,y,w,h;
public:    
	Rectangle(double a, double b, double c, double d);
	void Draw(Player *p);
};

Text

class Text 
{
protected:
    char *text;
    int length;
    double x,y;
public:
    Text(char *t, int l, double a, double b);         
    void Draw(Player *p);
};

Console

enum Color {Default,Black,Blue,White,Red,Green,nColors};

enum Action {NoAction, Quit, Fire, Place, HideOn, HideOff, 
	     ForwardOn, ForwardOff, BackwardOn, BackwardOff, 
	     LeftOn, LeftOff, RightOn, RightOff};

class Console
{
private:
    Display         *display;
    int             screen;
    int             depth;
    Window          window;
    Pixmap          bitmap;
    XFontStruct     *font;
    GC              gc[nColors];

public:
    Console(char *displaystring, int w, int h);
    ~Console();
    void DrawText(char *text, int length, 
			double x, double y, Color color);
    void DrawLine(double x1, double y1, 
			double x2, double y2, Color color);
    void DrawRectangle(double x, double y, 
			double w, double h, Color color);
    void DrawFilledCircle(double x, double y, 
				double r, Color color);
    void DrawCircle(double x, double y, double r, Color color);
    void UpdateArea(double x, double y, double w, double h);
    void SetTitle(char *text);
    Action GetEvent();
    void Sync();
};