---拼图地图格数据 ---@class ROPuzzleMapTileData local m = { ---@type number 位置标记 index = 0, ---@type number 所在行 x = 0, ---@type number 所在列 y = 0, ---@type number 地图格上放置的方块ID 为0 表示空格 blockId = 0, }
function m.New(index,x,y,id) local o = Clone(m) o:Init(index,x,y,id) return o end
function m:Init(index,x,y,id) self.index = index self.x = x self.y = y self.blockId = id end
---@class ROPuzzleGameData local m = { ---@type CfgRestaurantOperationPuzzleControlData cfgPuzzleGameControlData = nil, ---@type number 当前积分 score = 0, ---@type ROPuzzleMapTileData[] tileMaps = {}, ---@type number 最大行数 maxLine = 10, ---@type number 最大列数 maxColumn = 10, ---@type number 单次生成的方块数量(上限为4) randomBlock = {}, ---@type boolean 游戏是否已经开始(点了开始按钮视为游戏开始) isGameStart = false, }
local ROPuzzleMapTileData = require("IQIGame.Module.CommonActivity.RestaurantOperation.ROPuzzleGame.ROPuzzleMapTileData")
function m.New(cfgData) local o = Clone(m) o:Init(cfgData) return o end
function m:Init(cfgData) self.score = 0 self.cfgPuzzleGameControlData = cfgData self.tileMaps = self:CreateTiles() self.isGameStart = true end
---开始新游戏,创建拼图地图 function m:CreateTiles() local tab = {} local index = 0 for line = 1, self.maxLine do for column = 1, self.maxColumn do index = index + 1 local tileData = ROPuzzleMapTileData.New(index,line,column,0) tab[index] = tileData end end return tab end
---随机生成四个方块 function m:RefreshRandomBlock() self.randomBlock = {} local blockGroup = table.clone(self.cfgPuzzleGameControlData.BlockGroup) ---洗牌操作 for i = #blockGroup, 2, -1 do local random_index = math.random(i) blockGroup[i], blockGroup[random_index] = blockGroup[random_index],blockGroup[i] end ---根据配置数据取方块 for i = 1, self.cfgPuzzleGameControlData.BlockNum do local id = blockGroup[i] table.insert(self.randomBlock,id) end end
---消除满行满列,并返回消除的行列 ---@return number, number[],number[] 消除的总行数,同时消除的行和列 function m:Eliminate() local lines = {} local columns = {} ---行检测 for i = 1, self.maxLine do local isFull = true for j = 1, self.maxColumn do local pos = (i-1) * self.maxLine + j if self.tileMaps[pos].blockId == 0 then isFull = false break end end if isFull then table.insert(lines,i) end end ---列检测 for j = 1, self.maxColumn do local isFull = true for i = 1, self.maxLine do local pos = (i-1) * self.maxLine + j if self.tileMaps[pos].blockId == 0 then isFull = false break end end if isFull then table.insert(columns,j) end end local totalNum = #lines + #columns return totalNum,lines,columns end
---增加积分 ---@param score number function m:AddScore(score) self.score = self.score + score end
---检测方块还有没有空地能放下 ---@param blockCell PuzzleGameBlockCell ---@return boolean function m:CheckBlockCellCanPutDown(blockCell) local posTab = blockCell.blockData for i, tileData in pairs(self.tileMaps) do ---找到了一个空格子 local canPutDown = false if tileData.blockId == 0 then ---所有检测点都满足返回true for j, pos in pairs(posTab) do
---水果连连看水果数据 ---@class ROFruitData local m = { ---@type number 配置ID cid = nil, ---@type boolean 是否消除 isClean = false, ---@type number 所在位置 pos = 0, ---@type number 行 x = 0, ---@type number 列 y = 0, }
function m.New(cid,clean) local o = Clone(m) o:Init(cid,clean) return o end
function m:Init(cid,clean) self.cid = cid self.isClean = clean end
---@param pos number function m:SetPos(pos) self.pos = pos local x,y = self:GetX_Y() self.x = x self.y = y end
---@return CfgRestaurantOperationFruitListData function m:GetCfgData() if self.cid > 0 then return CfgRestaurantOperationFruitListTable[self.cid] end return nil end
---通过Pos获取格子位置 (每行10个格子) ---@return number,number 行,列 function m:GetX_Y() local x = math.ceil(self.pos / 10) local y = self.pos - 10 * (x-1) return x,y end