Sub FindPath(ByVal pre_row As Integer, ByVal pre_col As Integer, ByVal cur_row As Integer, ByVal cur_col As Integer)
Dim pre_left As Integer = pre_col
Dim pre_right As Integer = pre_col
Dim cur_left As Integer = cur_col
Dim cur_right As Integer = cur_col
For j As Integer = pre_col - 1 To 0 Step -1
If Map(pre_row, j) <> -1 Then
pre_left = j + 1
Exit For
End If
Next
For j As Integer = pre_col + 1 To MAP_SIZE + 1
If Map(pre_row, j) <> -1 Then
pre_right = j - 1
Exit For
End If
Next
For j As Integer = cur_col - 1 To 0 Step -1
If Map(cur_row, j) <> -1 Then
cur_left = j + 1
Exit For
End If
Next
For j As Integer = cur_col + 1 To MAP_SIZE + 1
If Map(cur_row, j) <> -1 Then
cur_right = j - 1
Exit For
End If
Next
Dim left As Integer = Math.Max(pre_left, cur_left)
Dim right As Integer = Math.Min(pre_right, cur_right)
For q As Integer = pre_col To left Step -1
If LineConnect(pre_row, q, cur_row, q) = True Then
Stage.Controls.Remove(Picture(pre_row - 1, pre_col - 1))
Stage.Controls.Remove(Picture(cur_row - 1, cur_col - 1))
Count = Count - 2
Exit Sub
End If
Next
For q As Integer = pre_col To right
If LineConnect(pre_row, q, cur_row, q) = True Then
Stage.Controls.Remove(Picture(pre_row - 1, pre_col - 1))
Stage.Controls.Remove(Picture(cur_row - 1, cur_col - 1))
Count = Count - 2
Exit Sub
End If
Next
Dim pre_top As Integer = pre_row
Dim pre_bottom As Integer = pre_row
Dim cur_top As Integer = cur_row
Dim cur_bottom As Integer = cur_row
For i As Integer = pre_row - 1 To 0 Step -1
If Map(i, pre_col) <> -1 Then
pre_top = i + 1
Exit For
End If
Next
For i As Integer = pre_row + 1 To MAP_SIZE + 1
If Map(i, pre_col) <> -1 Then
pre_bottom = i - 1
Exit For
End If
Next
For i As Integer = cur_row - 1 To 0 Step -1
If Map(i, pre_col) <> -1 Then
cur_top = i + 1
Exit For
End If
Next
For i As Integer = cur_row + 1 To MAP_SIZE + 1
If Map(i, pre_col) <> -1 Then
cur_bottom = i - 1
Exit For
End If
Next
Dim top As Integer = Math.Max(pre_top, cur_top)
Dim bottom As Integer = Math.Min(pre_bottom, cur_bottom)
For p As Integer = pre_col To left Step -1
If LineConnect(p, pre_col, p, cur_col) = True Then
Stage.Controls.Remove(Picture(pre_row - 1, pre_col - 1))
Stage.Controls.Remove(Picture(cur_row - 1, cur_col - 1))
Count = Count - 2
PreClick = -1
CurClick = -1
Exit Sub
End If
Next
For p As Integer = pre_col To right
If LineConnect(p, pre_col, p, cur_col) = True Then
Stage.Controls.Remove(Picture(pre_row - 1, pre_col - 1))
Stage.Controls.Remove(Picture(cur_row - 1, cur_col - 1))
Count = Count - 2
PreClick = -1
CurClick = -1
Exit Sub
End If
Next
End Sub
Dim pre_left As Integer = pre_col
Dim pre_right As Integer = pre_col
Dim cur_left As Integer = cur_col
Dim cur_right As Integer = cur_col
For j As Integer = pre_col - 1 To 0 Step -1
If Map(pre_row, j) <> -1 Then
pre_left = j + 1
Exit For
End If
Next
For j As Integer = pre_col + 1 To MAP_SIZE + 1
If Map(pre_row, j) <> -1 Then
pre_right = j - 1
Exit For
End If
Next
For j As Integer = cur_col - 1 To 0 Step -1
If Map(cur_row, j) <> -1 Then
cur_left = j + 1
Exit For
End If
Next
For j As Integer = cur_col + 1 To MAP_SIZE + 1
If Map(cur_row, j) <> -1 Then
cur_right = j - 1
Exit For
End If
Next
Dim left As Integer = Math.Max(pre_left, cur_left)
Dim right As Integer = Math.Min(pre_right, cur_right)
For q As Integer = pre_col To left Step -1
If LineConnect(pre_row, q, cur_row, q) = True Then
Stage.Controls.Remove(Picture(pre_row - 1, pre_col - 1))
Stage.Controls.Remove(Picture(cur_row - 1, cur_col - 1))
Count = Count - 2
Exit Sub
End If
Next
For q As Integer = pre_col To right
If LineConnect(pre_row, q, cur_row, q) = True Then
Stage.Controls.Remove(Picture(pre_row - 1, pre_col - 1))
Stage.Controls.Remove(Picture(cur_row - 1, cur_col - 1))
Count = Count - 2
Exit Sub
End If
Next
Dim pre_top As Integer = pre_row
Dim pre_bottom As Integer = pre_row
Dim cur_top As Integer = cur_row
Dim cur_bottom As Integer = cur_row
For i As Integer = pre_row - 1 To 0 Step -1
If Map(i, pre_col) <> -1 Then
pre_top = i + 1
Exit For
End If
Next
For i As Integer = pre_row + 1 To MAP_SIZE + 1
If Map(i, pre_col) <> -1 Then
pre_bottom = i - 1
Exit For
End If
Next
For i As Integer = cur_row - 1 To 0 Step -1
If Map(i, pre_col) <> -1 Then
cur_top = i + 1
Exit For
End If
Next
For i As Integer = cur_row + 1 To MAP_SIZE + 1
If Map(i, pre_col) <> -1 Then
cur_bottom = i - 1
Exit For
End If
Next
Dim top As Integer = Math.Max(pre_top, cur_top)
Dim bottom As Integer = Math.Min(pre_bottom, cur_bottom)
For p As Integer = pre_col To left Step -1
If LineConnect(p, pre_col, p, cur_col) = True Then
Stage.Controls.Remove(Picture(pre_row - 1, pre_col - 1))
Stage.Controls.Remove(Picture(cur_row - 1, cur_col - 1))
Count = Count - 2
PreClick = -1
CurClick = -1
Exit Sub
End If
Next
For p As Integer = pre_col To right
If LineConnect(p, pre_col, p, cur_col) = True Then
Stage.Controls.Remove(Picture(pre_row - 1, pre_col - 1))
Stage.Controls.Remove(Picture(cur_row - 1, cur_col - 1))
Count = Count - 2
PreClick = -1
CurClick = -1
Exit Sub
End If
Next
End Sub