Оценить:
 Рейтинг: 0

Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 6: Программирование на Visual Basic искусственного интеллекта. Продолжение 2

Год написания книги
2023
Теги
<< 1 ... 4 5 6 7 8 9 10 11 12 ... 57 >>
На страницу:
8 из 57
Настройки чтения
Размер шрифта
Высота строк
Поля

Public Sub New(ByVal newColor As Color)

colorValue = newColor

End Sub

Public Sub New(ByVal colors() As Color)

Dim ncolors As Integer = colors.Length

Dim pickedColor As Integer

pickedColor = rand.Next(0, ncolors)

colorValue = colors(pickedColor)

End Sub

Public Sub Draw(ByVal graphics As Graphics, ByVal point As Point)

Dim brush As System.Drawing.Drawing2D.LinearGradientBrush = _

CreateTheBrush(point)

DrawTheCircle(graphics, brush, point)

End Sub

Private Sub DrawTheCircle(ByVal graphics As Graphics, _

ByVal brush As LinearGradientBrush, ByVal location As Point)

Dim topleft As Point = location

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. Новый файл.

''' <summary>

''' This class represents the grid of blocks. It handles most of

''' the game play.

''' </summary>

''' <remarks></remarks>

Public Class Grid

' The grids is 12 columns and 15 rows of Block objects.
<< 1 ... 4 5 6 7 8 9 10 11 12 ... 57 >>
На страницу:
8 из 57

Другие электронные книги автора Валерий Алексеевич Жарков