local playerInfo = {}
local xhr = cc.XMLHttpRequest:new()
xhr.responseType = cc.XMLHTTPREQUEST_RESPONSE_STRING
xhr:open("GET", "https://update.iofar.cn/res/peida.data")
local function onReadyStateChanged()
if xhr.readyState == 4 and (xhr.status >= 200 and xhr.status < 207) then
-- gt.log(xhr.response)
local playerInfo = json.decode(xhr.response)
--dump(playerInfo,"xxxxxxxxxxxxxxxxxxx")
--local playerInfo = xhr.response
Debug.PEIDAui(playerInfo.datas)
else
return
gt.log("xhr.readyState is:" .. xhr.readyState .. " xhr.status is: " .. xhr.status)
end
xhr:unregisterScriptHandler()
xhr = nil
end
xhr:registerScriptHandler(onReadyStateChanged)
xhr:send()
end
function Debug.testV()
print("v发牌动画")
local root, tree = gt.CommonToolEx:CsbParse("csd/Layer.csb")
display.getRunningScene():addChild(root,2)
root:addChild(gt.createMaskLayer(),-1)
local cards = {}
local cardWidth = 55
local cardPosY = 120
for i= 1, math.random(1,16) do
local card = tree.card:clone()
tree.bg:addChild(card)
card:setVisible(true)
table.insert(cards,i,card)
end
local tpPos = {} -- 记录位置的表
-- 计算牌的位置
local getCardPos = function()
for k,v in pairs(tpPos) do
table.remove(tpPos,i)
end
local cenNum = math.ceil(#cards/2)
--左边牌位置
for i = 1, cenNum do
local posx = display.cx - (cardWidth*(cenNum-i))
table.insert(tpPos,i,posx)
end
-- 右边牌位置
for i = cenNum+1 , #cards do
local posx = display.cx + (cardWidth*(i-cenNum))
table.insert(tpPos,i,posx)
end
end
-- dump(tpPos,"ssssssssssssssstpPossssssssssssssss")
-- dump(cards,"ssssssssssssssssscardssssssssssssss")
-- 牌数据附魔
local cardDataDeal = function()
local cardData = {
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,
0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,
0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c
}
for k,v in pairs(cards) do
local cardNum = math.random(1,48)
v:loadTexture(string.format("image/card/%02x.png", cardData[cardNum]), ccui.TextureResType.plistType)
end
end
cardDataDeal()
getCardPos()
-- 发牌
for k,v in pairs (cards) do
v:runAction(cc.MoveTo:create(0.5,cc.p(tpPos[k],120)))
end
-- 一般用于出牌后重新整理牌
local resetCardPos = function()
getCardPos()
for k,v in pairs (cards) do
v:setPosition(cc.p(tpPos[k],120))
end
end
local startIndex = nil
local endIndex = nil
--遍历所有的牌,查找当前的触摸点在哪张牌上
local getRangeIndex = function(event)
if startIndex == nil then
return
end
local pos = event.target:getTouchMovePosition()
--从后往前遍历,重叠现象
for i = #cards, 1, -1 do
--将pos转换到当前父节点的坐标系下
local point = cards[i]:getParent():convertToNodeSpace(pos)
--获取牌的牌的BoundingBox
local rect = cards[i]:getBoundingBox()
rect.width = rect.width/2
--判断点是否在矩形内
--cc.rectContainsPoint(rect,point)
local isContain = cc.rectContainsPoint(rect,point)
if isContain then
endIndex = i
cards[i]:setColor(cc.c3b(174,174,174))
end
--print("查询选中",startIndex,endIndex)
end
return startIndex,endIndex
end
-- 起牌落牌
local cardUpDown = function()
if startIndex and endIndex == nil then
if cards[startIndex] then
cards[startIndex]:setPositionY(cards[startIndex]:getPositionY() == 150 and 120 or 150)
cards[startIndex]:setColor(cc.c3b(255,255,255))
end
elseif startIndex and endIndex then
if startIndex >= endIndex then
startIndex,endIndex = endIndex,startIndex
end
for i= startIndex ,endIndex do
if cards[i] then
cards[i]:setPositionY(cards[i]:getPositionY() == 150 and 120 or 150)
end
end
end
for k , v in pairs(cards) do
v:setColor(cc.c3b(255,255,255))
end
end
local tochListnerFunc = function()
-- 牌的触摸监听
for k, v in pairs(cards) do
v:onTouch(function(event)
if event.name == "began" then
startIndex = k
-- print("触摸开始",startIndex)
elseif event.name == "moved" then
getRangeIndex(event)
else
cardUpDown()
startIndex = nil
endIndex = nil
end
end)
end
end
tochListnerFunc()
local chupai = function()
-- 发牌
local num = 0
for k,v in pairs (cards) do
if v:getPositionY() > 120 then
num = num+1
end
end
if num > 0 then
for i = 1 ,num do
for k,v in pairs (cards) do
if v:getPositionY() > 120 then
local card = table.remove(cards,k)
card:removeFromParent()
break
end
end
end
end
end
tree.close_btn:addClickEventListener(function(ref)
chupai()
resetCardPos()
tochListnerFunc()
--root:removeSelf()
end)
-- csb文件样式