#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. jQuery 对象和 DOM 对象

    jQuery(DOM对象) 或者 $(DOM对象) 此函数的作用是将DOM对象,转换为jQuery的对象 DOM对象其实就是javascript的函数对象,可以用来操作所有HTML元素.比如: a标签 ...

  2. Jenkins自动部署到(远程)tomcat服务器

    Jenkins的流程: 1.从版本控制中获取代码 ->2. 使用maven编译生成相应的包(jar,war) ->3. 部署到指定的地点. 其中2.主要是解决依赖的问题,或许你需要先mvn ...

  3. #pragma详细解释(一)

    #pragma详细解释 #pragma详细解释(一) 2010-04-18 14:21:00|  分类: 默认分类 |  标签: |字号大中小订阅     在#Pragma是预处理指令它的作用是设定编 ...

  4. java中的深浅克隆

    假设有一个对象object,在某处又需要一个跟object一样的实例object2,强调的是object和object2是两个独立的实例,只是在开始的时候,他们是具有相同状态的(属性字段的值都相同). ...

  5. Linux0.11内核剖析--内核代码(kernel)--sched.c

    1.概述 linux/kernel/目录下共包括 10 个 C 语言文件和 2 个汇编语言文件以及一个 kernel 下编译文件的管理配置文件 Makefile.其中三个子目录中代码注释的将放在后面的 ...

  6. phpstorm failed to create jvm:error code -6 解决办法 解决方法

    phpStorm 软件打开运行提示 failed to create JVM的解决办法. 修改文件 D:\Program Files (x86)\JetBrains\PhpStorm 7.1.3\bi ...

  7. 【Android】Activity 生命周期具体解释

    与其它编程模式不同,android中的Activity没有main()函数.我们无法决定Activity的创建和销毁过程,Activiy的创建和销毁(即生命周期)由系统完毕,系统会在Activity的 ...

  8. (剑指Offer)面试题44:扑克牌的顺子

    题目: 从扑克牌中随机抽5张牌,判断是不是一个顺子,即这五张牌是不是连续的,2~10为数字本身,A为1,J为11,Q为12,K为13,而大小王可以看成任意数字. 思路: 把5张牌看成一个数组,就看排序 ...

  9. mvn 编译错误java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter. <init>(Z)V

    Spring+struts2 +hibernate3集成,在后台测试时报的错,报错的这句话: Exception in thread "main" java.lang.NoSuch ...

  10. ERROR security.UserGroupInformation: Priviledge...

    http://my.oschina.net/u/617085/blog/71740 "Failed to set permissions of path"问题 参考文献:https ...