设为首页 加入收藏

TOP

仿《雷霆战机》飞行射击手游开发--新手引导(三)
2017-10-13 10:14:57 】 浏览:3252
Tags:《雷霆战机》 飞行 射击 开发 新手 引导
nction<bool()>> m_condMap; std::map<int, std::function<Guide*()>> m_createMap; std::map<int, Guide*> m_objectMap; int m_iCnt; static GuideMgr* m_pInstance; };

  

GuideMgr* GuideMgr::m_pInstance = nullptr;

GuideMgr* GuideMgr::getInstance()
{
	if (!m_pInstance)
	{
		m_pInstance = new GuideMgr();
	}

	return m_pInstance;
}

GuideMgr::GuideMgr()
 : m_iCnt(0)
{

}

bool GuideMgr::registerFunc(int type, const std::function<bool()>& checkFunc, const std::function<Guide*()>& createFunc)
{
	m_condMap.insert(std::map<int, std::function<bool()>>::value_type(type, checkFunc));
	m_createMap.insert(std::map<int, std::function<Guide*()>>::value_type(type, createFunc));

	return true;
}

Guide* GuideMgr::show(int guideType, Node* parent, Node* widget, const std::function<void()>& callback)
{
	if (hasGuide())
	{
		return nullptr;
	}

	auto itCond = m_condMap.find(guideType);
	auto itCreate = m_createMap.find(guideType);
	if (itCond != m_condMap.end() && itCreate != m_createMap.end())
	{
		if (itCond->second())
		{
			Guide* pGuide = itCreate->second();
			pGuide->autorelease();

			if (pGuide)
			{
				auto it = m_objectMap.find(guideType);
				if (it != m_objectMap.end())
				{
					m_objectMap.erase(it);
				}
				m_objectMap.insert(std::map<int, Guide*>::value_type(guideType, pGuide));
				return pGuide->show(guideType, parent, widget, callback);
			}
		}
	}

	return nullptr;
}

bool GuideMgr::destory(int GuideType)
{
	auto it = m_objectMap.find(GuideType);
	if (it != m_objectMap.end())
	{
		it->second->restore();
		m_objectMap.erase(it);

		return true;
	}
	else
	{
		return false;
	}
	
}

void GuideMgr::incGuideCnt()
{ 
	++m_iCnt; 
}

void GuideMgr::decGuideCnt()
{ 
	--m_iCnt; 
	if (m_iCnt < 0)
	{
		m_iCnt = 0;
	}
}

bool GuideMgr::hasGuide()
{ 
	return m_iCnt > 0; 
}

没啥好说的,一个单例,两个map变量(m_condMap/m_createMap),通过引导类型来查找对应引导的条件判断和创建函数,然后创建Guide,并保存到m_objectMap中。

 

  好了,本游戏中的新手引导相关设计介绍完了,当然这并不是一个最好的设计,如果有好的设计和模式,希望能一起讨论。

 

本文涉及的相关代码下载:guide.rar

有任何疑问可联系:thorqq@163.com

转载请注明:http://www.cnblogs.com/thorqq/p/6403666.html 

首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇13:图像模糊处理 下一篇ReplaceChar

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目