开源手游暗黑世界客户端部分代码注解续

开源手游,暗黑世界客户端基于Cocos2d-x 2.1.4,详情:http://www.9miao.com/thread-42811-1-1.html

接上篇博客:http://blog.csdn.net/wangqiuyun/article/details/11234467

介绍登录之后
-------------------------------------------------------------------------------------
//登录场景
loginregister\LayerLogin.h

1.1、LayerLogin::receiveLoginData()
//接收到登录返回数据
//如果有角色:
this->schedule(schedule_selector(LayerLogin::sendPersonalData), 0.2);
//没角色:
CCLayer *slayer=startAnimate::create();

1.2、LayerLogin::sendPersonalData()
this->schedule(schedule_selector(LayerLogin::receivePersonalData), 0.2);

1.3、LayerLogin::receivePersonalData()
//点击开始按钮
pMenuItemStart->setTarget(this, SEL_MenuHandler(&LayerLogin::menuItemCallbackStart));

1.4、LayerLogin::menuItemCallbackStart()
homePage * homePage = homePage::create();

-------------------------------------------------------------------------------------
//创建角色
loginregister\startAnimate.h

startAnimate::callbackSelectRole()
CCLayer *xr=xuanren::create();

-------------------------------------------------------------------------------------
//选人
loginregister\xuanren.h

1.1、xuanren::EnterName()
CCMenuItemImage * sure=CCMenuItemImage::create("common_btn_ok_1.png", "common_btn_ok_2.png", "common_btn_ok_3.png", this, menu_selector(xuanren::replacScene));

1.2、xuanren::replacScene()
this->schedule(schedule_selector(xuanren::receiveRoleInfo),0.2);

1.3、xuanren::receiveRoleInfo()
this->schedule(schedule_selector(xuanren::receiveHomeInfo), 0.2);

1.4、xuanren::receiveHomeInfo()

1.5、this->enterHomePage();
CCScene *homePage=CCScene::create();//homepage  beginAni

-------------------------------------------------------------------------------------
//主页
headFile\zhujieMian\homepage.h

1.1、homePage::init()
//init 的时候发送消息[4500]给服务器,然后起定时器等待服务器回复.
SocketManager::getInstance()->sendMessage(json_file_jianghu.c_str(), 4500);
this->schedule(schedule_selector(homePage::rec_4500));

1.2、homePage::rec_4500()
//收到回复后,初始化窗体initTitle,btnsLoading,zhuangtaiLoad
this->initTitle();//加载标题
this->btnsLoading();//加载中部按钮
this->zhuangtaiLoad();//加载状态栏
this->downBtnLoading();//加载底部按钮

1.3、homePage::initTitle()
//加载标题,目前什么也没做

1.4、homePage::btnsLoading()
//加载中部按钮,即关卡
layerMainMap= LevelMap::create();

1.5、homePage::zhuangtaiLoad()
//加载状态栏
zhuangtai1 =zhuangtai::create();

1.6、homePage::downBtnLoading()
//加载底部按钮
btnHeCheng = CCMenuItemImage::create("zjm_hc_1.png", "zjm_hc_2.png", this, menu_selector(homePage::openHeCheng));
btnEmployFriends = CCMenuItemImage::create("zjm_employfriends_1.png", "zjm_employfriends_2.png", this, menu_selector(homePage::employFriends));
CCMenuItemImage *btnPersonal = CCMenuItemImage::create("zjm_personal_1.png", "zjm_personal_1.png", this, menu_selector(homePage::openPersonal));
linkFecharge = CCMenuItemImage::create("zjm_linkrecharge_1.png", "zjm_linkrecharge_2.png", this, menu_selector(homePage::recharge));
btnMail = CCMenuItemImage::create("zjm_mail_1.png", "zjm_mail_2.png", this, menu_selector(homePage::openMailWindow));
btnArena = CCMenuItemImage::create("zjm_arena_1.png", "zjm_arena_2.png", this, menu_selector(homePage::openArenaWindow));
homeLink = CCMenuItemImage::create("zjm_linkhome_1.png", "zjm_linkhome_2.png", this, menu_selector(homePage::mainView));

-------------------------------------------------------------------------------------
//状态栏
headFile\zhujieMian\zhuangtaiLoad.h

zhuangtai::init()
//获取玩家数据
char * json=CData::getCData()->getSendVal();
//设置显示玩家数据
coin=data["coin"].asInt();//货币
__coin=coin;
gold=data["yuanbao"].asInt();//金子、
level=data["level"].asInt();//等级
Exp=data["exp"].asInt();//当前经验
 maxExp=data["maxexp"].asInt();//最大经验
gas=data["gas"].asInt();//气
power=data["gas"].asInt();//力量

-------------------------------------------------------------------------------------
//中部副本按钮,即选关卡
headFile\zhujieMian\levelMap.h

1.1、LevelMap::init()
//点击事件
CCMenuItemSprite* leveltmp = CCMenuItemImage::create("zjm_building_1.png", "zjm_building_1.png", "zjm_building_2.png",this, menu_selector(LevelMap::clkBuilding));
//滚动,适应地图,绑定关卡数据
adjustMap(true)

1.2、LevelMap::adjustMap()
//CData::getCData()读取本关数据
MapItem* tmpLevelItemData = NULL;
tmpLevelItemData = CData::getCData()->getConfigOfMapLevel(offlevel + i);
//判断本关是否可玩
if(tmpLevelItemData->bid > currentLevelId)
{
    tmp->setEnabled(false);
}
else
{
    tmp->setEnabled(true);
}
//绑定本关数据      
tmp->setUserObject(tmpLevelItemData);

1.3、LevelMap::clkBuilding()
//获取关卡信息,然后展示关卡信息
MapItem *item = (MapItem*)building->getUserObject();
//buildingpop在popwindow.h
buildpop = buildingpop ::create();
this->getParent()->addChild(buildpop,100);
buildpop->show(item);

-------------------------------------------------------------------------------------
CData.h
//获取关卡信息,单例
CData::getCData()
//获取关卡信息
MapItem* CData::getConfigOfMapLevel(int levelid)
//读取配置文件
string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("map.json");
return (MapItem*)m_config_map_level_dic->objectForKey(levelid);
//MapItem对应map.json记录如下:
{"dropicon":"\r","yid":0,"coin":248,"mconfig":[100001],"name":"阿卡拉的试炼","levelrequired":0,"resourceid":0,"scene":1000,"dropid":1,"priority":0,"exp":124,"icon":5000,"quality":1,"id":1000,"desc":"打败佣兵向阿卡拉证明你的实力"}

-------------------------------------------------------------------------------------
headFile\zhujieMian\popwindow.h

//展示关卡数据
1.1、buildingpop::show(MapItem *item)
this->item = item;

1.2、buildingpop::init()
//关闭按钮
cl=CCMenuItemImage::create("common_btn_close_1.png", "common_btn_close_2.png",this, menu_selector(buildingpop::close));
//布阵按钮
bz = CCMenuItemImage::create("popbuilding_buzhen_1.png", "popbuilding_buzhen_2.png",this, menu_selector(buildingpop::buzhen));
//战斗按钮
ft = CCMenuItemImage::create("popbuilding_fire_1.png", "popbuilding_fire_2.png","popbuilding_fire_3.png", this, menu_selector(buildingpop::fight));
//关闭
1.3、buildingpop::close()   
this->hide();

1.4、buildingpop::buzhen()
//布阵,调用父层布阵函数
((homePage*)(this->getParent()))->openNewBuZhen();
//移除本层
this->removeFromParent();

1.5、buildingpop::fight()
//点击战斗,显示加载层
load=Loading::create();
//玩家编号
root["characterId"]=CData::getCData()->getCharactorId();

//关卡编号
root["zjid"]= this->item->bid;
//提交关卡及玩家数据,发送战斗请求,
SocketManager::getInstance()->sendMessage(json_file_zhandou.c_str(), 4501);
//定时器,每隔0.2秒调用receiveFireData检测一下是否接收到返回数据,如果接收到则取消定时器
this->schedule(schedule_selector(buildingpop::receiveFireData),0.2);

1.6、buildingpop::receiveFireData()
//接收战斗返回的数据,4501表示战斗
Message *revMsg=(Message *)CData::getCData()->m_dictionary->objectForKey(4501);

//返回的数据
char* data=revMsg->data;
//数据格式,结果以及评星数都已经确定
{"data": {"setData": {"huoli": -1, "item": [53000001], "coin": 248, "star": 3, "exp": 124}, "battleResult": 1, "stepData": [{"chaBattleId": 15, "enemyChaArr": [{"enemyBattleId": 25, "enemyChaId": 101, "enemyActionId": 96, "enemyChangeHp": -64, "enemyBuff": 0, "enemyCurrentHp": 2, "enemyTotalHp": 2}], "chaBuff": 0, "chaExpendHp": 0, "chaId": 1000003, "txtEffectId": 0, "actionId": 99, "chaCurrentHp": 56, "chaTotalHp": 56, "skill": 100006}], "startData": [{"chaBattleId": 15, "chaName": "123", "chaPos": 5, "chaLevel": 1, "chaDirection": 1, "chaIcon": 1, "chaCurrentHp": 56, "chaTotalHp": 56, "chaId": 1000003}, {"chaBattleId": 25, "chaName": "\u4f63\u5175", "chaPos": 5, "chaLevel": 1, "chaDirection": 2, "chaIcon": 6048, "chaCurrentHp": 2, "chaTotalHp": 2, "chaId": 101, "chaPz": 1}]}, "message": "", "star": 3, "result": true}    
CData::getCData()->m_dictionary->removeObjectForKey(4501);
//停止定时器
this->unschedule(schedule_selector(buildingpop::receiveFireData));
//进入战斗界面
CCScene *scene=Fire::scene();
//移除加载层
load->removeFromParent();

-------------------------------------------------------------------------------------
//战斗场景
FireWork.h

先写到这,后续!!!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值