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 = 0,
        _Reverse =1,
        _Both   = 2,
    };

};


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(0 != xmlStrcmp(BAD_CAST "bionts", pRootNode->name))
        {
            break;
        }
        //读取节点
        xmlNodePtr pCurNode = pRootNode->xmlChildrenNode;
        while (NULL != pCurNode)
        {
            if (0 != 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 (0);

    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(0 != xmlStrcmp(BAD_CAST "maps", pRootNode->name))
        {
            break;
        }
        //读取节点
        xmlNodePtr pElement = pRootNode->xmlChildrenNode;
        while (NULL != pElement)
        {
            if (0 == 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 = 0; i < vecData.size(); i++)
                {
                    vector<string> vecPos;
                    CXCommon::split(vecData[i], string(","), vecPos);
                    if (!vecPos.empty())
                    {
                        mapInfo.foundationPos.push_back(CCPoint(atof(vecPos[0].c_str()), atof(vecPos[1].c_str())));
                    }
                }
                
                vector<string> vecPath;
                CXCommon::split(CCXmlReader::getXMLNodeAttribStrs(&pElement, "path"), string(";"), vecPath);
                for (unsigned int i = 0; i < vecPath.size(); i++)
                {
                    vector<string> vecPos;
                    CXCommon::split(vecPath[i], string(","), vecPos);
                    if (!vecPos.empty())
                    {
                        mapInfo.path.push_back(CCPoint(atof(vecPos[0].c_str()), atof(vecPos[1].c_str())));
                    }
                }

                m_mapMapInfo[mapInfo.nId] = mapInfo;
            }
            pElement = pElement->next;
        }
        xmlFreeDoc(pDoc);
        return true;
    } while (0);

    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;
}

 

转载于:https://www.cnblogs.com/newlist/p/3180997.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
摘 要 伴随着人才教学的关注度越来越高,对于人才的培养也是当今社会发展的最为重要的问题之一。为了进一步的进行人才的培养关工作,许多的学校或者是教育的机构逐步的开展了网络信息化的教学和和管理工作,通过信息化的手段和技术实现网络信息化的教育及管理模式,通过网络信息化的手段实现在线答题在线考试和学生信息在线的管理等操作。这样更加的快捷解决了人才培养之中的问题,也在进一步的促进了网络信息化教学方式的快速的发展工作。相较于之前的人才教育和培养工作之中,存在这许多的问题和局限性。在学生信息管理方面通过线下管理的形式进行学生信息的管理工作,在此过程之中存在着一定的局限性和低效性,往往一些突发的问题导致其中工作出现错误。导致相关的教育工作受到了一定的阻碍。在学生信息和学生成绩的管理方面,往常的教育模式之下都是采用的是人工线下的进行管理和整理工作,在这一过程之中存在这一定的不安全和低效性,面对与学生基数的越来越大,学生的信息管理也在面领着巨大的挑战,管理人员面领着巨大的学生信息的信息量,运用之前的信息管理方式往往会在统计和登记上出现错误的情况的产生,为后续的管理工作造成了一定的困难。然而通过信息化的管理方式进行对学生信息的管理不仅可以避免这些错误情况的产生还可以进一步的简化学生信息管理工作的流程,节约了大量的人力和物力的之处。在线答题系统的实现不仅给学生的信息管理工作和在线考试带来了方便也进一步的促进了教育事业信息化的发展,从而实现高效化的教学工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值