#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类的更多相关文章

  1. Java类的继承与多态特性-入门笔记

    相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...

  2. C++ 可配置的类工厂

    项目中常用到工厂模式,工厂模式可以把创建对象的具体细节封装到Create函数中,减少重复代码,增强可读和可维护性.传统的工厂实现如下: class Widget { public: virtual i ...

  3. Android请求网络共通类——Hi_博客 Android App 开发笔记

    今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...

  4. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库

    在这一章中,我们将直接进入项目,并且为产品和分类添加一些基本的模型类.我们将在Entity Framework的代码优先模式下,利用这些模型类创建一个数据库.我们还将学习如何在代码中创建数据库上下文类 ...

  5. ASP.NET Core 折腾笔记二:自己写个完整的Cache缓存类来支持.NET Core

    背景: 1:.NET Core 已经没System.Web,也木有了HttpRuntime.Cache,因此,该空间下Cache也木有了. 2:.NET Core 有新的Memory Cache提供, ...

  6. .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类

    .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件功能比较简单,有的则比较复杂,并且依赖其它组件.除 ...

  7. Java基础Map接口+Collections工具类

    1.Map中我们主要讲两个接口 HashMap  与   LinkedHashMap (1)其中LinkedHashMap是有序的  怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...

  8. PHP-解析验证码类--学习笔记

    1.开始 在 网上看到使用PHP写的ValidateCode生成验证码码类,感觉不错,特拿来分析学习一下. 2.类图 3.验证码类部分代码 3.1  定义变量 //随机因子 private $char ...

  9. C# 多种方式发送邮件(附帮助类)

    因项目业务需要,需要做一个发送邮件功能,查了下资料,整了整,汇总如下,亲测可用- QQ邮箱发送邮件 #region 发送邮箱 try { MailMessage mail = new MailMess ...

随机推荐

  1. koa2搭建服务器+使用mongoose链接mangodb

    使用node搭建服务器,用到了现在比较流行的框架koa. 1.初始化package.json npm init -y 2.安装koa2 npm i koa --save 3.搭建服务器 const K ...

  2. iOS: xcode打包上传iTunes失败,iTunes Store operation failed,this action can not complete .try again

    通过xcode点击“upload to app store”上传到itunes,结果一直提示“itunes store operation failed” 原因:网速的问题,我之前也遇到过,网速好的时 ...

  3. FFmpeg的使用——PHP转换视频、截取视频以及JW Player播放器控制

    转载:http://blog.csdn.net/zm2714/article/details/7916440 给朋友做的一个项目中,涉及到上传视频.转换视频.自动截取已上传视频内容中的一帧做为缩略图片 ...

  4. Windows2003 Webshell默认权限

    0×00 前言 0×01 Windows2003默认配置 0×02 Windows2003典型配置的权限 0×03 cmd运行的条件   0×00 前言 这一章主要讲解关于我们刚拿到webshell的 ...

  5. MySQL for Mac安装和启动

    MySQL for Mac安装和启动 学习了:https://blog.csdn.net/a380880304/article/details/49840139 注意密码是数字1还是字母l: 系统提示 ...

  6. Android studio DrawerLayout

    网上开源项目地址:https://github.com/ikimuhendis/LDrawer 效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvQW ...

  7. jQuery几个经典表单应用整理回想

    1.文本框获得(失去)焦点 当文本框获得输入焦点时,将该文本框高亮显示,算不得一个应用.仅仅是一个小技巧,能够提高用户体验. [html] view plaincopy <span style= ...

  8. angularjs中的数据绑定

    这是一个最简单的angularjs的例子,关于数据绑定的,大家可以执行一下,看看效果 <html ng-app> <head> <title>angularjs-i ...

  9. 【Unity优化】怎样实现Unity编辑器中的协程

    Unity编辑器中何时须要协程 当我们定制Unity编辑器的时候,往往须要启动额外的协程或者线程进行处理.比方当运行一些界面更新的时候,须要大量计算,假设用户在不断修正一个參数,比方从1变化到2.这种 ...

  10. HDU4300-Clairewd’s message(KMP前缀匹配后缀)

    Clairewd's message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...