Game Development Reference
In-Depth Information
5. The checkTypeMatch method searches around the current index and looks for
matches at the top, bottom, left, and right of the index:
function GridController:checkTypeMatch (c, r)
local type = self.gameLayer.grid[c][r]
local stepC = c
local stepR = r
local temp_matches = {}
--check top
while stepR -1 >= 1 and
self.gameLayer.grid[c][stepR-1] == type do
stepR = stepR - 1
table.insert (temp_matches, {x = c, y =
stepR})
end
if (#temp_matches >= 2) then self:addMatches
(temp_matches) end
temp_matches = {}
--check bottom
stepR = r
while stepR + 1 <= constants.GRID_SIZE_Y
and self.gameLayer.grid[c][stepR + 1] == type do
stepR = stepR + 1
table.insert (temp_matches, {x = c, y= stepR})
end
if (#temp_matches >= 2) then self:addMatches
(temp_matches) end
temp_matches = {}
--check left
while stepC - 1 >= 1 and
self.gameLayer.grid[stepC - 1][r] == type do
stepC = stepC - 1
table.insert (temp_matches, {x = stepC, y= r})
end
if (#temp_matches >= 2) then self:addMatches
(temp_matches) end
temp_matches = {}
--check right
stepC = c;
Search WWH ::




Custom Search