CGameConfig类
#ifndef __GAMECONFIG_H__
#define __GAMECONFIG_H__ #include "GameFrameHead.h"
#include "GameParam.h" //生物配置
struct BiontInfo
{
int nId;
int nType; //生物类型
CCRect rArea; //生物活动区域
int nBulk; //体积
int nWeight; //重量 string strFile; //贴图文件
string strAudio; //声音文件
string strAction; //动作
int nTag; //标签
string strLap;
int nDirect; //方向 enum DirectType
{
_Normal = ,
_Reverse =,
_Both = ,
}; }; struct MapInfo
{
int nId;
vector<CCPoint> foundationPos;
vector<CCPoint> path; }; class CGameConfig
{
public:
~CGameConfig(); static CGameConfig* getInstance();
static void destroy();
void release(); //设置资源路径 一开始就要设定
void setResourcePath(const char* psPath);
string getResourcePath();
public: bool loadBiontInfo(); //生物配置
bool loadMapInfo(); //地图配置 vector<BiontInfo>* getBiontInfo();
BiontInfo* getBiontInfoByType(int nType); map<int, MapInfo>* getMapInfo();
MapInfo* getMapInfoById(int nId); private:
CGameConfig();
private:
static CGameConfig* g_pGameConfig;
string m_strResourcePath; private: //生物配置标识
vector<BiontInfo> m_vecBiontInfo; //地图配置
map<int, MapInfo> m_mapMapInfo; }; #endif //__GAMECONFIG_H__
#include "GameConfig.h"
#include "XXmlReader.h"
#include "XEncryptAccess.h"
#include "XCommon.h" CGameConfig* CGameConfig::g_pGameConfig = NULL; CGameConfig::CGameConfig()
{ } CGameConfig::~CGameConfig()
{ } CGameConfig* CGameConfig::getInstance()
{
if (!g_pGameConfig)
{
g_pGameConfig = new CGameConfig();
}
return g_pGameConfig;
} void CGameConfig::destroy()
{
SAFE_DELETE(g_pGameConfig);
} void CGameConfig::release()
{ } void CGameConfig::setResourcePath( const char* psPath )
{
m_strResourcePath = psPath;
} string CGameConfig::getResourcePath()
{
return m_strResourcePath;
} bool CGameConfig::loadBiontInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/biont.xml"; //读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc); if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
} do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
} if( != xmlStrcmp(BAD_CAST "bionts", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pCurNode = pRootNode->xmlChildrenNode;
while (NULL != pCurNode)
{
if ( != xmlStrcmp(pCurNode->name, BAD_CAST "biont"))
{
pCurNode = pCurNode->next;
continue;
} BiontInfo info;
info.nType = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "type");
info.strFile = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "file");
info.strAudio = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "audio");
info.nBulk = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "bulk");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCurNode,"area");
int nX, nY, nW, nH;
sscanf(strBuf.c_str(),"%d %d %d %d",&nX, &nY, &nW, &nH);
info.rArea = CCRect(nX,nY,nW,nH);
info.strAction = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "action");
info.nTag = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "tag");
info.strLap = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "lap");
info.nDirect = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "direct"); m_vecBiontInfo.push_back(info); pCurNode = pCurNode->next;
} xmlFreeDoc(pDoc);
return true; } while (); xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
} vector<BiontInfo>* CGameConfig::getBiontInfo()
{
return &m_vecBiontInfo;
} BiontInfo* CGameConfig::getBiontInfoByType( int nType )
{
for (vector<BiontInfo>::iterator it = m_vecBiontInfo.begin(); it != m_vecBiontInfo.end(); it++)
{
if (nType == it->nType)
{
return &(*it);
}
}
CCLog("error: CGameConfig::getBiontInfoByType");
return NULL;
} bool CGameConfig::loadMapInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/map.xml"; //读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc); if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
} do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
} if( != xmlStrcmp(BAD_CAST "maps", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pElement = pRootNode->xmlChildrenNode;
while (NULL != pElement)
{
if ( == xmlStrcmp(pElement->name, BAD_CAST "map"))
{
MapInfo mapInfo;
mapInfo.nId = CCXmlReader::getXMLNodeAttribInt(&pElement, "id"); vector<string> vecData;
CXCommon::split(CCXmlReader::getXMLNodeAttribStrs(&pElement, "data"), string(";"), vecData);
for (unsigned int i = ; i < vecData.size(); i++)
{
vector<string> vecPos;
CXCommon::split(vecData[i], string(","), vecPos);
if (!vecPos.empty())
{
mapInfo.foundationPos.push_back(CCPoint(atof(vecPos[].c_str()), atof(vecPos[].c_str())));
}
} vector<string> vecPath;
CXCommon::split(CCXmlReader::getXMLNodeAttribStrs(&pElement, "path"), string(";"), vecPath);
for (unsigned int i = ; i < vecPath.size(); i++)
{
vector<string> vecPos;
CXCommon::split(vecPath[i], string(","), vecPos);
if (!vecPos.empty())
{
mapInfo.path.push_back(CCPoint(atof(vecPos[].c_str()), atof(vecPos[].c_str())));
}
} m_mapMapInfo[mapInfo.nId] = mapInfo;
}
pElement = pElement->next;
}
xmlFreeDoc(pDoc);
return true;
} while (); xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
} map<int, MapInfo>* CGameConfig::getMapInfo()
{
return &m_mapMapInfo;
} MapInfo* CGameConfig::getMapInfoById( int nId )
{
for (map<int, MapInfo>::iterator it = m_mapMapInfo.begin(); it != m_mapMapInfo.end(); it++)
{
if (nId == it->first)
{
return &(it->second);
}
}
CCLog("error: CGameConfig::getMapInfoById");
return NULL;
}
CGameConfig类的更多相关文章
- Java类的继承与多态特性-入门笔记
相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...
- C++ 可配置的类工厂
项目中常用到工厂模式,工厂模式可以把创建对象的具体细节封装到Create函数中,减少重复代码,增强可读和可维护性.传统的工厂实现如下: class Widget { public: virtual i ...
- Android请求网络共通类——Hi_博客 Android App 开发笔记
今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库
在这一章中,我们将直接进入项目,并且为产品和分类添加一些基本的模型类.我们将在Entity Framework的代码优先模式下,利用这些模型类创建一个数据库.我们还将学习如何在代码中创建数据库上下文类 ...
- ASP.NET Core 折腾笔记二:自己写个完整的Cache缓存类来支持.NET Core
背景: 1:.NET Core 已经没System.Web,也木有了HttpRuntime.Cache,因此,该空间下Cache也木有了. 2:.NET Core 有新的Memory Cache提供, ...
- .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类
.NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件功能比较简单,有的则比较复杂,并且依赖其它组件.除 ...
- Java基础Map接口+Collections工具类
1.Map中我们主要讲两个接口 HashMap 与 LinkedHashMap (1)其中LinkedHashMap是有序的 怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...
- PHP-解析验证码类--学习笔记
1.开始 在 网上看到使用PHP写的ValidateCode生成验证码码类,感觉不错,特拿来分析学习一下. 2.类图 3.验证码类部分代码 3.1 定义变量 //随机因子 private $char ...
- C# 多种方式发送邮件(附帮助类)
因项目业务需要,需要做一个发送邮件功能,查了下资料,整了整,汇总如下,亲测可用- QQ邮箱发送邮件 #region 发送邮箱 try { MailMessage mail = new MailMess ...
随机推荐
- iOS:转载FMDB文档
来自会员pengtao的分享:(原文:https://github.com/ccgus/fmdb) 由于FMDB是建立在SQLite的之上的,所以你至少也该把这篇文章从头到尾读一遍.与此同时,把SQL ...
- split-array-largest-sum(参考了discuss)
注意,第一种用法,涉及到一些Java的知识.就是采用Object作为HashMap的key的时候,需要重载这个Class的 equals 和 hashCode 这两个方法.其中equals需要判断一下 ...
- SQL INNER JOIN
A INNER JOIN command is queries that combine data from more than 1 table.For two tables that want to ...
- pjsip视频通信开发(底层实现)之用户注册(1)
一.PJSIP简介 对于pjsip的介绍可以看http://www.cnblogs.com/my_life/articles/2175462.html 文章,里面详细介绍了它的组成框架以及各部份的组成 ...
- 如何在Visual Studio(VS)2012里使用libsvm工具箱
原文:http://blog.csdn.net/u014691453/article/details/40393137 软件版本: Visual Studio版本:VS2012 (注:使用方法在 VS ...
- Myeclipse最全快捷键
转自:http://www.iteye.com/topic/1051317 Ctrl+1 快速修复(最经典的快捷键,就不用多说了) Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一 ...
- (剑指Offer)面试题52:构建乘积数组
题目: 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1].不能 ...
- 9款HTML5实现的超酷特效
之前我们推荐了8款HTML5实现的特效和应用,今天我们带来的这9款热门的HTML5特效同样会带给你全新的视角和体验. HTML5是HTML的升级版,HTML5有两大特点:首先,强化了 Web 网页的表 ...
- discuz,ecshop的伪静态规则(apache+nginx)
discuz(nginx): (备注:该规则也适用于二级目录) rewrite ^([^\.]*)/topic-(.+)\.html$ $/portal.php?mod=topic&topic ...
- 转:介绍shell_notifyicon,SendMessage,CallWindowProc,GetWindowLong,SetWindowLong的用法
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias " Shell_NotifyIconA& ...