ЖАНРЫ

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

poly(0).X = c

poly(0).Y = h

poly(1).X = c

poly(1).Y = h – _width

poly(2).X = c + _thick

poly(2).Y = h – _width + _thick / 2

poly(3).X = c + _thick

poly(3).Y = h – _thick

Return poly

Case 6

c = x

h = y – 1

poly(0).X = c

poly(0).Y = h

poly(1).X = c

poly(1).Y = h – _width

poly(2).X = c + _thick

poly(2).Y = h – _width + _thick

poly(3).X = c + _thick

poly(3).Y = h – _thick / 2

Return poly

Case 7

ReDim poly(5)

c = x

h = y

poly(0).X = c

poly(0).Y = h

poly(1).X = c + _thick

poly(1).Y = h – _thick / 2

poly(2).X = c + _width – _thick

poly(2).Y = h – _thick / 2

poly(3).X = c + _width

poly(3).Y = h

poly(4).X = c + _width – _thick

poly(4).Y = h + _thick / 2

poly(5).X = c + _thick

poly(5).Y = h + _thick / 2

Return poly

End Select

End Function

Private Sub show(ByVal g As Graphics, ByVal led1 As Boolean, _

ByVal led2 As Boolean, ByVal led3 As Boolean, _

ByVal led4 As Boolean, ByVal led5 As Boolean, _

ByVal led6 As Boolean, ByVal led7 As Boolean)

led(g, 1, led1)

led(g, 2, led2)

led(g, 3, led3)

led(g, 4, led4)

led(g, 5, led5)

led(g, 6, led6)

led(g, 7, led7)

End Sub

Private Sub led(ByVal g As Graphics, ByVal led As Integer, _

ByVal sta As Boolean)

If (sta) Then

g.FillPolygon(_brush, conPol(led))

End If

End Sub

Private Sub showANum(ByVal g As Graphics, ByVal num As Integer)

Select Case num

Case 0

show(g, True, True, True, True, True, True, False)

Case 1

show(g, False, True, True, False, False, False, False)

Case 2

show(g, True, True, False, True, True, False, True)

Case 3

show(g, True, True, True, True, False, False, True)

Case 4

show(g, False, True, True, False, False, True, True)

Case 5

show(g, True, False, True, True, False, True, True)

Case 6

show(g, True, False, True, True, True, True, True)

Case 7

show(g, True, True, True, False, False, False, False)

Case 8

show(g, True, True, True, True, True, True, True)

Case 9

show(g, True, True, True, True, False, True, True)

End Select

End Sub

Public Sub showNumber(ByVal g As Graphics)

Dim tempnum As Integer

Dim tempPos As Point = _position

For i As Integer = 0 To _number.Length – 1

tempnum = _number.Substring(i, 1)

showANum(g, CInt(tempnum))

_position.X += _width + 2

Next

_position = tempPos

End Sub

#End Region

#Region "Show Time"

Private Sub show2Points(ByVal g As Graphics)

Dim r1 As Integer = _position.Y + _width / 2 – 2

Dim r2 As Integer = _position.Y – _width / 2 – 2

Dim c As Integer = _position.X + _width / 2 – 2

g.FillEllipse(_brush, c, r1, _width \ 3, _width \ 3)

g.FillEllipse(_brush, c, r2, _width \ 3, _width \ 3)

End Sub

Public Sub showTime(ByVal g As Graphics)

Dim num As Integer = CInt(_number)

Dim tempPos As Point = _position

Dim l As Integer = IIf(num = 3600, 8, 5)

Dim h As Integer = num \ 3600

Dim m As Integer = (num Mod 3600) \ 60

Dim s As Integer = num Mod 60

showANum(g, h \ 10)

_position.X += _width + 2

showANum(g, h Mod 10)

_position.X += _width + 2

show2Points(g)

_position.X += _width + 2

showANum(g, m \ 10)

_position.X += _width + 2

showANum(g, m Mod 10)

_position.X += _width + 2

show2Points(g)

_position.X += _width + 2

showANum(g, s \ 10)

_position.X += _width + 2

showANum(g, s Mod 10)

_position = tempPos

End Sub

#End Region

End Class

По второму варианту, в панели Solution Explorer выполняем правый щелчок по имени проекта и в контекстном меню выбираем Add, New Item, в панели Add New Item выделяем шаблон Code File, в окне Name записываем имя mModule.vb и щёлкаем кнопку Add. В проект (и в панель Solution Explorer) добавляется этот файл, открывается пустое окно редактирования кода, в которое записываем код со следующего листинга.

Листинг 21.10. Новый файл.

Public Module mModule

Private s As String = Application.StartupPath & "..\..\"

'Public ImgList As String = {s & "BlackBall.png",

's & "M_BlackBall.png", s & "BlueBall.png" _

', s & "M_BlueBall.png", s & "GreenBall.png", s &

'"M_GreenBall.png", s & "LGreenBall.png" _

', s & "M_LGreenBall.png", s & "MagentaBall.png", s &

'"M_MagentaBall.png" _

', s & "RedBall.png", s & "M_RedBall.png"}

'Исправляем ошибку:

Public ImgList As String = _

{"..\..\BlackBall.png", "..\..\M_BlackBall.png", _

"..\..\BlueBall.png", "..\..\M_BlueBall.png", _

"..\..\GreenBall.png", "..\..\M_GreenBall.png", _

"..\..\LGreenBall.png", "..\..\M_LGreenBall.png", _

"..\..\MagentaBall.png", "..\..\M_MagentaBall.png", _

"..\..\RedBall.png", "..\..\M_RedBall.png"}

Public Structure Player

Private _PlayerName As String

Private _PlayerScore As String

Public Sub New(ByVal PlayerName As String, _

ByVal PlayerScore As String)

_PlayerName = PlayerName

_PlayerScore = PlayerScore

End Sub

Public Property PlayerName As String

Get

Return _PlayerName

End Get

Set(ByVal Value As String)

_PlayerName = Value

End Set

End Property

Public Property PlayerScore As String

Get

Return _PlayerScore

End Get

Set(ByVal Value As String)

_PlayerScore = Value

Поделиться с друзьями: