这是我写的游戏代码片段 先发一个游戏对象基类 以后慢慢发完 //======================================================== /** * @file Objunit.hpp * * 项目描述: 构造游戏引擎 * 文件描述: 游戏对象基类 * 适用平台: Windows/Lunix/Unitx/.. * * 作者: ccsdu2004 * 电子邮件: ccsdu2004@yahoo.com.cn * 网址 : www.gaimo.net/ hi/csdn.net/ccsdu2004 * 创建日期: 2009-04-11 * 修改日期: .. * */ //======================================================== #ifndef G_OBJ_OBJUNIT_HPP #define G_OBJ_OBJUNIT_HPP #include <string> using namespace std; namespace g { namespace obj { //@定义游戏对象基类 /* 所有游戏对象都要继承之 */ /* 当该类析构的时候就把其索引设置为0 */ class ObjUnit { public: ObjUnit(); virtual ~ObjUnit(); public: //获取当前对象索引 unsigned int Index(); //获取当前对象类型 string GetObjType()const; //检测两个对象是不是同一类型 bool IsSameObj(ObjUnit *unit)const; protected: //设置当前对象类型 virtual void SetObjType(string type); protected: static unsigned int refcnt; unsigned int index; string type; }; //重载函数 检测对象是不是同一类型 bool IsSameObj(ObjUnit *unit1, ObjUnit *uni2); bool IsSameObj(const ObjUnit &unit1, ObjUnit &unit2); //宏定义 #define REGISTER_OBJ_NAME(unit) g::obj::ObjUnit::SetObjType(#unit); } } #endif