1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| Public Sub CheckForPattern()
Dim tilesToPop As New List(Of Tile)
For Each t As Tile In MovedTiles
'initialization
MatchingTilesInRow = New List(Of Tile)
MatchingTilesInCol = New List(Of Tile)
'horizontal lookup
MatchingTilesInRow.Add(t)
'leftwards
Dim r As Short = t.Row
Dim c As Short = t.Col - 1
Dim break As Boolean = False
While Not (c < 0 Or break)
If Tiles(r, c).Candy.Value = t.Candy.Value Then
MatchingTilesInRow.Add(Tiles(r, c))
Else
break = True
End If
c -= 1
End While
'rightwards
c = t.Col + 1
break = False
While Not (c > 9 Or break)
If Tiles(r, c).Candy.Value = t.Candy.Value Then
MatchingTilesInRow.Add(Tiles(r, c))
Else
break = True
End If
c += 1
End While
'vertical lookup
MatchingTilesInCol.Add(t)
'upwards
r = t.Row - 1
c = t.Col
break = False
While Not (r < 0 Or break)
If Tiles(r, c).Candy.Value = t.Candy.Value Then
MatchingTilesInCol.Add(Tiles(r, c))
Else
break = True
End If
r -= 1
End While
'downwards
r = t.Row + 1
break = False
While Not (r > 9 Or break)
If Tiles(r, c).Candy.Value = t.Candy.Value Then
MatchingTilesInCol.Add(Tiles(r, c))
Else
break = True
End If
r += 1
End While
If MatchingTilesInCol.Count >= 3 Then
For Each tile As Tile In MatchingTilesInCol
If Not tilesToPop.Contains(tile) Then
tilesToPop.Add(tile)
End If
Next
End If
If MatchingTilesInRow.Count >= 3 Then
For Each tile As Tile In MatchingTilesInRow
If Not tilesToPop.Contains(tile) Then
tilesToPop.Add(tile)
End If
Next
End If
Next
Pop(tilesToPop) 'delete matching candies
End Sub |
Partager