End If
' Update the matrix and compute the new score.
Dim count As Integer = matrix.Click(New Point(e.X, e.Y))
score += 10 * count
' Draw the new grid.
matrix.Draw(Me.PictureBox1.CreateGraphics(), _
Me.PictureBox1.BackColor)
' Write the score on the screen.
Dim images() As PictureBox = { _
Me.tenthousands, Me.thousands, _
Me.hundreds, Me.tens, Me.ones}
Dim scoreString As String = score.ToString().PadLeft(5)
Dim digits() As String = { _
scoreString.Chars(0), _
scoreString.Chars(1), _
scoreString.Chars(2), _
scoreString.Chars(3), _
scoreString.Chars(4)}
For index As Integer = 0 To 4
If digits(index) <> " " Then
images(index).Image = _
numbers.Images(CInt(digits(index)))
Else
images(index).Image = Nothing
End If
Next
End Sub
Private Sub StartNewGame()
' If a game is already running, check for a new high score.
If Not matrix Is Nothing Then
Me.Timer1.Enabled = False
HighScores.UpdateScores(score)
End If
Timer1.Enabled = False
matrix = New Grid(6)
score = 0
matrix.Draw(Me.PictureBox1.CreateGraphics(), _
Me.PictureBox1.BackColor)
Timer1.Enabled = True
AddHandler PictureBox1.MouseDown, AddressOf BlockClick
'Обнуляем счётчик секунд:
secondCounter = 0
End Sub
' To pause the game, turn off the timer.
Private Sub Pause()
Timer1.Enabled = False
Me.PauseToolStripMenuItem.Visible = False
Me.RestartToolStripMenuItem.Visible = True
RemoveHandler PictureBox1.MouseDown, AddressOf BlockClick
paused = True
End Sub
Private Sub ShowOptions()
'Dim optionsForm As New Options
Dim optionsForm As New Form2
optionsForm.SoundOn = isSoundOn
optionsForm.ShowDialog()
isSoundOn = optionsForm.SoundOn
optionsForm.Dispose()
End Sub
Private Sub Restart()
Timer1.Enabled = True
Me.PauseToolStripMenuItem.Visible = True
Me.RestartToolStripMenuItem.Visible = False
AddHandler PictureBox1.MouseDown, AddressOf BlockClick
paused = False
End Sub
Private Sub EndGame()
' Get top scores so far.
Me.Timer1.Enabled = False
HighScores.UpdateScores(score)
Me.Close()
End Sub
В панели Properties (для Form1) на вкладке Events дважды щёлкаем по имени события Load (Загрузка). Появившийся шаблон метода Form1_Load после записи нашего кода принимает следующий вид.
Листинг 20.2. Метод для загрузки объектов.
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
PointTranslator.Graphics = Me.PictureBox1.CreateGraphics()