Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

ООП / ООП / 3-2 / unit_stuff

.h
Скачиваний:
8
Добавлен:
18.02.2017
Размер:
3.55 Кб
Скачать
//---------------------------------------------------------------------------

#ifndef unit_stuffH
#define unit_stuffH
#include <vector.h>

//---------------------------------------------------------------------------

class Elements;
class CBall;
class CLine;
class CTarget;
struct DPoint;

bool   AddBall(vector<Elements*>&, const DPoint&, const double&),
	 AddSupport(vector<Elements*>&, const DPoint&, const double&, const double&, const double&),
	 AddBorder(vector<Elements*>&, const DPoint&, const DPoint&),
	 AddTarget(vector<Elements*>&, const DPoint&, const DPoint&, const int&);

Elements* FindItem(Graphics::TCanvas*, const TPoint&, vector<Elements*>&);
void DrawAll(Graphics::TCanvas*, vector<Elements*>&);
void MoveItem(Elements*, const TPoint&);
void MoveIt(Graphics::TCanvas*, CBall*, vector<Elements*>&, const double&, const double&, const double&);

//---------------------------------------------------------------------------

struct DPoint{
	double x, y;
	DPoint(){};
	DPoint(const DPoint&);
	DPoint(const TPoint&);
	DPoint(const double&, const double&);
	double Distance();
	double Distance(const DPoint&);
	DPoint Normalize();
	bool operator==(const DPoint&) const;
	friend const DPoint operator+(const DPoint&, const DPoint&);
	friend const DPoint operator-(const DPoint&, const DPoint&);
	friend DPoint& operator+=(DPoint&, const DPoint&);
	bool operator!=(const DPoint&) const;
};

//---------------------------------------------------------------------------

class Elements{

public:
	virtual void Draw(Graphics::TCanvas*) = 0;
	virtual void Move(const DPoint&) = 0;
	virtual DPoint GetNormal(CBall*) = 0;
};

//---------------------------------------------------------------------------

class CSupport : public Elements{
	DPoint center;
	double a, b, angle, t;
public:
	CSupport(const DPoint&, const double&, const double&, const double&);
	void Draw(Graphics::TCanvas*);
    void Move(const DPoint&);
	void Rotate(const double&);
	void Resize(const double&, const double&, const double&);
	DPoint GetNormal(CBall*);

	friend Elements* FindItem(Graphics::TCanvas*, const TPoint&, vector<Elements*>&);
};

//---------------------------------------------------------------------------

class CLine : public Elements{
	DPoint p1, p2;
public:
	CLine(const DPoint&, const DPoint&);
	void Draw(Graphics::TCanvas*);
	void Move(const DPoint&);
	DPoint GetNormal(CBall*);
};

//---------------------------------------------------------------------------

class CTarget : public Elements{
	DPoint p1, p2;
	int count;
public:
	CTarget(const DPoint&, const DPoint&, const int&);
	void Draw(Graphics::TCanvas*);
	void Move(const DPoint&);
	double getHeight();
	double getWidth();
	DPoint GetNormal(CBall*);

	friend Elements* FindItem(Graphics::TCanvas*, const TPoint&, vector<Elements*>&);
};

//---------------------------------------------------------------------------

class CBall : public Elements{

public:
	DPoint center, v;
	double r;
	CBall(const DPoint&, const double&);
	void Draw(Graphics::TCanvas*);
	void Move(const DPoint&);
	DPoint GetNormal(CBall*);

	friend DPoint Elements::GetNormal(CBall*);
	friend DPoint CSupport::GetNormal(CBall*);
	friend DPoint CLine::GetNormal(CBall*);
	friend DPoint CTarget::GetNormal(CBall*);

	friend Elements* FindItem(Graphics::TCanvas*, const TPoint&, vector<Elements*>&);
};

//---------------------------------------------------------------------------

#endif
Соседние файлы в папке 3-2