Литмир - Электронная Библиотека
Содержание  
A
A

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

End Set

End Property

End Structure

End Module

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

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

Option Strict On

Public Enum BallState

ZOOMING_BALL = -2

NO_BALL = -1

NORMAL_BALL = 0

JUMPING_BALL = 1

DESTROYING_BALL = 2

End Enum

Public Class MotionPic

Inherits System.Windows.Forms.PictureBox

Private myTimer As New System.Windows.Forms.Timer

Private picWidth As Integer

Private picHeight As Integer

Private picTop As Integer

Private picLeft As Integer

Private picState As Integer

Private picIndex As Integer

Private sign As Integer

#Region "Property Declaration"

Public Sub New(ByVal eSize As Size, ByVal eLocation As Point)

Me.Size = eSize

Me.Location = eLocation

picWidth = Me.Width

picHeight = Me.Height

picTop = Me.Top

picLeft = Me.Left

picState = BallState.NO_BALL

picIndex = -1

End Sub

Public ReadOnly Property MPState() As Integer

Get

Return picState

End Get

End Property

Public ReadOnly Property MPIndex() As Integer

Get

Return picIndex

End Get

End Property

Public Sub Init()

Me.Init(CInt(Rnd() * 12))

End Sub

#End Region

Public Sub Init(ByVal value As Integer)

picIndex = value

picState = BallState.ZOOMING_BALL

Dim i As Integer = ImgList(value).LastIndexOf("\")

Me.Tag = ImgList(value).Substring(i + 1, _

ImgList(value).Length – i – 5)

ZoomIn()

End Sub

Private Sub ZoomIn()

Me.Top = picTop + (picHeight – 4) \ 2

Me.Left = picLeft + (picWidth – 4) \ 2

Me.Width = 4

Me.Height = 4

Me.Image = Image.FromFile(ImgList(picIndex))

AddHandler myTimer.Tick, AddressOf TimerEventZoomIn

myTimer.Interval = 10

myTimer.Start()

End Sub

Private Sub TimerEventZoomIn(ByVal myObject As Object, _

ByVal myEventArgs As EventArgs)

If Me.Top > picTop And Me.Width < picWidth Then

Me.Top -= 2

Me.Left -= 2

Me.Width += 4

Me.Height += 4

Else

myTimer.Enabled = False

picState = BallState.NORMAL_BALL

RemoveHandler myTimer.Tick, AddressOf TimerEventZoomIn

End If

End Sub

Public Sub Jump()

If picState = BallState.NORMAL_BALL Then

sign = 1

picState = BallState.JUMPING_BALL

AddHandler myTimer.Tick, AddressOf TimerEventJump

myTimer.Interval = 20

myTimer.Start()

ElseIf picState = BallState.JUMPING_BALL Then

StopJump()

End If

End Sub

Public Sub StopJump()

If picState = BallState.JUMPING_BALL Then

picState = 0

myTimer.Enabled = False

RemoveHandler myTimer.Tick, AddressOf TimerEventJump

Me.Top = picTop

Me.Left = picLeft

Me.Height = picHeight

Me.Width = picWidth

End If

End Sub

Private Sub TimerEventJump(ByVal myObject As Object, _

ByVal myEventArgs As EventArgs)

Me.Height -= sign * 1

Me.Top = picTop + (Me.Height – picHeight) \ 4

If Me.Height = picHeight Or Me.Height <= 3 * picHeight / 4 Then

sign *= -1

End If

End Sub

Public Sub Destroy()

If picState = BallState.JUMPING_BALL Then

StopJump()

End If

picState = BallState.DESTROYING_BALL

AddHandler myTimer.Tick, AddressOf TimerEventDestroy

Me.Top = picTop + 1

Me.Left = picLeft + 1

Me.Width = picWidth – 2

Me.Height = picHeight – 2

myTimer.Interval = 10

myTimer.Start()

End Sub

Private Sub TimerEventDestroy(ByVal myObject As Object, _

ByVal myEventArgs As EventArgs)

If Me.Top > picTop And Me.Width > 0 Then

Me.Top += 2

Me.Left += 2

Me.Width -= 4

Me.Height -= 4

Else

Me.Image = Nothing

Me.Top = picTop

Me.Left = picLeft

Me.Width = picWidth

Me.Height = picHeight

myTimer.Enabled = False

Me.picState = BallState.NO_BALL

Me.picIndex = -1

Me.Tag = ""

RemoveHandler myTimer.Tick, AddressOf TimerEventDestroy

End If

End Sub

Public Sub Reset()

While Me.picState = BallState.DESTROYING_BALL

Application.DoEvents()

End While

If Me.picState = BallState.JUMPING_BALL Then

StopJump()

16
{"b":"813074","o":1}