Not any easier than this:
VB Code:
X = Index Mod SHAPESPERROW Y = Index \ SHAPESPERROW ' the code below makes sure you're not trying to go out of the game field If X > 0 Then If Shape1(Index - 1).BackColor = Shape1(Index).BackColor Then ' match If Y > 0 Then If Shape1(Index - SHAPESPERROW).BackColor = Shape1(Index).BackColor Then ' match If X < SHAPESPERROW - 1 Then If Shape1(Index + 1).BackColor = Shape1(Index).BackColor Then ' match If Y < TotalRows - 1 Then If Shape1(Index + SHAPESPERROW).BackColor = Shape1(Index).BackColor Then ' match
The code is partly a pseudocode. What happens on match depends on what you want to do. One method you could do is to have four boolean values, so you could see how many matches you get when you combine them together. For example:
VB Code:
Dim blnLeft As Boolean, blnTop As Boolean, blnRight As Boolean, blnBottom As Boolean Dim bytTotalMatch As Byte X = Index Mod SHAPESPERROW Y = Index \ SHAPESPERROW If X > 0 Then blnLeft = Shape1(Index - 1).BackColor = Shape1(Index).BackColor If Y > 0 Then blnTop = Shape1(Index - SHAPESPERROW).BackColor = Shape1(Index).BackColor If X < SHAPESPERROW - 1 Then blnRight = Shape1(Index + 1).BackColor = Shape1(Index).BackColor If Y < TotalRows - 1 Then blnBottom = Shape1(Index + SHAPESPERROW).BackColor = Shape1(Index).BackColor ' a boolean is either False (0) or True (-1) ' Abs strips out negative marker if one is found ' So True becomes 1 and False becomes 0 bytTotalMatch = Abs(blnLeft) + Abs(blnTop) + Abs(blnRight) + Abs(blnBottom)
You also might like to make combos. You could create a new array where you store stuff:
VB Code:
Dim barMatch() As Byte ReDim barMatch(TOTALSHAPES - 1) ' Think lngA as Index For lngA = 0 To UBound(barMatch) ' ... code to fill bytTotalMatch for this array item barMatch(lngA) = bytTotalMatch Next lngA
The code above shows how you can use an array to store information about all matches on the game field. I don't know if you have any use for it, but you might use something similar for calculating combos and such. Most importantly shows you how you can use an array to help you out
Surprisingly enough I've never made a puzzle or a block game.





Reply With Quote