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 ...
随机推荐
- 解决HUE报错MultipleObjectsReturned: get() returned more than one Document2 -- it returned 2!
表现:界面上报错:,刚登陆进去就能看到,点击执行也会出现.日志里报: Traceback (most recent call last): File "/home/work/hue-3.10 ...
- Linux环境MySQL集群配置
一.介绍 ======== 这篇文档旨在介绍如何安装配置基于2台服务器的MySQL集群.并且实现任意一台服务器出现问题或宕机时MySQL依然能够继续运行. 注意! 虽 然这是基于2台服务器的MySQL ...
- 数学图形(1.39)TN constant curve
这是个类似巴黎铁塔的曲线. #http://www.mathcurve.com/courbes2d/tn/tn.shtml vertices = t = to (PI*0.999) a = s = s ...
- [转]DICOM医学图像处理:Deconstructed PACS之Orthanc
转载:http://blog.csdn.net/zssureqh/article/details/41424027 背景: 此篇博文介绍一个开源的.基于WEB的DICOM Server软件.该开源软件 ...
- java学习笔记5--类的方法
接着前面的学习: java学习笔记4--类与对象的基本概念(2) java学习笔记3--类与对象的基本概念(1) java学习笔记2--数据类型.数组 java学习笔记1--开发环境平台总结 本文地址 ...
- java 中 SVN 设置所有文件及子目录 needs-lock, svn 提交时自动设置 needs-lock, 及版本不一致问题
摘自: http://my.oschina.net/zhangzhihao/blog/72177 设置后的效果:文件会自动带上svn:needs-lock属性,默认是只读的要签出才能修改以防止修改完后 ...
- Android -- 动态添加布局
在做项目的时候,遇到了scrollView与listView结合的使用,导致了滑动的混乱,但是有一个办法可以解决掉这个问题,就是手写listView的高度,还有另外一种方法,传送门:<Andro ...
- 【Linux】shell字符串分割、数组访问、条件判断
参考资料: shell字符串分割再循环:http://www.shangxueba.com/jingyan/1633455.html linux shell中 if else以及大于.小于.等于逻辑表 ...
- Xamarin C# Android for Windows 安装
Xamarin C# Android for Windows 安装 Xamarin的. Android手动安装 安装Xamarin的 Android在Windows机器上 大多数时候,Xama ...
- 用C#读取图片的EXIF信息的方法
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Dr ...