Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 6: Программирование на Visual Basic искусственного интеллекта. Продолжение 2
Шрифт:
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)
frm.Show
frm.PlashScreen
frm.drawTable
ResetBoard
End If
End If
PreShow
intFlag = -1
Else
MPBoxes(intFlag).Tag = tempS
End If
ResetAllTag
End If
End Sub
Private Sub ResetBoard
ThreeBI(0) = -1
tmr1.Enabled = False
tmr2.Enabled = False
playerScore = 0
playerTime = 0
DDScore.number = 0
DDTime.number = 0
Me.Refresh
PreShow
lblNameShow.Text = ""
picBallPre1.Image = Nothing
For i As Integer = 0 To 80
MPBoxes(i).Reset
Next
End Sub
Private Sub DrawBoard(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
Dim g As Graphics = e.Graphics
'Рисуем сетку линиями красного (Red) цвета:
Dim p1 As New Pen(Color.Red)
Dim p2 As New Pen(Color.Black)
For i As Integer = 0 To 9
g.DrawLine(p1, intBaseX + 45 * i – 4, intBaseY – 5, _
intBaseX + 45 * i – 4, intBaseY + 45 * 9 – 5)
g.DrawLine(p2, intBaseX + 45 * i – 3, intBaseY – 4, _
intBaseX + 45 * i – 3, intBaseY + 45 * 9 – 4)
g.DrawLine(p1, intBaseX – 4, intBaseY + 45 * i – 5, _
intBaseX + 45 * 9 – 4, intBaseY + 45 * i – 5)
g.DrawLine(p2, intBaseX – 3, intBaseY + 45 * i – 4, _
intBaseX + 45 * 9 – 3, intBaseY + 45 * i – 4)
Next
End Sub
Private Sub LabelScore_Paint(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.PaintEventArgs)
DDScore.showNumber(e.Graphics)
End Sub
Private Sub LabelTime_Paint(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.PaintEventArgs)
DDTime.showTime(e.Graphics)
End Sub
Private Sub tmr1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles tmr1.Tick
Dim s As String = lblNameShow.Text
lblNameShow.Text = s.Substring(1) + s.Substring(0, 1)
End Sub
'Счётчик секунд, который обнуляем в начале каждой игры
'в методе NewGame:
Dim secondCounter As Integer
'Время, через которое звучит мелодия
'возможного окончания игры:
Dim EndGameTime As Integer = 60
Private Sub tmr2_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles tmr2.Tick
DDTime.number += 1
lblTime.Refresh
'Счётчик секунд:
secondCounter = secondCounter + 1
'Мелодия окончания игры:
If secondCounter = EndGameTime Then
My.Computer.Audio.Play("..\..\Sounds\win.wav", _
AudioPlayMode.Background)
End If
End Sub
'#Region "Preview Balls"
Private Sub PreShow
Dim col, row As Integer
For i As Integer = 0 To 2
If ThreeBI(i) = -1 Then
prePic(i).Visible = False
Else
prePic(i).Visible = True
prePic(i).Image = Image.FromFile(ImgList(ThreeBI(i)))
col = ThreeBP(i) Mod 9
row = ThreeBP(i) \ 9
prePic(i).Location = New Point(col * 45 + _
intBaseX + (38 – prePic(i).Width) / 2, _
row * 45 + intBaseY + (38 – prePic(i).Height) / 2)
prePic(i).Visible = True
prePic(i).BringToFront
End If
If ThreeBI(0) <> -1 Then
picBallPre1.Visible = True
picBallPre1.Image = _
Image.FromFile(ImgList(ThreeBI(0)))
End If
If ThreeBI(1) <> -1 Then
picBallPre2.Visible = True
picBallPre2.Image = _
Image.FromFile(ImgList(ThreeBI(1)))
Else
picBallPre2.Visible = False
End If
If ThreeBI(2) <> -1 Then
picBallPre3.Visible = True
picBallPre3.Image = _
Image.FromFile(ImgList(ThreeBI(2)))
Else
picBallPre3.Visible = False
End If
Next
End Sub
Private Sub PrePic_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim i As Integer = Array.IndexOf(prePic, sender)