We will create two methods for checking the neighboring tiles, as we need to do this for each axis (x
and y)
, separately.
game
class, add a new method called CheckGemsX
. As parameters, it will take the column and row, the gem type, and a mark flag.Method CheckGemsX:Int(column:Int, row:Int, gem:Int, mark:Bool = False)
found
variable of the type INT. It will be set once we find similar gems.Local found:Int = 0
tileMap[column-1][row-1] = -1
column
is greater than 1
. It means there must be gems on the left.If column > 1 Then
column -1
to the first gem on the left.For Local c:Int = (column-1) To 1 Step -1
If tileMap[c-1][row-1] <> gem Then Exit
mark
flag was set, fill the value 99
into the tile slot. It is used if we want to mark tiles to delete them later.If mark Then tileMap[c-1][row-1] = 99 Else
found
by 1
.found += 1 Endif
Next Endif
column
isn't greater than the field columns
of the game
class.If column < columns Then
column+1
to columns
For Local c:Int = (column+1) To columns
If tileMap[c-1][row-1] <> gem Then Exit
mark
flag is set, fill the value 99
into the slot.If mark Then tileMap[c-1][row-1] = 99 Else
found
by 1
.found += 1 Endif
Next Endif
mark
flag was set, fill the value 99
into the slot of the actual gem, too. You want to delete it also, not only the neighboring tiles.If mark Then tileMap[column-1][row-1] = 99 Else
gem
parameter.tileMap[column-1][row-1] = gem Endif
Return found End
18.189.188.238