回合游戏模型显卡驱动会导致死机吗游戏死机么

23865人阅读
设计模式(9)
在游戏开发过程中,我们避免不了创建各种各样的人物职业,及怪物。试想一下,我有几十个大分类,复杂的层次结构,那么这个创建过程怎么维护。
不错,我们可以使用工厂模式进行创建过程,大大简化了维护方面的困难。
开发游戏过程中一般都会有各种职业
& &&& &&Warrior 战士
& &&& &&Master 法师
& &&& &&Priest 牧师
& &&& &&Robber 盗贼
& &&& &&....
我们可以使用简单工厂模式解决此类问题。简单工厂模式,在一定程度上支持了开闭原则,当增加一种职业的时候符合开闭原则
& & & & 如下:
然而,如果是各种职业分了种族,试想一下,种族几个大分类,职业几个小分类等等,复杂的层次结构,那么这个工厂模式怎么维护。
& & & & 于是我们用到了抽象工厂模式
抽象工厂模式与工厂方法模式的区别
& & & & 抽象工厂模式是工厂方法模式的升级版本,他用来创建一组相关或者相互依赖的对象。他与工厂方法模式的区别就在于,工厂方法模式针对的是一个产品等级结构;而抽象工厂模式则是针对的多个产品等级结构。在编程中,通常一个产品结构,表现为一个接口或者抽象类,也就是说,工厂方法模式提供的所有产品都是衍生自同一个接口或抽象类,而抽象工厂模式所提供的产品则是衍生自不同的接口或抽象类。
& & & & 在抽象工厂模式中,有一个产品族的概念:所谓的产品族,是指位于不同产品等级结构中功能相关联的产品组成的家族。抽象工厂模式所提供的一系列产品就组成一个产品族;而工厂方法提供的一系列产品称为一个等级结构。
开发过程中,同样也会碰到各种怪物,并且各种不同的怪物又分等级(简单,一般,困难,或其它归类供玩家选择适合自己的娱乐)
同样,如果保证创建过程中不出错,不能在简单模式下创建困难的怪物,也不能在困难的模式下创建简单的物怪。
这样的话,游戏就完了。
这里同样我们也可以使用抽象工厂模式
整个工厂模式图
抽象工厂模式的优点
& & & & 抽象工厂模式除了具有工厂方法模式的优点外,最主要的优点就是可以在类的内部对产品族进行约束。所谓的产品族,一般或多或少的都存在一定的关联,抽象工厂模式就可以在类内部对产品族的关联关系进行定义和描述,而不必专门引入一个新的类来进行管理。
抽象工厂模式的缺点
& & & &产品族的扩展将是一件十分费力的事情,假如产品族中需要增加一个新的产品,则几乎所有的工厂类都需要进行修改。所以使用抽象工厂模式时,对产品等级结构的划分是非常重要的。
& & & &当需要创建的对象是一系列相互关联或相互依赖的产品族时,便可以使用抽象工厂模式。说的更明白一点,就是一个继承体系中,如果存在着多个等级结构(即存在着多个抽象类),并且分属各个等级结构中的实现类之间存在着一定的关联或者约束,就可以使用抽象工厂模式。假如各个等级结构中的实现类之间不存在关联或约束,则使用多个独立的工厂来对产品进行创建,则更合适一点。
运行结果:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
以后的笔记潇汀会尽量详细讲解一些相关知识的,希望大家继续关注我的博客。
本节笔记到这里就结束了。
潇汀一有时间就会把自己的学习心得,觉得比较好的知识点写出来和大家一起分享。
游戏开发的路很长很长,非常希望能和大家一起交流,共同学习,共同进步。
如果文章中有什么疏漏的地方,也请大家指正。也希望大家可以多留言来和我探讨编程相关的问题。
最后,谢谢你们一直的支持~~~
代码及下载地址
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
GAME_FACTORY_MonsterAbstractFactory.h
& @file & & GAME_FACTORY_MonsterAbstractFactory.h&
& @brief & & the abstract factory of Monster, use to create Monster (different level)
& @author & arvin
& @version 1.0 &
#ifndef CXX_GAME_FACTORY_MONSTERABSTRACTFACTORY_H
#define CXX_GAME_FACTORY_MONSTERABSTRACTFACTORY_H
class MonsterAbstractFactory
/************************************************************************/
/* & & & & & & & & & & & & & & & function & & & & & & & & & & & & & & & */
* Destruction
* @param VOID
* @return&
virtual ~MonsterAbstractFactory();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (different level)
virtual Monster* CreateMonsterA() = 0;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (different level)
virtual Monster* CreateMonsterB() = 0;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (different level)
virtual Monster* CreateMonsterC() = 0;
protected:
* Construction
* @param VOID
* @return&
MonsterAbstractFactory();
/************************************************************************/
/************************************************************************/
/* & & & & & & & & & & & & & & & member & & & & & & & & & & & & & & & & */
protected:
/************************************************************************/
#endif /* &&CXX_GAME_FACTORY_MONSTERABSTRACTFACTORY_H&& */
GAME_FACTORY_MonsterFactoryLevel1.h
& @file & & GAME_FACTORY_MonsterFactoryLevel1.h
& @brief & & the level 1 factory of Monster, use to create Monster (level 1)
& @author & arvin
& @version 1.0 &
#ifndef CXX_GAME_FACTORY_MONSTERFACTORYLEVEL1_H
#define CXX_GAME_FACTORY_MONSTERFACTORYLEVEL1_H
#ifndef CXX_GAME_FACTORY_MONSTERABSTRACTFACTORY_H
#include &GAME_FACTORY_MonsterAbstractFactory.h&
class MonsterFactoryLevel1 : public MonsterAbstractFactory
/************************************************************************/
/* & & & & & & & & & & & & & & & function & & & & & & & & & & & & & & & */
* Destruction
* @param VOID
* @return&
virtual ~MonsterFactoryLevel1();
* Instance
* @param VOID
* @return MonsterFactoryLevel1*
* @note singleton
static MonsterFactoryLevel1* Instance();
* @param VOID
* @return VOID
* @note singleton
static VOID Destroy();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 1)
virtual Monster* CreateMonsterA();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 1)
virtual Monster* CreateMonsterB();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 1)
virtual Monster* CreateMonsterC();
protected:
* Construction
* @param VOID
* @return&
MonsterFactoryLevel1();
/************************************************************************/
/************************************************************************/
/* & & & & & & & & & & & & & & & member & & & & & & & & & & & & & & & & */
protected:
static MonsterFactoryLevel1* m_pI
/************************************************************************/
#endif /* &&CXX_GAME_FACTORY_MONSTERFACTORYLEVEL1_H&& */
GAME_FACTORY_MonsterFactoryLevel2.h
& @file & & GAME_FACTORY_MonsterFactoryLevel1.h
& @brief & & the level 1 factory of Monster, use to create Monster (level 1)
& @author & arvin
& @version 1.0 &
#ifndef CXX_GAME_FACTORY_MONSTERFACTORYLEVEL1_H
#define CXX_GAME_FACTORY_MONSTERFACTORYLEVEL1_H
#ifndef CXX_GAME_FACTORY_MONSTERABSTRACTFACTORY_H
#include &GAME_FACTORY_MonsterAbstractFactory.h&
class MonsterFactoryLevel1 : public MonsterAbstractFactory
/************************************************************************/
/* & & & & & & & & & & & & & & & function & & & & & & & & & & & & & & & */
* Destruction
* @param VOID
* @return&
virtual ~MonsterFactoryLevel1();
* Instance
* @param VOID
* @return MonsterFactoryLevel1*
* @note singleton
static MonsterFactoryLevel1* Instance();
* @param VOID
* @return VOID
* @note singleton
static VOID Destroy();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 1)
virtual Monster* CreateMonsterA();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 1)
virtual Monster* CreateMonsterB();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 1)
virtual Monster* CreateMonsterC();
protected:
* Construction
* @param VOID
* @return&
MonsterFactoryLevel1();
/************************************************************************/
/************************************************************************/
/* & & & & & & & & & & & & & & & member & & & & & & & & & & & & & & & & */
protected:
static MonsterFactoryLevel1* m_pI
/************************************************************************/
#endif /* &&CXX_GAME_FACTORY_MONSTERFACTORYLEVEL1_H&& */
GAME_FACTORY_MonsterFactoryLevel3.h
& @file & & GAME_FACTORY_MonsterFactoryLevel3.h
& @brief & & the level 3 factory of Monster, use to create Monster (level 3)
& @author & arvin
& @version 1.0 &
#ifndef CXX_GAME_FACTORY_MONSTERFACTORYLEVEL3_H
#define CXX_GAME_FACTORY_MONSTERFACTORYLEVEL3_H
#ifndef CXX_GAME_FACTORY_MONSTERABSTRACTFACTORY_H
#include &GAME_FACTORY_MonsterAbstractFactory.h&
class MonsterFactoryLevel3 : public MonsterAbstractFactory
/************************************************************************/
/* & & & & & & & & & & & & & & & function & & & & & & & & & & & & & & & */
* Destruction
* @param VOID
* @return&
virtual ~MonsterFactoryLevel3();
* Instance
* @param VOID
* @return MonsterFactoryLevel3*
* @note singleton
static MonsterFactoryLevel3* Instance();
* @param VOID
* @return VOID
* @note singleton
static VOID Destroy();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 3)
virtual Monster* CreateMonsterA();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 3)
virtual Monster* CreateMonsterB();
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 3)
virtual Monster* CreateMonsterC();
protected:
* Construction
* @param VOID
* @return&
MonsterFactoryLevel3();
/************************************************************************/
/************************************************************************/
/* & & & & & & & & & & & & & & & member & & & & & & & & & & & & & & & & */
protected:
static MonsterFactoryLevel3* m_pI
/************************************************************************/
#endif /* &&CXX_GAME_FACTORY_MONSTERFACTORYLEVEL3_H&& */
GAME_FACTORY_ProfessionAbstractFactory.h
& @file & & GAME_FACTORY_ProfessionAbstractFactory.h
& @brief & & the abstract factory of profession, use to create the professions (different race)
& @author & arvin
& @version 1.0 &
#ifndef CXX_GAME_FACTORY_PROFESSIONABSTRACTFACTORY_H
#define CXX_GAME_FACTORY_PROFESSIONABSTRACTFACTORY_H
class ProfessionAbstractFactory
* Destruction
* @param VOID
* @return&
virtual ~ProfessionAbstractFactory();
* Create Warrior
* @param VOID
* @return Profession*
* @note use to create the Warrior (different race)
virtual Profession* CreateWarrior() = 0;
* Create Master
* @param VOID
* @return Profession*
* @note use to create the Master (different race)
virtual Profession* CreateMaster() = 0;
* Create Priest
* @param VOID
* @return Profession*
* @note use to create the Priest (different race)
virtual Profession* CreatePriest() = 0;
* Create Robber
* @param VOID
* @return Profession*
* @note use to create the Robber (different race)
virtual Profession* CreateRobber() = 0;
protected:
* Construction
* @param VOID
* @return&
ProfessionAbstractFactory();
#endif /* &&CXX_GAME_FACTORY_PROFESSIONABSTRACTFACTORY_H&& */
GAME_FACTORY_ProfessionFactoryHuman.h
& @file & & GAME_FACTORY_ProfessionFactoryHuman.h
& @brief & & the Human factory of profession, use to create the professions (Human)
& @author & arvin
& @version 1.0 &
#ifndef CXX_GAME_FACTORY_PROFESSIONFACTORYHUMAN_H
#define CXX_GAME_FACTORY_PROFESSIONFACTORYHUMAN_H
#ifndef CXX_GAME_FACTORY_PROFESSIONABSTRACTFACTORY_H
#include &GAME_FACTORY_ProfessionAbstractFactory.h&
class ProfessionFactoryHuman : public ProfessionAbstractFactory
/************************************************************************/
/* & & & & & & & & & & & & & & & function & & & & & & & & & & & & & & & */
* Destruction
* @param VOID
* @return&
virtual ~ProfessionFactoryHuman();
* Instance
* @param VOID
* @return ProfessionFactoryHuman*
* @note singleton
static ProfessionFactoryHuman* Instance();
* @param VOID
* @return VOID
* @note singleton
static VOID Destroy();
* Create Warrior
* @param VOID
* @return Profession*
* @note use to create the Warrior (Human)
virtual Profession* CreateWarrior();
* Create Master
* @param VOID
* @return Profession*
* @note use to create the Master (Human)
virtual Profession* CreateMaster();
* Create Priest
* @param VOID
* @return Profession*
* @note use to create the Priest (Human)
virtual Profession* CreatePriest();
* Create Robber
* @param VOID
* @return Profession*
* @note use to create the Robber (Human)
virtual Profession* CreateRobber();
protected:
* Construction
* @param VOID
* @return&
ProfessionFactoryHuman();
/************************************************************************/
/************************************************************************/
/* & & & & & & & & & & & & & & & member & & & & & & & & & & & & & & & & */
protected:
static ProfessionFactoryHuman* m_pI
/************************************************************************/
#endif /* &&CXX_GAME_FACTORY_PROFESSIONFACTORYHUMAN_H&& */
GAME_FACTORY_ProfessionFactoryOrc.h
& @file & & GAME_FACTORY_ProfessionFactoryOrc.h
& @brief & & the Orc factory of profession, use to create the professions (Orc)
& @author & arvin
& @version 1.0 &
#ifndef CXX_GAME_FACTORY_PROFESSIONFACTORYORC_H
#define CXX_GAME_FACTORY_PROFESSIONFACTORYORC_H
#ifndef CXX_GAME_FACTORY_PROFESSIONABSTRACTFACTORY_H
#include &GAME_FACTORY_ProfessionAbstractFactory.h&
class ProfessionFactoryOrc : public ProfessionAbstractFactory
/************************************************************************/
/* & & & & & & & & & & & & & & & function & & & & & & & & & & & & & & & */
* Destruction
* @param VOID
* @return&
virtual ~ProfessionFactoryOrc();
* Instance
* @param VOID
* @return ProfessionFactoryOrc*
* @note singleton
static ProfessionFactoryOrc* Instance();
* @param VOID
* @return VOID
* @note singleton
static VOID Destroy();
* Create Warrior
* @param VOID
* @return Profession*
* @note use to create the Warrior (Orc)
virtual Profession* CreateWarrior();
* Create Master
* @param VOID
* @return Profession*
* @note use to create the Master (Orc)
virtual Profession* CreateMaster();
* Create Priest
* @param VOID
* @return Profession*
* @note use to create the Priest (Orc)
virtual Profession* CreatePriest();
* Create Robber
* @param VOID
* @return Profession*
* @note use to create the Robber (Orc)
virtual Profession* CreateRobber();
protected:
* Construction
* @param VOID
* @return&
ProfessionFactoryOrc();
/************************************************************************/
/************************************************************************/
/* & & & & & & & & & & & & & & & member & & & & & & & & & & & & & & & & */
protected:
static ProfessionFactoryOrc* m_pI
/************************************************************************/
#endif /* &&CXX_GAME_FACTORY_PROFESSIONFACTORYORC_H&& */
GAME_FACTORY_ProfessionFactoryUndead.h
& @file & & GAME_FACTORY_ProfessionFactoryUndead.h
& @brief & & the Undead factory of profession, use to create the professions (Undead)
& @author & arvin
& @version 1.0 &
#ifndef CXX_GAME_FACTORY_PROFESSIONFACTORYUNDEAD_H
#define CXX_GAME_FACTORY_PROFESSIONFACTORYUNDEAD_H
#ifndef CXX_GAME_FACTORY_PROFESSIONABSTRACTFACTORY_H
#include &GAME_FACTORY_ProfessionAbstractFactory.h&
class ProfessionFactoryUndead : public ProfessionAbstractFactory
/************************************************************************/
/* & & & & & & & & & & & & & & & function & & & & & & & & & & & & & & & */
* Destruction
* @param VOID
* @return&
virtual ~ProfessionFactoryUndead();
* Instance
* @param VOID
* @return ProfessionFactoryUndead*
* @note singleton
static ProfessionFactoryUndead* Instance();
* @param VOID
* @return VOID
* @note singleton
static VOID Destroy();
* Create Warrior
* @param VOID
* @return Profession*
* @note use to create the Warrior (Undead)
virtual Profession* CreateWarrior();
* Create Master
* @param VOID
* @return Profession*
* @note use to create the Master (Undead)
virtual Profession* CreateMaster();
* Create Priest
* @param VOID
* @return Profession*
* @note use to create the Priest (Undead)
virtual Profession* CreatePriest();
* Create Robber
* @param VOID
* @return Profession*
* @note use to create the Robber (Undead)
virtual Profession* CreateRobber();
protected:
* Construction
* @param VOID
* @return&
ProfessionFactoryUndead();
/************************************************************************/
/************************************************************************/
/* & & & & & & & & & & & & & & & member & & & & & & & & & & & & & & & & */
protected:
static ProfessionFactoryUndead* m_pI
/************************************************************************/
#endif /* &&CXX_GAME_FACTORY_PROFESSIONFACTORYUNDEAD_H&& */
GAME_FACTORY_MonsterAbstractFactory.cpp
& @file & & GAME_FACTORY_MonsterAbstractFactory.h&
& @brief & & the abstract factory of Monster, use to create Monster (different level)
& @author & arvin
& @version 1.0 &
#include &stdafx.h&
#ifndef CXX_GAME_FACTORY_MONSTERABSTRACTFACTORY_H
#include &GAME_FACTORY_MonsterAbstractFactory.h&
* Construction
* @param VOID
* @return&
MonsterAbstractFactory::MonsterAbstractFactory()
* Destruction
* @param VOID
* @return&
MonsterAbstractFactory::~MonsterAbstractFactory()
GAME_FACTORY_MonsterFactoryLevel1.cpp
& @file & & GAME_FACTORY_MonsterFactoryLevel1.cpp
& @brief & & the level 1 factory of Monster, use to create Monster (level 1)
& @author & arvin
& @version 1.0 &
#include &stdafx.h&
#ifndef CXX_GAME_FACTORY_MONSTERFACTORYLEVEL1_H
#include &GAME_FACTORY_MonsterFactoryLevel1.h&
MonsterFactoryLevel1* MonsterFactoryLevel1::m_pInstance = NULL;
* Construction
* @param VOID
* @return&
MonsterFactoryLevel1::MonsterFactoryLevel1()
* Destruction
* @param VOID
* @return&
MonsterFactoryLevel1::~MonsterFactoryLevel1()
* Instance
* @param VOID
* @return MonsterFactoryLevel1*
* @note singleton
MonsterFactoryLevel1*&
MonsterFactoryLevel1::Instance()
if (NULL == m_pInstance) {
m_pInstance = new MonsterFactoryLevel1;
return m_pI
* @param VOID
* @return VOID
* @note singleton
MonsterFactoryLevel1::Destroy()
if (NULL != m_pInstance) {
delete m_pI
m_pInstance = NULL;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 1)
MonsterFactoryLevel1::CreateMonsterA()
return NULL;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 1)
MonsterFactoryLevel1::CreateMonsterB()
return NULL;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 1)
MonsterFactoryLevel1::CreateMonsterC()
return NULL;
GAME_FACTORY_MonsterFactoryLevel2.cpp
& @file & & GAME_FACTORY_MonsterFactoryLevel2.cpp
& @brief & & the level 2 factory of Monster, use to create Monster (level 2)
& @author & arvin
& @version 1.0 &
#include &stdafx.h&
#ifndef CXX_GAME_FACTORY_MONSTERFACTORYLEVEL2_H
#include &GAME_FACTORY_MonsterFactoryLevel2.h&
MonsterFactoryLevel2* MonsterFactoryLevel2::m_pInstance = NULL;
* Construction
* @param VOID
* @return&
MonsterFactoryLevel2::MonsterFactoryLevel2()
* Destruction
* @param VOID
* @return&
MonsterFactoryLevel2::~MonsterFactoryLevel2()
* Instance
* @param VOID
* @return MonsterFactoryLevel2*
* @note singleton
MonsterFactoryLevel2*&
MonsterFactoryLevel2::Instance()
if (NULL == m_pInstance) {
m_pInstance = new MonsterFactoryLevel2;
return m_pI
* @param VOID
* @return VOID
* @note singleton
MonsterFactoryLevel2::Destroy()
if (NULL != m_pInstance) {
delete m_pI
m_pInstance = NULL;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 2)
MonsterFactoryLevel2::CreateMonsterA()
return NULL;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 2)
MonsterFactoryLevel2::CreateMonsterB()
return NULL;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 2)
MonsterFactoryLevel2::CreateMonsterC()
return NULL;
GAME_FACTORY_MonsterFactoryLevel3.cpp
& @file & & GAME_FACTORY_MonsterFactoryLevel3.cpp
& @brief & & the level 3 factory of Monster, use to create Monster (level 3)
& @author & arvin
& @version 1.0 &
#include &stdafx.h&
#ifndef CXX_GAME_FACTORY_MONSTERFACTORYLEVEL3_H
#include &GAME_FACTORY_MonsterFactoryLevel3.h&
MonsterFactoryLevel3* MonsterFactoryLevel3::m_pInstance = NULL;
* Construction
* @param VOID
* @return&
MonsterFactoryLevel3::MonsterFactoryLevel3()
* Destruction
* @param VOID
* @return&
MonsterFactoryLevel3::~MonsterFactoryLevel3()
* Instance
* @param VOID
* @return MonsterFactoryLevel3*
* @note singleton
MonsterFactoryLevel3*&
MonsterFactoryLevel3::Instance()
if (NULL == m_pInstance) {
m_pInstance = new MonsterFactoryLevel3;
return m_pI
* @param VOID
* @return VOID
* @note singleton
MonsterFactoryLevel3::Destroy()
if (NULL != m_pInstance) {
delete m_pI
m_pInstance = NULL;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 3)
MonsterFactoryLevel3::CreateMonsterA()
return NULL;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 3)
MonsterFactoryLevel3::CreateMonsterB()
return NULL;
* Create Monster
* @param VOID
* @return Monster*
* @use to create Monster (level 3)
MonsterFactoryLevel3::CreateMonsterC()
return NULL;
GAME_FACTORY_ProfessionAbstractFactory.cpp
& @file & & GAME_FACTORY_ProfessionAbstractFactory.cpp
& @brief & & the abstract factory of profession, use to create the professions (different race)
& @author & arvin
& @version 1.0 &
#include &stdafx.h&
#ifndef CXX_GAME_FACTORY_PROFESSIONABSTRACTFACTORY_H
#include &GAME_FACTORY_ProfessionAbstractFactory.h&
* Construction
* @param VOID
* @return&
ProfessionAbstractFactory::ProfessionAbstractFactory()
* Destruction
* @param VOID
* @return&
ProfessionAbstractFactory::~ProfessionAbstractFactory()
GAME_FACTORY_ProfessionFactoryHuman.cpp
& @file & & GAME_FACTORY_ProfessionFactoryHuman.cpp
& @brief & & the Human factory of profession, use to create the professions (Human)
& @author & arvin
& @version 1.0 &
#include &stdafx.h&
#ifndef CXX_GAME_FACTORY_PROFESSIONFACTORYHUMAN_H
#include &GAME_FACTORY_ProfessionFactoryHuman.h&
ProfessionFactoryHuman* ProfessionFactoryHuman::m_pInstance = NULL;
* Construction
* @param VOID
* @return&
ProfessionFactoryHuman::ProfessionFactoryHuman()
* Destruction
* @param VOID
* @return&
ProfessionFactoryHuman::~ProfessionFactoryHuman()
* Instance
* @param VOID
* @return ProfessionFactoryHuman*
* @note singleton
ProfessionFactoryHuman*&
ProfessionFactoryHuman::Instance()
if (NULL == m_pInstance) {
m_pInstance = new ProfessionFactoryH
return m_pI
* @param VOID
* @return VOID
* @note singleton
ProfessionFactoryHuman::Destroy()
if (NULL != m_pInstance) {
delete m_pI
m_pInstance = NULL;
* Create Warrior
* @param VOID
* @return Profession*
* @note use to create the Warrior (Human)
Profession*&
ProfessionFactoryHuman::CreateWarrior()
return NULL;
* Create Master
* @param VOID
* @return Profession*
* @note use to create the Master (Human)
Profession*&
ProfessionFactoryHuman::CreateMaster()
return NULL;
* Create Priest
* @param VOID
* @return Profession*
* @note use to create the Priest (Human)
Profession*&
ProfessionFactoryHuman::CreatePriest()
return NULL;
* Create Robber
* @param VOID
* @return Profession*
* @note use to create the Robber (Human)
Profession*&
ProfessionFactoryHuman::CreateRobber()
return NULL;
GAME_FACTORY_ProfessionFactoryOrc.cpp
& @file & & GAME_FACTORY_ProfessionFactoryOrc.cpp
& @brief & & the Orc factory of profession, use to create the professions (Orc)
& @author & arvin
& @version 1.0 &
#include &stdafx.h&
#ifndef CXX_GAME_FACTORY_PROFESSIONFACTORYORC_H
#include &GAME_FACTORY_ProfessionFactoryOrc.h&
ProfessionFactoryOrc* ProfessionFactoryOrc::m_pInstance = NULL;
* Construction
* @param VOID
* @return&
ProfessionFactoryOrc::ProfessionFactoryOrc()
* Destruction
* @param VOID
* @return&
ProfessionFactoryOrc::~ProfessionFactoryOrc()
* Instance
* @param VOID
* @return ProfessionFactoryOrc*
* @note singleton
ProfessionFactoryOrc*&
ProfessionFactoryOrc::Instance()
if (NULL == m_pInstance) {
m_pInstance = new ProfessionFactoryO
return m_pI
* @param VOID
* @return VOID
* @note singleton
ProfessionFactoryOrc::Destroy()
if (NULL != m_pInstance) {
delete m_pI
m_pInstance = NULL;
* Create Warrior
* @param VOID
* @return Profession*
* @note use to create the Warrior (Orc)
Profession*&
ProfessionFactoryOrc::CreateWarrior()
return NULL;
* Create Master
* @param VOID
* @return Profession*
* @note use to create the Master (Orc)
Profession*&
ProfessionFactoryOrc::CreateMaster()
return NULL;
* Create Priest
* @param VOID
* @return Profession*
* @note use to create the Priest (Orc)
Profession*&
ProfessionFactoryOrc::CreatePriest()
return NULL;
* Create Robber
* @param VOID
* @return Profession*
* @note use to create the Robber (Orc)
Profession*&
ProfessionFactoryOrc::CreateRobber()
return NULL;
GAME_FACTORY_ProfessionFactoryUndead.cpp
& @file & & GAME_FACTORY_ProfessionFactoryUndead.cpp
& @brief & & the Undead factory of profession, use to create the professions (Undead)
& @author & arvin
& @version 1.0 &
#include &stdafx.h&
#ifndef CXX_GAME_FACTORY_PROFESSIONFACTORYUNDEAD_H
#include &GAME_FACTORY_ProfessionFactoryUndead.h&
ProfessionFactoryUndead* ProfessionFactoryUndead::m_pInstance = NULL;
* Construction
* @param VOID
* @return&
ProfessionFactoryUndead::ProfessionFactoryUndead()
* Destruction
* @param VOID
* @return&
ProfessionFactoryUndead::~ProfessionFactoryUndead()
* Instance
* @param VOID
* @return ProfessionFactoryUndead*
* @note singleton
ProfessionFactoryUndead*&
ProfessionFactoryUndead::Instance()
if (NULL == m_pInstance) {
m_pInstance = new ProfessionFactoryU
return m_pI
* @param VOID
* @return VOID
* @note singleton
ProfessionFactoryUndead::Destroy()
if (NULL != m_pInstance) {
delete m_pI
m_pInstance = NULL;
* Create Warrior
* @param VOID
* @return Profession*
* @note use to create the Warrior (Undead)
Profession*&
ProfessionFactoryUndead::CreateWarrior()
return NULL;
* Create Master
* @param VOID
* @return Profession*
* @note use to create the Master (Undead)
Profession*&
ProfessionFactoryUndead::CreateMaster()
return NULL;
* Create Priest
* @param VOID
* @return Profession*
* @note use to create the Priest (Undead)
Profession*&
ProfessionFactoryUndead::CreatePriest()
return NULL;
* Create Robber
* @param VOID
* @return Profession*
* @note use to create the Robber (Undead)
Profession*&
ProfessionFactoryUndead::CreateRobber()
return NULL;
GameFactory.cpp (Main文件)
// GameFactory.cpp : Defines the entry point for the console application.
#include &stdafx.h&
#ifndef CXX_GAME_FACTORY_MONSTERFACTORYLEVEL1_H
#include &GAME_FACTORY_MonsterFactoryLevel1.h&
#ifndef CXX_GAME_FACTORY_MONSTERFACTORYLEVEL2_H
#include &GAME_FACTORY_MonsterFactoryLevel2.h&
#ifndef CXX_GAME_FACTORY_MONSTERFACTORYLEVEL3_H
#include &GAME_FACTORY_MonsterFactoryLevel3.h&
#ifndef CXX_GAME_FACTORY_PROFESSIONFACTORYHUMAN_H
#include &GAME_FACTORY_ProfessionFactoryHuman.h&
#ifndef CXX_GAME_FACTORY_PROFESSIONFACTORYORC_H
#include &GAME_FACTORY_ProfessionFactoryOrc.h&
#ifndef CXX_GAME_FACTORY_PROFESSIONFACTORYUNDEAD_H
#include &GAME_FACTORY_ProfessionFactoryUndead.h&
MonsterAbstractFactory*&
GetMonsterFactory()
//Monster Factory
static int i = 0;
i++;
if (3 == i) {
if (0 == i) {
return MonsterFactoryLevel1::Instance();
else if (1 == i) {
return MonsterFactoryLevel2::Instance();
else if (2 == i) {
return MonsterFactoryLevel3::Instance();
return NULL;
ProfessionAbstractFactory*&
GetProfessionFactory()
//Profession Factory
static int i = 0;
i++;
if (3 == i) {
if (0 == i) {
return ProfessionFactoryHuman::Instance();
else if (1 == i) {
return ProfessionFactoryOrc::Instance();
else if (2 == i) {
return ProfessionFactoryUndead::Instance();
return NULL;
int _tmain(int argc, _TCHAR* argv[])
Monster* pMonsterTemp = NULL;
for (int i=0; i&3; i++)
MonsterAbstractFactory* pMonsterFactory = GetMonsterFactory();
if (NULL == pMonsterFactory) {
//error do something
pMonsterTemp = pMonsterFactory-&CreateMonsterA();
pMonsterTemp = pMonsterFactory-&CreateMonsterB();
pMonsterTemp = pMonsterFactory-&CreateMonsterC();
//Profession
Profession* pProfessionTemp = NULL;
for (int i=0; i&3; i++)
ProfessionAbstractFactory* pProfessionFactory = GetProfessionFactory();
if (NULL == pProfessionFactory) {
//error do something
pProfessionTemp = pProfessionFactory-&CreateWarrior();
pProfessionTemp = pProfessionFactory-&CreateMaster();
pProfessionTemp = pProfessionFactory-&CreatePriest();
pProfessionTemp = pProfessionFactory-&CreateRobber();
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3369985次
积分:20565
积分:20565
排名:第865名
原创:63篇
转载:84篇
评论:50条
文章:25篇
阅读:1043575
阅读:248324
(3)(18)(26)(2)(1)(6)(9)(17)(36)(2)(1)(3)(6)(3)(5)(9)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'}

我要回帖

更多关于 静电会导致手机死机吗 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信