Dim bottomright As Point = New Point(location.X + _
BlockSize, location.Y + BlockSize)
Dim transTopLeft As Point = PointTranslator.TranslateToBL( _
topleft)
Dim transBottomRight As Point = _
PointTranslator.TranslateToBL(bottomright)
Dim transwidth As Integer = transBottomRight.X – transTopLeft.X
Dim transheight As Integer = _
transBottomRight.Y – transTopLeft.Y
graphics.FillEllipse(brush, New Rectangle(transTopLeft, _
New Size(transwidth, transheight)))
End Sub
Private Function CreateTheBrush(ByVal location As Point) As _
LinearGradientBrush
Dim transLocation As Point = _
PointTranslator.TranslateToBL(location)
Dim brushpt1 As Point = transLocation
Dim brushpt2 As New Point(transLocation.X + Block.BlockSize _
+ 4, transLocation.Y – BlockSize – 4)
Dim brush As New LinearGradientBrush(brushpt1, _
brushpt2, Me.Color, System.Drawing.Color.White)
Return brush
End Function
End Class
По второму варианту, в панели Solution Explorer выполняем правый щелчок по имени проекта и в контекстном меню выбираем Add, New Item, в панели Add New Item выделяем шаблон Code File, в окне Name записываем имя Grid.vb и щёлкаем кнопку Add. В проект (и в панель Solution Explorer) добавляется этот файл, открывается пустое окно редактирования кода, в которое записываем код со следующего листинга.
Листинг 20.17. Новый файл.
'''
''' This class represents the grid of blocks. It handles most of
''' the game play.
'''
'''
Public Class Grid
' The grids is 12 columns and 15 rows of Block objects.
Dim matrix(11, 14) As Block
'''
''' Creates a few rows of blocks to start the game.
''' Game starts with Red, Blue, and Green blocks.
'''
''' Number of rows of blocks to create
''' to start the game.
'''
Public Sub New(ByVal nrows As Integer)
If nrows > matrix.GetLength(0) Then
Throw New Exception("Must start with " & _
matrix.GetLength(0) & " or fewer rows.")
End If
Dim row As Integer
Dim column As Integer
For row = 0 To nrows – 1
For column = 0 To matrix.GetLength(1) – 1
matrix(row, column) = New Block( _
New Color() {Color.Red, Color.Blue, Color.Green})
Next
Next
For row = nrows To matrix.GetLength(0) – 1
For column = 0 To matrix.GetLength(1) – 1
matrix(row, column) = Nothing
Next
Next
End Sub
'''