AddHandler prePic(i).Click, AddressOf PrePic_Click
prePic(i).BringToFront()
Next
Else
ResetBoard()
End If
lblNameShow.Text = playerName
If playerName.Length > 8 Then
lblNameShow.Text += " "
tmr1.Enabled = True
End If
tmr2.Enabled = True
DDScore.number = plScore
lblScore.Refresh()
DDTime.number = plTime
lblTime.Refresh()
PreShow()
End Sub
Private Sub FindSol(ByVal i As Integer)
If MPBoxes(i).Tag <> "" Or MPBoxes(i).Tag = "Here" Then
Return
Else
MPBoxes(i).Tag = "Here"
End If
Select Case TestABox(i)
Case 1
FindSol(1)
FindSol(9)
Case 2
FindSol(7)
FindSol(17)
Case 3
FindSol(71)
FindSol(79)
Case 4
FindSol(63)
FindSol(73)
Case 5
FindSol(i + 1)
FindSol(i + 9)
FindSol(i 1)
Case 6
FindSol(i 9)
FindSol(i 1)
FindSol(i + 9)
Case 7
FindSol(i 1)
FindSol(i 9)
FindSol(i + 1)
Case 8
FindSol(i 9)
FindSol(i + 1)
FindSol(i + 9)
Case Else
FindSol(i 9)
FindSol(i + 9)
FindSol(i + 1)
FindSol(i 1)
End Select
End Sub
Private Sub ResetAllTag()
For Each Pic As MotionPic In MPBoxes
If Pic.Tag = "Here" Then
Pic.Tag = ""
End If
Next
End Sub
Private Function TestABox(ByVal val As Integer)
Select Case val
Case 0 : Return 1
Case 8 : Return 2
Case 80 : Return 3
Case 72 : Return 4
Case 1 To 7 : Return 5
Case 73 To 79 : Return 7
Case 17, 26, 35, 44, 53, 62, 71 : Return 6
Case 9, 18, 27, 36, 45, 54, 63 : Return 8
Case Else : Return 0
End Select
End Function
'Serious trouble happened think more
Private Function GiveThreeBalls() As Boolean
If ThreeBI(1) = -1 Then 'Review for Game over
Return False
Else
For i As Integer = 0 To 2
If ThreeBI(i) = -1 Then
Exit For
Else
If MPBoxes(ThreeBP(i)).MPState = BallState. _
NO_BALL And ThreeBP(i) <> posMoveTo Then
MPBoxes(ThreeBP(i)).Init(ThreeBI(i))
CalWin(ThreeBP(i))
End If
End If
Next
End If
RandomThreeBalls()
PreShow()
Return True
End Function
Private Function IsFullBoard() As Boolean
Dim i As Integer
For Each Pic As PictureBox In MPBoxes
If MPBoxes(i).MPState <> BallState.NO_BALL Then
i += 1
End If
Next
If i = 81 Then
Return True
Else
Return False
End If
End Function
Private Sub RandomThreeBalls()
Dim ArrL As New ArrayList
Dim i As Integer
Dim pos As Integer
Dim ind As Integer
For i = 0 To 80
If MPBoxes(i).MPState = BallState.NO_BALL Or _
MPBoxes(i).MPState = BallState.DESTROYING_BALL Then
ArrL.Add(i)
End If
Next
For i = 0 To IIf(ArrL.Count > 2, 2, ArrL.Count 1)
pos = Rand.Next(0, ArrL.Count)
pos = CInt(ArrL(pos))
ArrL.Remove(pos)
ThreeBP(i) = pos
ind = Rand.Next(0, 12)
ind = (ind \ 2) * 2
ThreeBI(i) = ind
Next
For j As Integer = i To 2
ThreeBI(j) = -1
ThreeBP(j) = -1
Next
End Sub
'#Region "Check for Calculate Score"
Private Function CheckHor(ByVal pos As Integer) As Integer
Dim type As Integer = MPBoxes(pos).MPIndex
Dim i As Integer = (pos \ 9) * 9
Dim count As Integer
Dim startpos As Integer = i
Dim endpos As Integer = i
While i < (pos \ 9) * 9 + 9
If MPBoxes(i).MPIndex = type Then
endpos += 1
count = endpos startpos
Else
If count > 4 Then
While MPBoxes(pos).MPState = _
BallState.ZOOMING_BALL
Application.DoEvents()
End While
For j As Integer = 0 To count 1
MPBoxes(startpos + j).Destroy()
Next
Return count
End If
If i >= (pos \ 9) * 9 + 5 Then
Return count
End If
startpos = i + 1
endpos = i + 1
End If
i += 1
End While
If count > 4 Then
While MPBoxes(pos).MPState = BallState.ZOOMING_BALL
Application.DoEvents()
End While
For j As Integer = 0 To count 1
MPBoxes(startpos + j).Destroy()
Next
Return count
End If
End Function
Private Function CheckVer(ByVal pos As Integer) As Integer
Dim type As Integer = MPBoxes(pos).MPIndex
Dim i As Integer = pos Mod 9
Dim count As Integer
Dim startpos As Integer = i
Dim endpos As Integer = i
While i < (pos Mod 9) + 73
If MPBoxes(i).MPIndex = type Then
endpos += 9
count = (endpos startpos) / 9
Else
If count > 4 Then
While MPBoxes(pos).MPState = _
BallState.ZOOMING_BALL
Application.DoEvents()
End While
For j As Integer = 0 To count 1
MPBoxes(startpos + j * 9).Destroy()
Next
Return count
End If
If i >= (pos Mod 9) + 36 Then
Return count
End If
startpos = i + 9
endpos = i + 9
End If
i += 9
End While
If count > 4 Then
While MPBoxes(pos).MPState = BallState.ZOOMING_BALL
Application.DoEvents()
End While
For j As Integer = 0 To count 1
MPBoxes(startpos + j * 9).Destroy()
Next
Return count
End If
End Function
Private Function CheckLR(ByVal pos As Integer) As Integer
If pos = 5 Or pos = 6 Or pos = 7 Or pos = 8 Or pos = 15 _
Or pos = 16 Or pos = 17 _
Or pos = 25 Or pos = 26 Or pos = 35 Or pos = 45 _
Or pos = 54 Or pos = 55 _
Or pos = 63 Or pos = 64 Or pos = 65 Or pos = 72 _
Or pos = 73 Or pos = 74 Or pos = 75 Then
Return 0
End If
Dim type As Integer = MPBoxes(pos).MPIndex
Dim i As Integer = pos Mod 10
i = IIf(i = 8, 18, IIf(i = 7, 27, IIf(i = 6, 36, i)))
Dim count As Integer
Dim startpos As Integer = i
Dim endpos As Integer = i
Dim tempi As Integer = i + 1
Dim temp As Integer
If i < 9 Then
temp = 9 i
Else
temp = 9 (i \ 9)
End If
While i < tempi + (temp 1) * 10
If MPBoxes(i).MPIndex = type Then
endpos += 10
count = (endpos startpos) \ 10
Else
If count > 4 Then
While MPBoxes(pos).MPState = _
BallState.ZOOMING_BALL
Application.DoEvents()
End While
For j As Integer = 0 To count 1
MPBoxes(startpos + j * 10).Destroy()
Next
Return count
End If
If i >= pos + 40 Then
Return count
End If
startpos = i + 10
endpos = i + 10
End If
i += 10
End While
If count > 4 Then
While MPBoxes(pos).MPState = BallState.ZOOMING_BALL
Application.DoEvents()
End While
For j As Integer = 0 To count 1
MPBoxes(startpos + j * 10).Destroy()
Next
Return count
End If
End Function
Private Function CheckRL(ByVal pos As Integer) As Integer
If pos = 0 Or pos = 1 Or pos = 2 Or pos = 3 Or pos = 9 _
Or pos = 10 Or pos = 11 _
Or pos = 18 Or pos = 19 Or pos = 27 Or pos = 53 _
Or pos = 61 Or pos = 62 _
Or pos = 69 Or pos = 70 Or pos = 71 Or pos = 77 _
Or pos = 78 Or pos = 79 Or pos = 80 Then
Return 0
End If
Dim type As Integer = MPBoxes(pos).MPIndex
Dim i As Integer = pos Mod 8
If i = 0 Then
i = 8
ElseIf i < 4 Then
i = (i + 1) * 8 + i
ElseIf pos \ 8 >= 5 Then
i = 45
End If
Dim count As Integer
Dim startpos As Integer = i
Dim endpos As Integer = i
Dim tempi As Integer = i + 1
Dim temp As Integer
If i < 9 Then
temp = i + 1
Else
temp = 9 (i \ 8)
End If
While i < tempi + temp * 8
If MPBoxes(i).MPIndex = type Then
endpos += 8
count = (endpos startpos) \ 8
Else
If count > 4 Then
While MPBoxes(pos).MPState = _
BallState.ZOOMING_BALL
Application.DoEvents()
End While
For j As Integer = 0 To count 1
MPBoxes(startpos + j * 8).Destroy()
Next
Return count
End If
If i >= pos + 32 Then
Return count
End If
startpos = i + 8
endpos = i + 8
End If
i += 8
End While
If count > 4 Then
While MPBoxes(pos).MPState = BallState.ZOOMING_BALL
Application.DoEvents()
End While
For j As Integer = 0 To count 1
MPBoxes(startpos + j * 8).Destroy()
Next
Return count
End If
End Function
Private Function CalWin(ByVal pos As Integer) As Integer
Dim point As Integer = CheckHor(pos)
If point < 4 Then
point = CheckVer(pos)
End If
If point < 4 Then
point = CheckLR(pos)
End If
If point < 4 Then
point = CheckRL(pos)
End If
If point > 4 Then
Dim dpoint As Double = point * 100 + (dpoint \ 6) * 100
Dim n As Double = DDScore.number + dpoint
For i As Double = DDScore.number To n Step 10
DDScore.number = i
lblScore.Refresh()
Next
DDScore.number = n
Return point
Else
Return 0
End If
End Function
'#Region "Ball Event And Paint Board"
Private Sub Ball_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
CType(sender, MotionPic).Jump()
If CType(sender, MotionPic).MPState <> _
BallState.NO_BALL Then
If intFlag <> -1 Then
MPBoxes(intFlag).Jump()
End If
'intFlag = MPBoxes.IndexOf(MPBoxes, sender)
'Исправляем предупреждение:
intFlag = Array.IndexOf(MPBoxes, sender)
ElseIf intFlag <> -1 Then
Dim tempS As String = MPBoxes(intFlag).Tag
MPBoxes(intFlag).Tag = ""
FindSol(intFlag)
If sender.tag = "Here" Then
'posMoveTo = MPBoxes.IndexOf(MPBoxes, sender)
'Исправляем предупреждение:
posMoveTo = Array.IndexOf(MPBoxes, sender)
If posMoveTo = ThreeBP(0) Then
prePic(0).SendToBack()
ElseIf posMoveTo = ThreeBP(1) Then
prePic(1).SendToBack()
ElseIf posMoveTo = ThreeBP(2) Then
prePic(2).SendToBack()
End If
CType(sender, MotionPic).Init(MPBoxes(intFlag). _
MPIndex)
MPBoxes(intFlag).Destroy()
While MPBoxes(intFlag).MPState = _
BallState.DESTROYING_BALL
Application.DoEvents()
End While
If CalWin(posMoveTo) = 0 Then
If GiveThreeBalls() = False Then
playerScore = DDScore.number
Dim frm As Form2 = New Form2
frm.AddPlayer() = _
New Player(playerName, playerScore)