初始化系统的状态和点击反馈,有数值系统和老虎机系统:
-- 初始化系统的信息和状态
function MineSecretDialog:initSystemStatus(v)
local times = 0
local haveRunAction = false
G_Font_Purple = { name = DefaultFont, size = 15, color = FontColor.Purple }
G_Font_Orange = { name = DefaultFont, size = 15, color = FontColor.Orange }
G_Font_Blue = { name = DefaultFont, size = 15, color = FontColor.Blue }
local rockBonus = {"6", "8", "9", "E", "$", "@", "*"}
local itemSize = CCSizeMake(v.width, v.height)
local sprite = CCScale9Sprite:create("p_purecolor_"..v.color..".png", CCRectMake(0, 0, 10, 10), CCRectMake(2, 2, 6, 6))
sprite:setContentSize(itemSize)
local sysItem = CCMenuItemSprite:create( sprite, sprite )
self.m_menu:addChild(sysItem, 1)
sysItem:setPosition(v.pos)
sysItem:setAnchorPoint(ccp(0, 1))
local clickCost,addNum,sysName = 0,0,""
if v.sys == SysType.AACT then
clickCost,addNum,sysName = v.cost[v.curst],v.curst*5,"ACT"
elseif v.sys == SysType.AATK then
clickCost,addNum,sysName = v.cost[v.curst],v.curst*5,"ATK"
elseif v.sys == SysType.ADEF then
clickCost,addNum,sysName = v.cost[v.curst],v.curst*5,"DEF"
elseif v.sys == SysType.ADOT then
clickCost,addNum,sysName = v.cost[v.curst],v.curst*5,"DOT"
elseif v.sys == SysType.AKEY then
clickCost,sysName = v.cost[1],"KEY"
AddLabel( " ? ", ccp(v.width/2, v.height/2), sysItem, Tag.SysNumLabel+1, G_Font_Purple, ccp(0.5, 0.5) )
elseif v.sys == SysType.ROCK then
clickCost,sysName = v.cost[1],"ROCK"
AddLabel( " ? ", ccp(v.width/2 - 20, v.height/2), sysItem, Tag.SysNumLabel+1, G_Font_Purple, ccp(0.5, 0.5) )
AddLabel( " ? ", ccp(v.width/2, v.height/2), sysItem, Tag.SysNumLabel+2, G_Font_Purple, ccp(0.5, 0.5) )
AddLabel( " ? ", ccp(v.width/2 + 20, v.height/2), sysItem, Tag.SysNumLabel+3, G_Font_Purple, ccp(0.5, 0.5) )
end
AddLabel( "$"..clickCost, ccp(5, v.height-10), sysItem, Tag.SysCostLabel, G_Font_Black_8, ccp(0, 0.5) )
AddLabel( sysName, ccp(v.width-5, 10), sysItem, Tag.SysNameLabel, G_Font_Black_8, ccp(1, 0.5) )
if addNum > 0 then AddLabel( "+"..addNum, ccp(v.width/2, v.height/2), sysItem, Tag.SysNumLabel, G_Font_Purple, ccp(0.5, 0.5) ) end
sysItem:registerScriptTapHandler(function ()
if self.m_timer - times < 1 then
return
else
times = self.m_timer
end
local clickcost = v.cost[1]
if #v.cost > 1 and v.curst <= #v.cost then
clickcost = v.cost[v.curst]
end
game.fleetingLabelManager:pushLabel( "posX "..v.pos.x.." posY "..v.pos.y.." cost "..clickcost, self )
local redMoney = true
if v.sys == SysType.ROCK and v.curst > 0 then
redMoney = false
end
if userData.money < clickcost and redMoney then
game.fleetingLabelManager:pushLabel( "金币不足", self, "error" )
return
elseif redMoney then
self:updateUserMoney(0 - clickcost)
end
local addnum = 0
if v.sys == SysType.AACT then
self:updateUserActive(0, v.curst*5)
v.curst = v.curst + 1
addnum = v.curst*5
elseif v.sys == SysType.AATK then
self:addUserRecoverAtkDef(0, v.curst*5, 0)
v.curst = v.curst + 1
addnum = v.curst*5
elseif v.sys == SysType.ADEF then
self:addUserRecoverAtkDef(0, 0, v.curst*5)
v.curst = v.curst + 1
addnum = v.curst*5
elseif v.sys == SysType.ADOT then
self:addUserExp(0, v.curst*5)
v.curst = v.curst + 1
addnum = v.curst*5
elseif v.sys == SysType.AKEY then
if self:getRandomResult(1) then
AddLabel( " 紫 ", ccp(v.width/2, v.height/2), sysItem, Tag.SysNumLabel+1, G_Font_Purple, ccp(0.5, 0.5) )
self:updateUserKey(0, 0, 1)
elseif self:getRandomResult(10) then
AddLabel( " 橙 ", ccp(v.width/2, v.height/2), sysItem, Tag.SysNumLabel+1, G_Font_Orange, ccp(0.5, 0.5) )
self:updateUserKey(0, 1, 0)
else
AddLabel( " 蓝 ", ccp(v.width/2, v.height/2), sysItem, Tag.SysNumLabel+1, G_Font_Blue, ccp(0.5, 0.5) )
self:updateUserKey(1, 0, 0)
end
elseif v.sys == SysType.ROCK then
if v.curst == 0 then v.curst = v.curst + 1 end
if haveRunAction then
v.curst = v.curst + 1
sysItem:stopAllActions()
haveRunAction = false
end
if v.curst < 4 then
local array = CCArray:create()
array:addObject(CCDelayTime:create(0.1))
array:addObject(CCCallFunc:create(function ()
v.result[v.curst] = v.result[v.curst] + 1
if v.result[v.curst] > #rockBonus then v.result[v.curst] = 1 end
AddLabel( rockBonus[v.result[v.curst]], ccp(v.width/2 + (v.curst-2)*20, v.height/2), sysItem, Tag.SysNumLabel+v.curst, G_Font_Purple, ccp(0.5, 0.5) )
haveRunAction = true
end))
if haveRunAction == false then
sysItem:runAction(CCRepeatForever:create(CCSequence:create(array)))
end
else
-- 进行结算
game.fleetingLabelManager:pushLabel( v.result[1].." "..v.result[2].." "..v.result[3], self, "error" )
if v.result[1] == v.result[2] and v.result[2] == v.result[3] and v.result[3] == 1 then
elseif v.result[1] == v.result[2] and v.result[2] == v.result[3] and v.result[3] == 2 then
elseif v.result[1] == v.result[2] and v.result[2] == v.result[3] and v.result[3] == 3 then
elseif v.result[1] == v.result[2] and v.result[2] == v.result[3] and v.result[3] == 4 then
elseif v.result[1] == v.result[2] and v.result[2] == v.result[3] and v.result[3] == 5 then
elseif v.result[1] == v.result[2] and v.result[2] == v.result[3] and v.result[3] == 6 then
elseif v.result[1] == v.result[2] and v.result[2] == v.result[3] and v.result[3] == 7 then
end
v.curst = 0
v.result = {0,0,0}
end
end
if #v.cost > 1 then
if v.curst > #v.cost then
AddLabel( "完", ccp(v.width/2, v.height/2), sysItem, Tag.SysNumLabel, G_Font_Purple, ccp(0.5, 0.5) )
sysItem:removeChildByTag( Tag.SysCostLabel, true )
sysItem:setEnabled(false)
return
else
AddLabel( "$"..v.cost[v.curst], ccp(5, v.height-10), sysItem, Tag.SysCostLabel, G_Font_Black_8, ccp(0, 0.5) )
AddLabel( "+"..addnum, ccp(v.width/2, v.height/2), sysItem, Tag.SysNumLabel, G_Font_Purple, ccp(0.5, 0.5) )
end
end
end)
end
老虎机具体发放的奖励可以自己配置