NPC框架

#include <iostream>
#include "NPC.h"

using namespace std;


void main()
{
	Girl_Sword_NPC buildGirl;
	NPC* pGirlNPC = buildGirl.Create_Girl_Sword_NPC();
	pGirlNPC->recvState(0);
	pGirlNPC->Show();
	pGirlNPC->recvState(2);
	pGirlNPC->Show();
	delete pGirlNPC;

	Boy_Sword_NPC buildBoy;
	NPC* pBoyNPC = buildBoy.Create_Girl_Sword_NPC();
	pBoyNPC->recvState(0);
	pBoyNPC->Show();
	pBoyNPC->recvState(2);
	pBoyNPC->Show();
	delete pBoyNPC;

	system("pause");
}

 
#include <iostream>
#include <map>
#include <string.h>


using namespace std;


class NPC
{
public:
	//收到转换状态
	virtual void recvState(int _iID){ m_dCurStateID = _iID; }
	//显示
	virtual void Show()
	{
		string szText = m_dStateSet[m_dCurStateID];
		cout<<"当前状态 \""<<szText.c_str()<<"\""<<endl;
	}
private:
	NPC():m_dCurStateID(-1){}
	map<int, string> m_dStateSet;
	int m_dCurStateID;
	friend class NPCBuilder;
};



//NPC创建者
class NPCBuilder
{//建造者,对客户屏蔽目标的内部生成功能,暂时提供外部的生成选择,过后只提供目标的使用功能的权限。
public:
	//创建NPC
	void Build_NPC(){ m_pNPC = new NPC();}
	//施放火球攻击法术状态
	void Build_FireBallMagicState(string szMagic){ m_pNPC->m_dStateSet[0] = szMagic; }
	//被攻击状态
	void Build_BeAttackedState(string szBeAttacked){ m_pNPC->m_dStateSet[1] = szBeAttacked; }
	//搜索AI
	void Build_AIEngine(string szSearchAI){ m_pNPC->m_dStateSet[2] = szSearchAI; }
	//获得NPC
	NPC* Get_NPC(){ return m_pNPC; }
private:
	NPC* m_pNPC;
};


//女剑士_NPC   
class Girl_Sword_NPC  
{ 
public:
	static NPC* Create_Girl_Sword_NPC()
	{
		NPCBuilder builder;
		builder.Build_NPC();
		builder.Build_FireBallMagicState("女式火球攻击术");
		builder.Build_BeAttackedState("女式被攻击状态");
		builder.Build_AIEngine("女式搜索AI");
		return builder.Get_NPC();
	}
};

//男剑士_NPC   
class Boy_Sword_NPC  
{ 
public:
	static NPC* Create_Girl_Sword_NPC()
	{
		NPCBuilder builder;
		builder.Build_NPC();
		builder.Build_FireBallMagicState("男式火球攻击术");
		builder.Build_BeAttackedState("男式被攻击状态");
		builder.Build_AIEngine("男式搜索AI");
		return builder.Get_NPC();
	}
};

你可能感兴趣的:(NPC框架)