cocos2d-x技术群新群:117871561
c++技术交流群:593010226
--处理杠的类型HonLin
function GameViewLayer:dealGangKind()
-- local ret ,card = GameLogic.checkCanGan(self.cbActionCard,self._cardLayer:getGangCard())
-----------------------
--存放杠牌数据
self.anGangs = {}
local card = self.cbActionCard
local hadGang = false
--遍历手牌判断过路杠数据
local handcard = {}
--获得碰牌数据
local cbBpBgData = self._cardLayer:getBpBgCardData()
--获得自己的碰牌区数据,将碰牌区数据加入到手牌
local MyBumpData = cbBpBgData[cmd.MY_VIEWID]
handcard = clone(self._cardLayer.cbCardData)
--情况一:自己摸牌杠,和别人点杠
if #MyBumpData~= 0 then
GameLogic.SortCardList(MyBumpData)
end
-- if ret == 1 then
--判断数据里有没有可以杠的
--遍历自己碰牌区 如果可以组成杠牌则发此牌给服务器
for i = 1, #MyBumpData do
local d = MyBumpData[i]
local d1 = MyBumpData[i+2]
if d == d1 and d == card then
if self._scene.wCurrentUser == cmd.MY_VIEWID then
table.insert(anGangs,card)
break
else
self._scene:sendOperateCard(GameLogic.WIK_GANG, card)
hadGang = true
break
end
end
end
if #handcard~= 0 then
GameLogic.SortCardList(handcard)
end
--遍历手牌 如果此牌可以跟手牌组合成杠则发此牌
for i = 1,#handcard do
local d = handcard[i]
local d1 = handcard[i+2]
if d == d1 and d == card then
if self._scene.wCurrentUser == cmd.MY_VIEWID then
table.insert(anGangs,card)
break
else
self._scene:sendOperateCard(GameLogic.WIK_GANG, card)
hadGang = true
break
end
end
end
-- end
if not hadGang then
--第二种情况 碰牌区3张牌 手牌一张同样的牌 3+1
for i = 1, #handcard do
local num = 0
for j = 1,#MyBumpData do
if MyBumpData[j] == handcard[i]
then
num = num+1
if num ==3 then
card = handcard[i]
table.insert(self.anGangs,card)
break
end
end
end
end
if #self.anGangs ~= 0 and self.anGangs ~= nil then
--去重
GameLogic.RemoveRepetition(self.anGangs)
end
end
--第三种情况 手牌区有暗杠
if #handcard~= 0 then
GameLogic.SortCardList(handcard)
end
if not hadGang then
for i = 1,#handcard do
local d = handcard[i]
local d1 = handcard[i+3]
if d== d1 then
table.insert(self.anGangs,d)
end
end
if #self.anGangs == 1 then
card = self.anGangs[1]
self._scene:sendOperateCard(GameLogic.WIK_GANG,card)
else
for i = 1, #self.anGangs do
if self:isMagicCard(self.anGangs[i]) then
table.remove(self.anGangs,i)
end
end
if #self.anGangs > 1 then
self._cardLayer:showMuiltGangCard(self.anGangs)
else
self._scene:sendOperateCard(GameLogic.WIK_GANG,self.anGangs[1])
end
end
end
end
去重
--参数是一个table
function GameLogic.RemoveRepetition(TableData)
assert(type(cbCardData) == "table")
--在对应的位置赋予ture值比如 3,3,5,6,6 。bExist的第三个值第五个值第六个元素都是true也就是3,5,6位置元素是有值的
local bExist = {}
for v, k in pairs(cbCardData) do
bExist[k] = true
end
--将有值得位置作为元素存到一个表里
local result = {}
for v, k in pairs(bExist) do
table.insert(result, v)
end
GameLogic.SortCardList(result)
return result
end
网友评论