Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 6: Программирование на Visual Basic искусственного интеллекта. Продолжение 2. Валерий Алексеевич Жарков
Читать онлайн книгу.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)
Dim MP As MotionPic = MPBoxes(ThreeBP(i))
Call Ball_Click(MP, e)
End Sub
'#Region "Save and Load Game"
Private Sub SaveGame()
Dim strNewLine = Chr(13) + Chr(10)
Dim s As String = Nothing
playerScore = DDScore.number
playerTime = DDTime.number
s += "#Assignment Line" + strNewLine
s += playerName.ToString + strNewLine
s += playerScore.ToString + strNewLine
s += playerTime.ToString + strNewLine
For i As Integer = 0 To 2
s += ThreeBI(i).ToString + ";" + ThreeBP(i).ToString
If i < 2 Then
s += ","
End If
Next
s += strNewLine
For i As Integer = 0 To 80
s += MPBoxes(i).MPState.ToString + ";" + _
MPBoxes(i).MPIndex.ToString
If i < 80 Then
s += ","
End If
Next
Dim SW As StreamWriter = Nothing
Try
SW = New StreamWriter("LSF.vmt")
SW.Write(s)
Catch IOE As IOException
MessageBox.Show("Can't save File !", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch EX As Exception
MessageBox.Show("Some Error occurs while Saving" + _
strNewLine + "Error :" + EX.ToString, _
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
SW.Close()
End Try
End Sub
Private Sub LoadGame()
Dim strRead(4) As String
Dim strBigArr() As String
Dim strSmallArr() As String
Dim SR As StreamReader = Nothing
If Not File.Exists("LSF.vmt") Then
MessageBox.Show("Save File doesn't Exists", _
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
Try
SR = New StreamReader("LSF.vmt")
If SR.ReadLine <> "#Assignment Line" Then
MessageBox.Show("Invalid Loaded File", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
SR.Close()
Exit Sub
End If
For i As Integer = 0 To 4
strRead(i) = SR.ReadLine
Next
Catch IOE As IOException
MessageBox.Show("Can't load File !", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch EX As Exception
MessageBox.Show("Some