#include <windows.h>
#include <tchar.h>
#include <typeinfo>
#include <iostream>
using namespace std;
class SpaceShip;
class SpaceStation;
class Asteriod;
class GameObject
{
public:
virtual void Collide(GameObject& otherObject) = 0;
public:
virtual void Collide(SpaceShip& otherObject) = 0;
virtual void Collide(SpaceStation& otherObject) = 0;
virtual void Collide(Asteriod& otherObject) = 0;
virtual ~GameObject();
};
class SpaceShip: public GameObject
{
public:
virtual void Collide(GameObject& otherObject);
public:
virtual void Collide(SpaceShip& otherObject);
virtual void Collide(SpaceStation& otherObject);
virtual void Collide(Asteriod& otherObject);
};
class SpaceStation: public GameObject
{
public:
virtual void Collide(GameObject& otherObject);
public:
virtual void Collide(SpaceShip& otherObject);
virtual void Collide(SpaceStation& otherObject);
virtual void Collide(Asteriod& otherObject);
};
class Asteriod: public GameObject
{
public:
virtual void Collide(GameObject& otherObject);
public:
virtual void Collide(SpaceShip& otherObject);
virtual void Collide(SpaceStation& otherObject);
virtual void Collide(Asteriod& otherObject);
};
GameObject::~GameObject()
{
}
void SpaceShip::Collide(GameObject& otherObject)
{
otherObject.Collide(*this);
}
void SpaceShip::Collide(SpaceShip& otherObject)
{
cout << "The space ship is colliding with a space ship";
cout << endl;
}
void SpaceShip::Collide(SpaceStation& otherObject)
{
cout << "The space ship is colliding with a space station";
cout << endl;
}
void SpaceShip::Collide(Asteriod& otherObject)
{
cout << "The space ship is colliding with a asteriod";
cout << endl;
}
void SpaceStation::Collide(GameObject& otherObject)
{
otherObject.Collide(*this);
}
void SpaceStation::Collide(SpaceShip& otherObject)
{
cout << "The space station is colliding with a space ship";
cout << endl;
}
void SpaceStation::Collide(SpaceStation& otherObject)
{
cout << "The space station is colliding with a space station";
cout << endl;
}
void SpaceStation::Collide(Asteriod& otherObject)
{
cout << "The space station is colliding with a asteriod";
cout << endl;
}
void Asteriod::Collide(GameObject& otherObject)
{
otherObject.Collide(*this);
}
void Asteriod::Collide(SpaceShip& otherObject)
{
cout << "The space ship is colliding with a space ship";
cout << endl;
}
void Asteriod::Collide(SpaceStation& otherObject)
{
cout << "The space ship is colliding with a space station";
cout << endl;
}
void Asteriod::Collide(Asteriod& otherObject)
{
cout << "The space ship is colliding with a asteriod";
cout << endl;
}
int _tmain (int argc, _TCHAR* argv[])
{
GameObject *p1;
GameObject *p2;
SpaceShip ship;
SpaceStation station;
Asteriod asteriod;
p1 = &ship;
p2 = &ship; p1->Collide(*p2);
p2 = &station; p1->Collide(*p2);
p2 = &asteriod; p1->Collide(*p2);
return 0;
}
The space ship is colliding with a space ship
The space station is colliding with a space ship
The space ship is colliding with a space ship