       .  6:   Visual Basic  .  2
  


                   ()  -     ,   ,           .    Visual Basic   XVIII ,      4, 5  6.    6   IX-XVIII.    :          ,    ,           ,   ,    ,     ,   ,   ,            .              VB   .





 

       .  6:   Visual Basic  .  2








                                  , ,      ,        Visual Basic         Microsoft ().

  ()     ,    ,   ,         .     , ,      ,    ,      -    .  ,         .           .      , ,     ,   ,      ,        .            .

  (, , ) Visual Studio (  VS)   -               ,             .  ,    VS      ,       ,       (    )            Visual C#, Visual Basic  Visual C++.      (   )    ,     ,              .

       ,      .           Visual Basic        VB.     ,        (          ZharkovPress.ru     )    ,         .           ,            VB,      ;       ,           Visual Basic     .    ,        ,    ,   (   ,     ,       ),      ,     .         ,           .     .           (        ,    )      ( : ,  )           VS.               (      )        .                       ZharkovPress.ru (    Help  Visual Studio,  ,      ),       , ,     (   )   , , , , ,      (  )     .                 VS  (  ),            ,        .

    XVIII     4, 5  6     Visual Basic. .  I.   Visual Basic.  1.   .  2.         .  3.              .  II.         .  4.      .  5.   ,       .  6.    .  7.   ,      .  8.       .  9.         .  10.       ,         .  11.      .  III.       .  12.            .  IV.            .  13.               .  V.        ,    .  14.        ,           ,    .  15.        ,           ,    .  VI.               .  16.               12 .  17.               7      ,     .  VII.        -       .  18.        -.  VIII.              .  19.               .  IX.               .  20.           .  21.           5     .  X.        .  22.                .  XI.               . 23.                .  XII.       .  24.                  .  XIII.        .  25.              .  XIV.         ,   .  26.          ,          .  XV.       .  27.         .  XVI.                .  28.         .  29.    .  30.  .  XVII.          .  31.    .  XVIII. ,          .  32.     . .  .

   VIII-XVIII    6     Visual Basic. .  IX.               .  20.           .  21.           5     .  X.        .  22.                .  XI.               .  23.                .  XII.       .  24.                  .  XIII.        .  25.              .  XIV.         ,   .  26.          ,          .  XV.       .  27.         .  XVI.                .  28.         .  29.    .  30.  .  XVII.          .  31.    .  XVIII. ,          .  32.     . .  .

        ,    Microsoft,      Microsof.                   ,        .     ,        (              ZharkovPress.ru)  ,                ,                 ,            .

                      ,    (  )    Visual Basic     , ,   ,                           .      ,   ,      , , , ,    .

    (     )         .

,             email   ZharkovPress.ru.




 IX.               








 20.           







20.1.  




         ,         (      ...  Random)          ,   ,   .

         ,        ( )     (     ).   ,      ( )   ( ) ,     10     .         ,            .

         ( ).

    ,   Game   microsoft.com.        Visual Studio.           Visual Studio,          , ,          .

           (   (.bmp)     ),    (-: circle)     FillEllipse  Graphics    System.Drawing  :

graphics.FillEllipse(brush, New Rectangle(transTopLeft, _

New Size(transwidth, transheight)))

, ,    (Ellipse)      ,       ,        .




20.2.  


1.        (. 20.1).

2.        PictureBox      New    Game   New Game.

     ( Window)      12   7  () ,    (  ...)   4 : Red  , Blue  , Green    Gray   (. 20.2).

    ,       (    Timer1)   (  ,  7000   7 )       12   12    (. 20.3).








. 20.1.  .








. 20.2.     .








. 20.3.     .








. 20.4.  .

        (Time)           Text     Timer2.

3.     .

           .

   ,      ,     ,     (   ),    10 .

   ,         ,    ,      ( )   ( ) ,     10     .

,          ,        ( ).

        ,            .        Windows XP Balloon.wav ( ).

        (    Timer1)   (  ,  7000   7 )      ( ).

     ,    .  M (    Menu)     Game,   P (    Pause)     .    Alt       ( )    Game  Help,   .

4.       (Time)           Text     Timer2.

   ()        ,   , 60 ,       win.wav.

         .

5.        ,     .          PictureBox      New    Game   New Game.

    :

  ,    ;

      ,       ,

  (    )  InputBox      (. 20.5).

     InputBox  ,     .








. 20.5.  InputBox     .

   InputBox    (    )    (   )    OK.  InputBox .

6.           Options (       ),   ,        PictureBox      Options    Game   Options.   Options       (. 20.6),             (high score)    .

  ,    Reset.    ,    Sound.








. 20.6.  Options    .

7.             PictureBox      New    Game   New Game.

8.           PictureBox      Exit    Game   Exit

       ,        ,      Contents ()   Help ()        .




20.3.   




    : VS   New Project   Project types    Visual Basic, Windows,   Templates   Windows Forms Application,   Name    Game   OK.  ,   Form1    (. 20.7).      ,        .       ,    Properties ( Form1)   Size  , , 519; 464.          (  Me.BackColor = Color.White).

       -    .   ,    Toolbox      MenuStrip     (    ).   Form1     Type Here ( ),    , : Game (), New Game ( ), Pause (), Restart (), Options (), Exit (), . 20.9, : Help (), Contents (), Index (), Search (), About this game (  ), . 20.10.















. 20.7.  Form1   . . 20.8. SE  Properties.















. 20.9.   Game. . 20.10.   Help.

  Properties   Text      MenuStrip      &,        . ,    ,    Alt       ( )    Game  Help,   .

   Toolbox        PictureBox   .     ,    Properties   Size   300; 375,    BackColor       Control    Window.

    Panel,      Size   175; 96.

   Panel  5   PictureBox   Size (24; 67).   Properties   BackColor        Window,    Name    5    ( ):

ones  ,

tens  ,

hundreds  ,

thousands  ,

tenthousands   .

      PictureBox      Size (100; 50).      ,   Properties   Image,    Select Resource   Local resource    Imports (. 20.11).   Open  (,       )   new.bmp (. 20.12)    Open,         Select Resource,    OK. ,   new.bmp    Properties   Image        PictureBox.

         PictureBox      Size (100; 50),     exit.bmp.









. 20.11.   Select Resource  Imports. . 20.12.   Open  .

         PictureBox,    Size  128; 50      option.bmp.

   Toolbox        ImageList, ,  ,   .   Properties   Name     numbers (   ),    ImageSize     26; 67.        ,   Properties   Images,    Images Collection Editor   Add (. 20.13).     Open  (,       )   0.bmp    Open,         Images Collection Editor.     ImageList    1, 2, 3, , 9.

    Interval        (   ),    Toolbox    (,  )   Timer1.   Properties (  )   Enabled      False, ..             (Timer1.Enabled = True).    Interval     100  , ,  7000  ( 7 ).

     (     Text)       (Time),      Timer2.   Properties (   )   Enabled      False  True ( ),   Interval     100    1000 ( 1 ),     .

     ,         , , Resources.      ,   Solution Explorer      ,     Add, New Folder,            Enter.

       Windows XP Balloon.wav   :       ,     Add, Existing Item,   Add Existing Item   Files of type  All Files,     (,       )        Add (     ).   Solution Explorer    .

      win.wav.

,           ,     (      ,      Shift      ,      Ctrl        ).








. 20.13.   Images Collection Editor   Add  OK.

      (    )   Project  Add Windows Form,   Add New Item         Add.   VS    Form2     Solution Explorer   Form2.vb. ,  ,    (. 20.14),       Size (436; 223)      :  DataGridView   Size (288; 104),  Button   Reset (  Text)   CheckBox,     Name   isSoundOn,    Checked   True ( ).       ,   .








. 20.14.  Form2     .




20.4.   




  Form1.vb (,  : File, Open, File)    Form1       .

 20.1.   .

Dim matrix As Grid

Dim score As Integer = 0

Dim mouseOffset As Point

Dim paused As Boolean = False

Dim isSoundOn As Boolean = True

Private Sub BlockClick(ByVal sender As Object, _

ByVal e As System.Windows.Forms.MouseEventArgs)

' Play the sound.

If isSoundOn Then

'   :

My.Computer.Audio.Play( _

"..\..\Resources\Windows XP Balloon.wav", _

AudioPlayMode.WaitToComplete) '  .

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()

Me.PictureBox1.Width = Block.BlockSize * 12

Me.PictureBox1.Height = Block.BlockSize * 15

HighScores.SetUpHighScores()

' Setup the background color and the starting score.

Me.BackColor = Color.White

Me.ones.Image = Me.numbers.Images(0)

Me.tens.Image = Me.numbers.Images(0)

Me.hundreds.Image = Me.numbers.Images(0)

Me.Menu = Nothing

End Sub

    New Game    MenuStrip.   ,        .

 20.3. -  .

Private Sub NewGameToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles NewGameToolStripMenuItem.Click

StartNewGame()

End Sub

    Pause    MenuStrip.   ,        .

 20.4. -  .

Private Sub PauseToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles PauseToolStripMenuItem.Click

Me.Pause()

End Sub

    Restart    MenuStrip.   ,        .

 20.5. -  .

Private Sub RestartToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles RestartToolStripMenuItem.Click

Restart()

End Sub

    Options    MenuStrip.   ,        .

 20.6. -  .

Private Sub OptionsToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles OptionsToolStripMenuItem.Click

Dim optionsForm As New Form2

optionsForm.ShowDialog()

End Sub

    Exit    MenuStrip.   ,        .

 20.7. -  .

Private Sub ExitToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles ExitToolStripMenuItem.Click

Me.EndGame()

End Sub

     PictureBox   new.bmp (   Properties      Events      Click).   ,        .

 20.8. -   .

Private Sub newGame_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles newGame.Click

StartNewGame()

End Sub

     PictureBox   exit.bmp (   Properties      Events      Click).   ,        .

 20.9. -   .

Private Sub exitGame_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles exitGame.Click

EndGame()

End Sub

     PictureBox   options.bmp (   Properties      Events      Click).   ,        .

 20.10. -   .

Private Sub options_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles options.Click

ShowOptions()

End Sub

   ,   Properties (  Form1)   Events      MouseDown.   ,        .

 20.11. -   .

Private Sub Form1_MouseDown(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.MouseEventArgs) _

Handles MyBase.MouseDown

mouseOffset = New Point(-e.X, -e.Y)

End Sub

   ,   Properties (  Form1)   Events      MouseMove.   ,        .

 20.12. -  .

Private Sub Form1_MouseMove(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.MouseEventArgs) _

Handles MyBase.MouseMove

If e.Button = Windows.Forms.MouseButtons.Left Then

Dim mousePos As Point = Control.MousePosition

mousePos.Offset(mouseOffset.X, mouseOffset.Y)

Location = mousePos

End If

End Sub

    ,   Properties (  Form1)   Events      KeyPress.   ,        .

 20.13. -  .

Private Sub Form1_KeyPress(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.KeyPressEventArgs) _

Handles MyBase.KeyPress

Select Case e.KeyChar

Case "p"c, "P"c

If paused Then

Restart()

Else

Pause()

End If

Case "m"c, "M"c

If Me.FormBorderStyle = _

Windows.Forms.FormBorderStyle.Fixed3D Then

Me.FormBorderStyle = _

Windows.Forms.FormBorderStyle.None

Me.Menu = Nothing

Else

Me.FormBorderStyle = _

Windows.Forms.FormBorderStyle.Fixed3D

'Me.Menu = Me.MainMenu1

End If

Case Else

' Do nothing.

End Select

End Sub

    Interval        (   ),          Timer1 (   Properties      Events      Tick).   ,        .

 20.14. ,   Interval .

Private Sub Timer1_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Timer1.Tick

' Add another row to the grid and update the screen.

matrix.AddRow()

matrix.Draw(Me.PictureBox1.CreateGraphics(), _

Me.PictureBox1.BackColor)

End Sub

     (     Text)       (Time),          Timer2 (   Properties      Events      Tick).   ,        .

 20.15. ,   Interval .

' ,      

'  StartNewGame:

Dim secondCounter As Integer

'  :

Dim EndGameTime As Integer = 60

Private Sub Timer2_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Timer2.Tick

secondCounter = secondCounter + 1

Me.Text = "Time : " & secondCounter.ToString()

'  :

If secondCounter = EndGameTime Then

My.Computer.Audio.Play( _

"..\..\Resources\win.wav", _

AudioPlayMode.Background)

End If

End Sub

     , ,       Contents (   MenuStrip)           .

       Form1 (  Form1    ).

       (    ).        .

  ,        :  Solution Explorer      ,     Add, Existing Item,   Add Existing Item   Files of type  All Files,     (,    ,   ),        Add (      ).

  ,   Solution Explorer            Add, New Item,   Add New Item   Code File,   Name   Block.vb    Add.   (   Solution Explorer)   ,     ,       .

 20.16.  .

Imports System.Drawing.Drawing2D

''' <summary>

''' This class represents one of the balls in the game grid.

''' </summary>

''' <remarks></remarks>

Public Class Block

Public Const BlockSize As Integer = 25

Private colorValue As Color

Private deletionValue As Boolean = False

Private Shared rand As New Random

Public Property Color() As Color

Get

Return colorValue

End Get

Set(ByVal Value As Color)

colorValue = Value

End Set

End Property

Public Property MarkedForDeletion() As Boolean

Get

Return deletionValue

End Get

Set(ByVal Value As Boolean)

deletionValue = Value

End Set

End Property

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.

Dim matrix(11, 14) As Block

''' <summary>

''' Creates a few rows of blocks to start the game.

''' Game starts with Red, Blue, and Green blocks.

''' </summary>

''' <param name="nrows">Number of rows of blocks to create

''' to start the game.</param>

''' <remarks></remarks>

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

''' <summary>

''' A new row may be added at any time. New rows have Gray

''' blocks in addition

''' to Red, Blue, and Green. This makes the game more difficult.

''' </summary>

''' <remarks></remarks>

Public Sub AddRow()

Dim column As Integer

' Add a new block to each column.

For column = 0 To matrix.GetLength(1)  1

Dim newBlock As New Block(New Color() _

{Color.Red, Color.Blue, Color.Green, Color.Gray})

' Add the new block at the botttom of the column,



' and push the rest of the

' blocks up one column.

For row As Integer = matrix.GetLength(0)  1 To 1 Step -1

matrix(row, column) = matrix(row  1, column)

Next

matrix(0, column) = newBlock

Next

End Sub

''' <summary>

''' Draw the grid of blocks

''' </summary>

''' <param name="graphics"></param>

''' <param name="backColor"></param>

''' <remarks></remarks>

Public Sub Draw(ByVal graphics As Graphics, _

ByVal backColor As Color)

graphics.Clear(backColor)

Dim row As Integer

Dim column As Integer

Dim theBlock As Block

For row = 0 To matrix.GetLength(0)  1

For column = 0 To matrix.GetLength(1)  1

theBlock = matrix(row, column)

If Not theBlock Is Nothing Then

Dim pointA As New Point( _

column * Block.BlockSize, _

row * Block.BlockSize)

matrix(row, column).Draw(graphics, pointA)

End If

Next

Next

End Sub

''' <summary>

''' This method responds to a click event in the UI.

''' </summary>

''' <param name="point"></param>

''' <returns>The number of blocks removed from the grid.</returns>

''' <remarks></remarks>

Public Function Click(ByVal point As Point) As Integer

' Figure out row and column.

Dim total As Integer

Dim transPt As Point = PointTranslator.TranslateToTL(point)

Dim selectedRow As Integer = transPt.Y \ Block.BlockSize

Dim selectedColumn As Integer = transPt.X \ Block.BlockSize

Dim selectedBlock As Block = matrix(selectedRow, _

selectedColumn)

If Not selectedBlock Is Nothing Then

selectedBlock.MarkedForDeletion = True

' Determine if any of the neighboring blocks are

' the same color.

FindSameColorNeighbors(selectedRow, selectedColumn)

' Determine how many blocks would be eliminated.

total = Me.CalculateScore()

If total > 1Then

Me.CollapseBlocks()

Else

Me.ClearMarkedForDeletion()

End If

End If

Return total

End Function

Private Sub ClearMarkedForDeletion()

Dim row As Integer

Dim column As Integer

For column = matrix.GetLength(1)  1 To 0 Step -1

' If column is completely empty, then move everthing

' down one.

For row = 0 To matrix.GetLength(0)  1

If Not matrix(row, column) Is Nothing Then

matrix(row, column).MarkedForDeletion = False

End If

Next

Next

End Sub

''' <summary>

''' Find out how many blocks will be eliminated.

''' </summary>

''' <returns></returns>

''' <remarks></remarks>

Private Function CalculateScore() As Integer

Dim row As Integer

Dim column As Integer

Dim total As Integer = 0

For column = matrix.GetLength(1)  1 To 0 Step -1

' If column is completely empty, then move everthing

' down one.

For row = 0 To matrix.GetLength(0)  1

If Not matrix(row, column) Is Nothing Then

If matrix(row, column).MarkedForDeletion Then

total += 1

End If

End If

Next

Next

Return total

End Function

''' <summary>

''' After the blocks are removed from the columns, there may be

''' columns that are empty. Move columns from right to left to

''' fill in the empty columns.

''' </summary>

''' <remarks></remarks>

Public Sub CollapseColumns()

Dim row As Integer

Dim column As Integer

For column = matrix.GetLength(1)  1 To 0 Step -1

' If column is completely empty, then all the columns

' over one.

Dim noBlocks As Boolean = True

For row = 0 To matrix.GetLength(0)  1

If Not matrix(row, column) Is Nothing Then

noBlocks = False

End If

Next

If noBlocks Then

Dim newcol As Integer

For newcol = column To matrix.GetLength(1)  2

For row = 0 To matrix.GetLength(0)  1

matrix(row, newcol) = matrix(row, newcol + 1)

Next

Next

newcol = matrix.GetLength(1)  1

For row = 0 To matrix.GetLength(0)  1

matrix(row, newcol) = Nothing

Next

End If

Next



End Sub

''' <summary>

''' Remove all the blocks from the grid.

''' </summary>

''' <remarks></remarks>

Public Sub CollapseBlocks()

Dim theBlock As Block

Dim column As Integer

Dim row As Integer

Dim aRow As Integer

' First remove the blocks from each column.

For column = 0 To matrix.GetLength(1)  1

For row = matrix.GetLength(0)  1 To 0 Step -1

theBlock = matrix(row, column)

If (Not theBlock Is Nothing) Then

If theBlock.MarkedForDeletion Then

For aRow = row To matrix.GetLength(0)  2

matrix(aRow, column) = _

matrix(aRow + 1, column)

Next

matrix(matrix.GetLength(0)  1, _

column) = Nothing

End If

End If

Next

Next

' Reset the MarkedForDeletion flags.

For row = 0 To matrix.GetLength(0)  1

For column = 0 To matrix.GetLength(1)  1

theBlock = matrix(row, column)

If Not theBlock Is Nothing Then

theBlock.MarkedForDeletion = False

End If

Next

Next

' Remove any columns that are now empty.

CollapseColumns()

End Sub

''' <summary>

''' Provides access into the grid.

''' </summary>

''' <param name="row"></param>

''' <param name="column"></param>

''' <value></value>

''' <remarks></remarks>

Default Public Property Item(ByVal row As Integer, _

ByVal column As Integer) As Block

Get

Return matrix(row, column)

End Get

Set(ByVal Value As Block)

matrix(row, column) = Value

End Set

End Property

Private blocksToExamine As ArrayList

''' <summary>

''' Set MarkedForDeletion to True for each neighboring block

''' of the same color.

''' </summary>

''' <param name="row"></param>

''' <param name="column"></param>

''' <remarks></remarks>

Private Sub FindSameColorNeighbors(ByVal row As Integer, _

ByVal column As Integer)

Dim color As Color = matrix(row, column).Color

blocksToExamine = New ArrayList

blocksToExamine.Add(New Point(row, column))

matrix(row, column).MarkedForDeletion = True

' Each time you find a neighbor, mark it for deletion, and

' add it to the list of blocks to look for neighbors.

' After you

' examine it, remove it from the list. Keep doing this

' until there are no more blocks to look at.

While blocksToExamine.Count > 0

FindNeighbors()

End While

End Sub

''' <summary>

''' Look to the blocks on each side.

''' </summary>

''' <remarks></remarks>

Private Sub FindNeighbors()

' Take the first block out of the arraylist and examine it.

Dim location As Point = CType(blocksToExamine(0), Point)

Dim currentBlock As Block = matrix(location.X, location.Y)

Dim row As Integer = location.X

Dim column As Integer = location.Y

blocksToExamine.RemoveAt(0)

Dim nextRow As Integer

Dim nextCol As Integer

Dim selected As Block

' look up

If row < matrix.GetLength(0)  1 Then

nextRow = row + 1

selected = matrix(nextRow, column)

ExamineNeighbor(selected, nextRow, column, _

currentBlock.Color)

End If

' look down

If row > 0Then

nextRow = row  1

selected = matrix(nextRow, column)

ExamineNeighbor(selected, nextRow, column, _

currentBlock.Color)

End If

' look left

If column > 0Then

nextCol = column  1

selected = matrix(row, nextCol)

ExamineNeighbor(selected, row, nextCol, _

currentBlock.Color)

End If

' look right

If column < matrix.GetLength(1)  1 Then

nextCol = column + 1

selected = matrix(row, nextCol)

ExamineNeighbor(selected, row, nextCol, _

currentBlock.Color)

End If

End Sub

''' <summary>

''' If the neighbor is the same color, add it to the blocks

''' to examine.

''' </summary>

''' <param name="selected"></param>

''' <param name="row"></param>

''' <param name="column"></param>

''' <param name="color"></param>

''' <remarks></remarks>

Private Sub ExamineNeighbor(ByVal selected As Block, _

ByVal row As Integer, ByVal column As Integer, _

ByVal color As Color)

If Not selected Is Nothing Then

If selected.Color.Equals(color) Then

If Not selected.MarkedForDeletion Then

selected.MarkedForDeletion = True

blocksToExamine.Add(New Point(row, column))

End If

End If

End If

End Sub

End Class

  ,   Solution Explorer            Add, New Item,   Add New Item   Code File,   Name   HighScore.vb    Add.   (   Solution Explorer)   ,     ,       .

 20.18.  .

''' <summary>

''' Represents one high score.

''' </summary>

''' <remarks></remarks>

Public Class HighScore

Implements IComparable

Public nameValue As String

Public scoreValue As Integer

Public Property Name() As String

Get

Return nameValue

End Get

Set(ByVal Value As String)

nameValue = Value

End Set

End Property

Public Property Score() As Integer

Get

Return scoreValue

End Get

Set(ByVal Value As Integer)

scoreValue = Value

End Set

End Property

Public Overrides Function ToString() As String

Return Name & ":" & Score

End Function

Public Sub New(ByVal saved As String)

Name = saved.Split(":".ToCharArray)(0)

Score = CInt(saved.Split(":".ToCharArray)(1))

End Sub

Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo

Dim other As HighScore

other = CType(obj, HighScore)

Return Me.Score  other.Score

End Function

End Class

  ,   Solution Explorer            Add, New Item,   Add New Item   Code File,   Name   HighScores.vb    Add.   (   Solution Explorer)   ,     ,       .

 20.19.  .

Imports Microsoft.Win32

''' <summary>

''' Reads and writes the top three high scores to the registry.

''' </summary>

''' <remarks></remarks>

Public Class HighScores

''' <summary>

''' Read scores from the registry.

''' </summary>

''' <returns></returns>

''' <remarks></remarks>

Public Shared Function GetHighScores() As HighScore()

Dim tops(2) As HighScore

Dim scoreKey As RegistryKey = Registry.CurrentUser. _

CreateSubKey("Software\VBSamples\Collapse\HighScores")

For index As Integer = 0 To 2

Dim key As String = "place" & index.ToString

Dim score As New HighScore(CStr(scoreKey.GetValue(key)))

tops(index) = score

Next

scoreKey.Close()

Return tops

End Function

''' <summary>

''' Update and write the high scores.

''' </summary>

''' <param name="score"></param>

''' <remarks></remarks>

Public Shared Sub UpdateScores(ByVal score As Integer)

Dim tops(3) As HighScore

Dim scoreKey As RegistryKey = Registry.CurrentUser. _

CreateSubKey("Software\VBSamples\Collapse\HighScores")

tops(0) = New HighScore(scoreKey.GetValue("Place0").ToString)

tops(1) = New HighScore(scoreKey.GetValue("Place1").ToString)

tops(2) = New HighScore(scoreKey.GetValue("Place2").ToString)

If score > tops(2).Score Then

Dim name As String = InputBox("New high score of " & _

score & " for:")

tops(3) = New HighScore(" :0")

tops(3).Name = name

tops(3).Score = score

Array.Sort(tops)

Array.Reverse(tops)

scoreKey.SetValue("Place0", tops(0).ToString)

scoreKey.SetValue("Place1", tops(1).ToString)

scoreKey.SetValue("Place2", tops(2).ToString)

End If

scoreKey.Close()

End Sub

''' <summary>

''' Set up the entries for new scores.

''' </summary>

''' <remarks></remarks>

Shared Sub SetUpHighScores()

Dim scoreKey As RegistryKey = Registry.CurrentUser. _

CreateSubKey("Software\VBSamples\Collapse\HighScores")

If scoreKey.GetValue("Place1") Is Nothing Then

scoreKey.SetValue("Place0", " :0")

scoreKey.SetValue("Place1", " :0")

scoreKey.SetValue("Place2", " :0")

End If

scoreKey.Close()

End Sub

''' <summary>

''' Reset scores.

''' </summary>

''' <remarks></remarks>

Shared Sub ResetScores()

Dim scoreKey As RegistryKey = Registry.CurrentUser. _

CreateSubKey("Software\VBSamples\Collapse\HighScores")

scoreKey.SetValue("Place0", " :0")

scoreKey.SetValue("Place1", " :0")

scoreKey.SetValue("Place2", " :0")

scoreKey.Close()

End Sub

End Class

  ,   Solution Explorer            Add, New Item,   Add New Item   Code File,   Name   PointTranslator.vb    Add.   (   Solution Explorer)   ,     ,       .

 20.20.  .

''' <summary>

''' Form coordinates have the top, left as (0,0). For the game grid,

''' it is easier to have the bottom left of the grid as (0,0). This

''' translates the points.

''' </summary>

''' <remarks></remarks>

Public Class PointTranslator

Private Shared graphicsValue As Graphics

Private Shared height As Integer

Public Shared Property Graphics() As Graphics

Get

Return graphicsValue

End Get

Set(ByVal Value As Graphics)

graphicsValue = Value

height = CInt(graphicsValue.VisibleClipBounds.Height())

End Set

End Property

' Translates an (X,Y) point from the top left to

' an (X, Y) point from the bottom left.

Public Shared Function TranslateToBL(ByVal topleft As Point) _

As Point

Dim newPoint As Point

newPoint.X = topleft.X

newPoint.Y = height  topleft.Y

Return newPoint

End Function

Public Shared Function TranslateToTL(ByVal bottomleft As Point) _

As Point

Dim newPoint As Point

newPoint.X = bottomleft.X

newPoint.Y = height  bottomleft.Y

Return newPoint

End Function

End Class

   ( Block.vb, Grid.vb, HighScore.vb, HighScores.vb, PointTranslator.vb)   Solution Explorer   ,  .     ,    ,   .

       ,    Form2    .

  Form2.vb (,  : File, Open, File)    Form2     .

 20.21. .

Public Property SoundOn() As Boolean

Get

Return Me.isSoundOn.Checked

End Get

Set(ByVal Value As Boolean)

Me.isSoundOn.Checked = Value

End Set

End Property

  Properties ( Form2)   Events      Load ().    Form2_Load       .

 20.22.     .

Private Sub Form2_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

Me.DataGridView1.DataSource = HighScores.GetHighScores()

End Sub

  Form2     Button.    (   ),        .

 20.23. -  .

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

HighScores.ResetScores()

Me.DataGridView1.DataSource = HighScores.GetHighScores()

End Sub

  ,       Beep (-: )  .




20.5.  




       :

Build, Build Selection; Debug, Start Without Debugging.

  Visual Studio    ,       (      ...  Random)          ,   ,   .

         ,        ( )     (     ).

  ,      ( )   ( )   ,     10     .

        ,             (   ).

                      .




 21.           5     








21.1.   




                ,       , , 9 x 9    (      ...  Random)   ,    3  , , 3  ,       ,  3   ,    ,         (           ).

        ()   ,        ( )   . ,    ,  .        ,     ,       .     .          3    .

           ,    .           3    .

    ,       5     ,    ( 100       ),      ,     .

        ,             .     (              )   3    ( ).

    ,   Line ( lines_vbnet.zip   )  ,      Visual Studio.           Visual Studio,          , ,         .

  Solution Explorer (  )       BlackBall.png     .     Visual Studio    ,         (. 21.1)    . ,          (  ,  )    ,          .              .

    :

My.Computer.Audio.Play("..\..\Sounds\drumpad-crash.wav")

          ,   :

' ,      

'  NewGame:

Dim secondCounter As Integer

',    

'  :

Dim EndGameTime As Integer = 60

Private Sub tmr2_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles tmr2.Tick

DDTime.number += 1

lblTime.Refresh()

' :

secondCounter = secondCounter + 1

'  :

If secondCounter = EndGameTime Then

My.Computer.Audio.Play("..\..\Sounds\win.wav", _

AudioPlayMode.Background)

End If

End Sub

      60 .    ,       ,              .








. 21.1.   Visual Studio   .




21.2.  


1.    (  )      (. 21.2).

2.         .

  (    )  InputBox     (. 21.3).  (   )     OK (   Enter, ,   ,     ).








. 21.2.  .








. 21.3.     .

3.       9 x 9   (  ...  Random)  3   ,       ,  3   ,    ,         (           ).

   ,        (. 21.4).

4.         ,         ()  ,        ( )   .

        ,         ()  ,       ( ,   )  .








. 21.4. 3   3  ,     .

,    ,   (  ,     ).

      .      ,     ,    .

   :   3 ,       ,         .

      ,     ,        .

    .

,             ,       ,             (                 ).    ,       (  )                 ( ,      ).

5.          3    ,  3        (       5   ), . 21.5.

   :      3 ,             .

6.            ,    .           3    ,  3        (       5   ).








. 21.5.   3  ,  3      .








. 21.6.     5     6- .

7.  . 21.6 ,      5     6- .

8.        6-    ,       6  .

    ,       5     ,    ( 100       ),      ,  ,         .

 . 21.7   600 .

9.         ,             .

    (              )    5    (    ),  ,   3    ( ),  3        (       5   )..








. 21.7.   600 .

10.    (,    )         .

   MessageBox.Show    (. 21.8):

:

:

 : (/).

11.          .








. 21.8.  MessageBox.Show   .

12.  ,         .

   ()        ,   , 60 ,       win.wav.

         .

13.            .

14.           (     Close).

            ,        ,              (     ZharkovPress.ru) .




21.3.  




    : VS   New Project   Project types    Visual Basic, Windows,   Templates   Windows Forms Application,   Name    Line   OK.  ,   Form1    (. 21.9).      ,        .       ,    Properties ( Form1)   Size  , , 880; 630.    Window      BackColor.

       -    .   ,    Toolbox      MenuStrip     (    ).   Form1     Type Here ( ),        :

File, New Game, Save, Load, Exit;

Score, Show Score, Calculate Avg;

Help, Help, About.

   Properties (  )   Text      :

, , , , ;

, ,  ;

, ,   (. 21.10  21.12).








. 21.9.  Form1   .












. 21.10.   . . 21.11.   . . 21.12.  .

   Toolbox      Label.   Properties (  )   Location       430; 124,   Name    lblName,   Font     28,   Text  :.

        Label.   Properties (  )   Location       568; 124,   Name    lblNameShow,   Font     28,   Text  .

    Label.   Properties (  )   Location       430; 212,   Name    lblScore,   Font     28,   Text  :  (       ).

    Label.   Properties (  )   Location       430; 302,   Name    lblTime,   Font     28,   Text  :  (    ,      ).

    Label.   Properties (  )   Location       430; 392,   Name    lblBallPreview,   Font     28,   Text   :.

      PictureBox.   Properties (  )   Location       453; 477,   Size   52; 52,   Name    picBallPre1.

    PictureBox.   Properties (  )   Location       510; 477,   Size   52; 52,   Name    picBallPre2.

    PictureBox.   Properties (  )   Location       568; 477,   Size   52; 52,   Name    picBallPre3.

    Interval       ,    Toolbox    (,  )   Timer.   Properties (  )   Name   tmr1,   Enabled      False, ..             (Timer1.Enabled = True).    Interval     100  , ,  150 .

         (Time),      Timer.   Properties (  )   Name   tmr2,   Enabled      False,    Interval  1000  ( 1 ).

     ,         , , Sounds.      ,   Solution Explorer      ,     Add, New Folder,            Enter.

      drumpad-crash.wav  win.wav   :       ,     Add, Existing Item,   Add Existing Item   Files of type  All Files,     (,       )     Ctrl       Add.   Solution Explorer     (. 21.13).   Properties       .















. 21.13.  Solution Explorer. . 21.14.  Properties.

       :  Solution Explorer      ,     Add, Existing Item ( Project, Add Existing Item),   Add Existing Item   Files of type  All Files,     (,       )     Ctrl       Add.   Solution Explorer     (. 21.13).   Properties        (. 21.14).

      (    )   Project  Add Windows Form,   Add New Item         Add.   VS    Form2     Solution Explorer   Form2.vb.   Form2,          ,       .

   Toolbox    Form2 (,  )   Timer.   Properties (  )   Enabled      False, ..             (Timer1.Enabled = True).    Interval     100  , ,  20 .

    Form2   Timer.   Properties (  )   Enabled      False,    Interval  40 .

      Form3,          .   Form3  -  , , TextBox,     , ,      .

     ,           .

      ,   .




21.4.  




  Form1.vb (, : File, Open, File)         :

Imports System.IO '  StreamWriter.

,       ,           .

   Form1       .

 21.1.   .

Const intBaseX As Integer = 10

Const intBaseY As Integer = 120

Dim Rand As New Random

'***

Dim playerName As String

Dim playerScore As Double

Dim playerTime As Integer

Dim DDScore As New DPaint

Dim DDTime As New DPaint

'***

Dim intFlag As Integer = -1

Dim flagMadeNew = 0

Dim posMoveTo As Integer

Dim MPBoxes(80) As MotionPic

Dim ThreeBI(2) As Integer

Dim ThreeBP(2) As Integer

Dim prePic(2) As PictureBox

Private Sub InitBoard(ByVal plName As String, _

ByVal plScore As Double, ByVal plTime As Integer)

playerName = plName

playerScore = plScore

playerTime = plTime

If flagMadeNew = 0 Then

Dim i As Integer

Dim intX = intBaseX + 2

Dim intY = intBaseY + 2

For i = 0 To 80

Dim MP As New MotionPic(New Size(36, 36), _

New Point(intX, intY))

MP.SizeMode = PictureBoxSizeMode.StretchImage

intX += 45

If (i + 1) Mod 9 = 0 Then

intY += 45

intX = intBaseX + 2

End If

AddHandler MP.Click, AddressOf Ball_Click

MPBoxes(i) = MP

Next

Me.Controls.AddRange(MPBoxes)

DDScore.width = lblScore.Height / 2  6

DDScore.thick = DDScore.width / 4

DDScore.position = New Point(lblScore.Width  _

(DDScore.width + 2) * 9, lblScore.Height / 2)

DDTime.width = lblTime.Height / 2  6

DDTime.thick = DDTime.width / 4

DDTime.position = New Point(lblTime.Width  _

(DDTime.width + 2) * 9, lblTime.Height / 2)

AddHandler lblScore.Paint, AddressOf LabelScore_Paint

lblScore.Refresh()

AddHandler lblTime.Paint, AddressOf LabelTime_Paint

lblTime.Refresh()

For i = 0 To 2

prePic(i) = New PictureBox

prePic(i).SizeMode = PictureBoxSizeMode.StretchImage

prePic(i).Size = New Size(16, 16)

prePic(i).Visible = False

Me.Controls.Add(prePic(i))

AddHandler prePic(i).Click, AddressOf PrePic_Click

prePic(i).BringToFront()

Next

Else

ResetBoard()

End If

lblNameShow.Text = playerName

If playerName.Length > 8Then

lblNameShow.Text += " "

tmr1.Enabled = True

End If

tmr2.Enabled = True

DDScore.number = plScore

lblScore.Refresh()

DDTime.number = plTime

lblTime.Refresh()

PreShow()

End Sub

Private Sub FindSol(ByVal i As Integer)

If MPBoxes(i).Tag <> "" Or MPBoxes(i).Tag = "Here" Then

Return

Else

MPBoxes(i).Tag = "Here"

End If

Select Case TestABox(i)

Case 1

FindSol(1)

FindSol(9)

Case 2

FindSol(7)

FindSol(17)

Case 3

FindSol(71)

FindSol(79)

Case 4

FindSol(63)

FindSol(73)

Case 5

FindSol(i + 1)

FindSol(i + 9)

FindSol(i  1)

Case 6

FindSol(i  9)

FindSol(i  1)

FindSol(i + 9)

Case 7

FindSol(i  1)

FindSol(i  9)

FindSol(i + 1)

Case 8

FindSol(i  9)

FindSol(i + 1)

FindSol(i + 9)

Case Else

FindSol(i  9)

FindSol(i + 9)

FindSol(i + 1)

FindSol(i  1)

End Select

End Sub

Private Sub ResetAllTag()

For Each Pic As MotionPic In MPBoxes

If Pic.Tag = "Here" Then

Pic.Tag = ""

End If

Next

End Sub

Private Function TestABox(ByVal val As Integer)

Select Case val

Case 0 : Return 1

Case 8 : Return 2

Case 80 : Return 3

Case 72 : Return 4

Case 1 To 7 : Return 5

Case 73 To 79 : Return 7

Case 17, 26, 35, 44, 53, 62, 71 : Return 6

Case 9, 18, 27, 36, 45, 54, 63 : Return 8

Case Else : Return 0

End Select

End Function



'Serious trouble happened  think more

Private Function GiveThreeBalls() As Boolean

If ThreeBI(1) = -1 Then 'Review for Game over

Return False

Else

For i As Integer = 0 To 2

If ThreeBI(i) = -1 Then

Exit For

Else

If MPBoxes(ThreeBP(i)).MPState = BallState. _

NO_BALL And ThreeBP(i) <> posMoveTo Then

MPBoxes(ThreeBP(i)).Init(ThreeBI(i))

CalWin(ThreeBP(i))

End If

End If

Next

End If

RandomThreeBalls()

PreShow()

Return True

End Function

Private Function IsFullBoard() As Boolean

Dim i As Integer

For Each Pic As PictureBox In MPBoxes

If MPBoxes(i).MPState <> BallState.NO_BALL Then

i += 1

End If

Next

If i = 81 Then

Return True

Else

Return False

End If

End Function

Private Sub RandomThreeBalls()

Dim ArrL As New ArrayList

Dim i As Integer

Dim pos As Integer

Dim ind As Integer

For i = 0 To 80

If MPBoxes(i).MPState = BallState.NO_BALL Or _

MPBoxes(i).MPState = BallState.DESTROYING_BALL Then

ArrL.Add(i)

End If

Next

For i = 0 To IIf(ArrL.Count > 2, 2, ArrL.Count  1)

pos = Rand.Next(0, ArrL.Count)

pos = CInt(ArrL(pos))

ArrL.Remove(pos)

ThreeBP(i) = pos

ind = Rand.Next(0, 12)

ind = (ind \ 2) * 2

ThreeBI(i) = ind

Next

For j As Integer = i To 2

ThreeBI(j) = -1

ThreeBP(j) = -1

Next

End Sub

'#Region "Check for Calculate Score"

Private Function CheckHor(ByVal pos As Integer) As Integer

Dim type As Integer = MPBoxes(pos).MPIndex

Dim i As Integer = (pos \ 9) * 9

Dim count As Integer

Dim startpos As Integer = i

Dim endpos As Integer = i

While i < (pos \ 9) * 9 + 9

If MPBoxes(i).MPIndex = type Then

endpos += 1

count = endpos  startpos

Else

If count > 4Then

While MPBoxes(pos).MPState = _

BallState.ZOOMING_BALL

Application.DoEvents()

End While

For j As Integer = 0 To count  1

MPBoxes(startpos + j).Destroy()

Next

Return count

End If

If i >= (pos \ 9) * 9 + 5 Then

Return count

End If

startpos = i + 1

endpos = i + 1

End If

i += 1

End While

If count > 4Then

While MPBoxes(pos).MPState = BallState.ZOOMING_BALL

Application.DoEvents()

End While

For j As Integer = 0 To count  1

MPBoxes(startpos + j).Destroy()

Next

Return count

End If

End Function

Private Function CheckVer(ByVal pos As Integer) As Integer

Dim type As Integer = MPBoxes(pos).MPIndex

Dim i As Integer = pos Mod 9

Dim count As Integer

Dim startpos As Integer = i

Dim endpos As Integer = i

While i < (pos Mod 9) + 73

If MPBoxes(i).MPIndex = type Then

endpos += 9

count = (endpos  startpos) / 9

Else

If count > 4Then

While MPBoxes(pos).MPState = _

BallState.ZOOMING_BALL

Application.DoEvents()

End While

For j As Integer = 0 To count  1

MPBoxes(startpos + j * 9).Destroy()

Next

Return count

End If

If i >= (pos Mod 9) + 36 Then

Return count

End If

startpos = i + 9

endpos = i + 9

End If

i += 9

End While

If count > 4Then

While MPBoxes(pos).MPState = BallState.ZOOMING_BALL

Application.DoEvents()

End While

For j As Integer = 0 To count  1

MPBoxes(startpos + j * 9).Destroy()

Next

Return count

End If

End Function

Private Function CheckLR(ByVal pos As Integer) As Integer

If pos = 5 Or pos = 6 Or pos = 7 Or pos = 8 Or pos = 15 _

Or pos = 16 Or pos = 17 _

Or pos = 25 Or pos = 26 Or pos = 35 Or pos = 45 _

Or pos = 54 Or pos = 55 _

Or pos = 63 Or pos = 64 Or pos = 65 Or pos = 72 _

Or pos = 73 Or pos = 74 Or pos = 75 Then

Return 0

End If

Dim type As Integer = MPBoxes(pos).MPIndex

Dim i As Integer = pos Mod 10

i = IIf(i = 8, 18, IIf(i = 7, 27, IIf(i = 6, 36, i)))

Dim count As Integer

Dim startpos As Integer = i

Dim endpos As Integer = i

Dim tempi As Integer = i + 1

Dim temp As Integer

If i < 9Then

temp = 9  i

Else

temp = 9  (i \ 9)

End If

While i < tempi + (temp  1) * 10

If MPBoxes(i).MPIndex = type Then

endpos += 10

count = (endpos  startpos) \ 10

Else

If count > 4Then

While MPBoxes(pos).MPState = _

BallState.ZOOMING_BALL

Application.DoEvents()

End While

For j As Integer = 0 To count  1

MPBoxes(startpos + j * 10).Destroy()

Next

Return count

End If

If i >= pos + 40 Then

Return count

End If

startpos = i + 10

endpos = i + 10

End If

i += 10

End While

If count > 4Then

While MPBoxes(pos).MPState = BallState.ZOOMING_BALL

Application.DoEvents()

End While

For j As Integer = 0 To count  1

MPBoxes(startpos + j * 10).Destroy()

Next

Return count

End If

End Function

Private Function CheckRL(ByVal pos As Integer) As Integer

If pos = 0 Or pos = 1 Or pos = 2 Or pos = 3 Or pos = 9 _

Or pos = 10 Or pos = 11 _

Or pos = 18 Or pos = 19 Or pos = 27 Or pos = 53 _

Or pos = 61 Or pos = 62 _

Or pos = 69 Or pos = 70 Or pos = 71 Or pos = 77 _

Or pos = 78 Or pos = 79 Or pos = 80 Then

Return 0

End If

Dim type As Integer = MPBoxes(pos).MPIndex

Dim i As Integer = pos Mod 8

If i = 0 Then

i = 8

ElseIf i < 4Then

i = (i + 1) * 8 + i

ElseIf pos \ 8 >= 5 Then

i = 45

End If

Dim count As Integer

Dim startpos As Integer = i

Dim endpos As Integer = i

Dim tempi As Integer = i + 1

Dim temp As Integer

If i < 9Then

temp = i + 1

Else

temp = 9  (i \ 8)

End If

While i < tempi + temp * 8

If MPBoxes(i).MPIndex = type Then

endpos += 8

count = (endpos  startpos) \ 8

Else

If count > 4Then

While MPBoxes(pos).MPState = _

BallState.ZOOMING_BALL

Application.DoEvents()

End While

For j As Integer = 0 To count  1

MPBoxes(startpos + j * 8).Destroy()

Next

Return count

End If

If i >= pos + 32 Then

Return count

End If

startpos = i + 8

endpos = i + 8

End If

i += 8

End While

If count > 4Then

While MPBoxes(pos).MPState = BallState.ZOOMING_BALL

Application.DoEvents()

End While

For j As Integer = 0 To count  1

MPBoxes(startpos + j * 8).Destroy()

Next

Return count

End If

End Function

Private Function CalWin(ByVal pos As Integer) As Integer

Dim point As Integer = CheckHor(pos)

If point < 4Then

point = CheckVer(pos)

End If

If point < 4Then

point = CheckLR(pos)

End If

If point < 4Then

point = CheckRL(pos)

End If

If point > 4Then

Dim dpoint As Double = point * 100 + (dpoint \ 6) * 100

Dim n As Double = DDScore.number + dpoint

For i As Double = DDScore.number To n Step 10

DDScore.number = i

lblScore.Refresh()

Next

DDScore.number = n

Return point

Else

Return 0

End If

End Function

'#Region "Ball Event And Paint Board"

Private Sub Ball_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs)

CType(sender, MotionPic).Jump()

If CType(sender, MotionPic).MPState <> _

BallState.NO_BALL Then

If intFlag <> -1 Then

MPBoxes(intFlag).Jump()

End If

'intFlag = MPBoxes.IndexOf(MPBoxes, sender)

' :

intFlag = Array.IndexOf(MPBoxes, sender)

ElseIf intFlag <> -1 Then

Dim tempS As String = MPBoxes(intFlag).Tag

MPBoxes(intFlag).Tag = ""

FindSol(intFlag)

If sender.tag = "Here" Then

'posMoveTo = MPBoxes.IndexOf(MPBoxes, sender)

' :

posMoveTo = Array.IndexOf(MPBoxes, sender)

If posMoveTo = ThreeBP(0) Then

prePic(0).SendToBack()

ElseIf posMoveTo = ThreeBP(1) Then

prePic(1).SendToBack()

ElseIf posMoveTo = ThreeBP(2) Then

prePic(2).SendToBack()

End If

CType(sender, MotionPic).Init(MPBoxes(intFlag). _

MPIndex)

MPBoxes(intFlag).Destroy()

While MPBoxes(intFlag).MPState = _

BallState.DESTROYING_BALL

Application.DoEvents()

End While

If CalWin(posMoveTo) = 0 Then

If GiveThreeBalls() = False Then

playerScore = DDScore.number

Dim frm As Form2 = New Form2

frm.AddPlayer() = _

New Player(playerName, playerScore)

frm.Show()

frm.PlashScreen()

frm.drawTable()

ResetBoard()

End If

End If

PreShow()

intFlag = -1

Else

MPBoxes(intFlag).Tag = tempS

End If

ResetAllTag()

End If

End Sub

Private Sub ResetBoard()

ThreeBI(0) = -1

tmr1.Enabled = False

tmr2.Enabled = False

playerScore = 0

playerTime = 0

DDScore.number = 0

DDTime.number = 0

Me.Refresh()

PreShow()

lblNameShow.Text = ""

picBallPre1.Image = Nothing

For i As Integer = 0 To 80

MPBoxes(i).Reset()

Next

End Sub

Private Sub DrawBoard(ByVal sender As Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) _

Handles MyBase.Paint

Dim g As Graphics = e.Graphics

'    (Red) :

Dim p1 As New Pen(Color.Red)

Dim p2 As New Pen(Color.Black)

For i As Integer = 0 To 9

g.DrawLine(p1, intBaseX + 45 * i  4, intBaseY  5, _

intBaseX + 45 * i  4, intBaseY + 45 * 9  5)

g.DrawLine(p2, intBaseX + 45 * i  3, intBaseY  4, _

intBaseX + 45 * i  3, intBaseY + 45 * 9  4)

g.DrawLine(p1, intBaseX  4, intBaseY + 45 * i  5, _

intBaseX + 45 * 9  4, intBaseY + 45 * i  5)

g.DrawLine(p2, intBaseX  3, intBaseY + 45 * i  4, _

intBaseX + 45 * 9  3, intBaseY + 45 * i  4)

Next

End Sub

Private Sub LabelScore_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs)

DDScore.showNumber(e.Graphics)

End Sub

Private Sub LabelTime_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs)

DDTime.showTime(e.Graphics)

End Sub

Private Sub tmr1_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles tmr1.Tick

Dim s As String = lblNameShow.Text

lblNameShow.Text = s.Substring(1) + s.Substring(0, 1)

End Sub

' ,      

'  NewGame:

Dim secondCounter As Integer

',    

'  :

Dim EndGameTime As Integer = 60

Private Sub tmr2_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles tmr2.Tick

DDTime.number += 1

lblTime.Refresh()

' :

secondCounter = secondCounter + 1

'  :

If secondCounter = EndGameTime Then

My.Computer.Audio.Play("..\..\Sounds\win.wav", _

AudioPlayMode.Background)

End If

End Sub

'#Region "Preview Balls"

Private Sub PreShow()

Dim col, row As Integer

For i As Integer = 0 To 2

If ThreeBI(i) = -1 Then

prePic(i).Visible = False

Else

prePic(i).Visible = True

prePic(i).Image = Image.FromFile(ImgList(ThreeBI(i)))

col = ThreeBP(i) Mod 9

row = ThreeBP(i) \ 9

prePic(i).Location = New Point(col * 45 + _

intBaseX + (38  prePic(i).Width) / 2, _

row * 45 + intBaseY + (38  prePic(i).Height) / 2)

prePic(i).Visible = True

prePic(i).BringToFront()

End If

If ThreeBI(0) <> -1 Then

picBallPre1.Visible = True

picBallPre1.Image = _

Image.FromFile(ImgList(ThreeBI(0)))

End If

If ThreeBI(1) <> -1 Then

picBallPre2.Visible = True

picBallPre2.Image = _

Image.FromFile(ImgList(ThreeBI(1)))

Else

picBallPre2.Visible = False

End If

If ThreeBI(2) <> -1 Then

picBallPre3.Visible = True

picBallPre3.Image = _

Image.FromFile(ImgList(ThreeBI(2)))

Else

picBallPre3.Visible = False

End If

Next

End Sub

Private Sub PrePic_Click(ByVal sender As Object, _

ByVal e As System.EventArgs)

Dim i As Integer = Array.IndexOf(prePic, sender)

Dim MP As MotionPic = MPBoxes(ThreeBP(i))

Call Ball_Click(MP, e)

End Sub

'#Region "Save and Load Game"

Private Sub SaveGame()

Dim strNewLine = Chr(13) + Chr(10)

Dim s As String = Nothing

playerScore = DDScore.number

playerTime = DDTime.number

s += "#Assignment Line" +strNewLine

s += playerName.ToString + strNewLine

s += playerScore.ToString + strNewLine

s += playerTime.ToString + strNewLine

For i As Integer = 0 To 2

s += ThreeBI(i).ToString + ";" +ThreeBP(i).ToString

If i < 2Then

s += ","

End If

Next

s += strNewLine

For i As Integer = 0 To 80

s += MPBoxes(i).MPState.ToString + ";" +_

MPBoxes(i).MPIndex.ToString

If i < 80 Then

s += ","

End If

Next

Dim SW As StreamWriter = Nothing

Try

SW = New StreamWriter("LSF.vmt")

SW.Write(s)

Catch IOE As IOException

MessageBox.Show("Can't save File !", "Error", _

MessageBoxButtons.OK, MessageBoxIcon.Error)

Catch EX As Exception

MessageBox.Show("Some Error occurs while Saving" +_

strNewLine + "Error :" +EX.ToString, _

"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally

SW.Close()

End Try

End Sub

Private Sub LoadGame()

Dim strRead(4) As String

Dim strBigArr() As String

Dim strSmallArr() As String

Dim SR As StreamReader = Nothing

If Not File.Exists("LSF.vmt") Then

MessageBox.Show("Save File doesn't Exists", _

"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)

Exit Sub

End If

Try

SR = New StreamReader("LSF.vmt")

If SR.ReadLine <> "#Assignment Line" Then

MessageBox.Show("Invalid Loaded File", "Error", _

MessageBoxButtons.OK, MessageBoxIcon.Error)

SR.Close()

Exit Sub

End If

For i As Integer = 0 To 4

strRead(i) = SR.ReadLine

Next

Catch IOE As IOException

MessageBox.Show("Can't load File !", "Error", _

MessageBoxButtons.OK, MessageBoxIcon.Error)

Catch EX As Exception

MessageBox.Show("Some Error occurs while Loading" +_

Chr(13) + Chr(10) + "Error :" +EX.ToString, _

"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally

SR.Close()

End Try

'Information Loaded

playerName = strRead(0)

playerScore = CDbl(strRead(1))

playerTime = CInt(strRead(2))

ReDim strBigArr(2)

ReDim strSmallArr(1)

strBigArr = strRead(3).Split(",")

For i As Integer = 0 To 2

strSmallArr = strBigArr(i).Split(";")

ThreeBI(i) = CInt(strSmallArr(0))

ThreeBP(i) = CInt(strSmallArr(1))

Next

InitBoard(playerName, playerScore, playerTime)

ReDim strBigArr(80)

strBigArr = strRead(4).Split(",")

For i As Integer = 0 To 80

strSmallArr = strBigArr(i).Split(";")

If CInt(strSmallArr(0)) <> BallState.NO_BALL Then

MPBoxes(i).Init(CInt(strSmallArr(1)))

End If

Next

End Sub

        (   MenuStrip).   ,        .

 21.2. -  .

Private Sub NewGameToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles NewGameToolStripMenuItem.Click

'  :

secondCounter = 0

'  :

My.Computer.Audio.Play("..\..\Sounds\drumpad-crash.wav")

Dim plName As String = Nothing

While Trim(plName) = ""

plName = InputBox(", ,   " +_

"(   ):", " ")

End While

InitBoard(plName, 0, 0)

RandomThreeBalls()

GiveThreeBalls()

flagMadeNew = 1

SaveToolStripMenuItem.Enabled = True

End Sub

        (   MenuStrip).   ,        .

 21.3. -  .

Private Sub SaveToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles SaveToolStripMenuItem.Click

SaveGame()

End Sub

        (   MenuStrip).   ,        .

 21.4. -  .

Private Sub LoadToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles LoadToolStripMenuItem.Click

If flagMadeNew = 1 Then

ResetBoard()

End If

LoadGame()

flagMadeNew = 1

SaveToolStripMenuItem.Enabled = True

End Sub

        (   MenuStrip).   ,        .

 21.5. -  .

Private Sub ExitToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles ExitToolStripMenuItem.Click

Me.Close()

End Sub

        (   MenuStrip).   ,        .

 21.6. -  .

Private Sub ShowScorToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles ShowScorToolStripMenuItem.Click

Dim frm As Form2 = New Form2

frm.Show()

frm.drawTable()

End Sub

         (   MenuStrip).   ,        .

 21.7. -   .

Private Sub CalculateAvgToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles CalculateAvgToolStripMenuItem.Click

Dim strnewL = Chr(13) + Chr(10)

Dim avg As Double = DDScore.number / DDTime.number

Dim s As String = FormatNumber(avg, 3)

Dim h As New System.IntPtr

MessageBox.Show(" : " +DDScore.number.ToString + _

" " + "()" +strnewL _

+ " : " +DDTime.number.ToString + " " + "()" +_

strnewL + "  : " +s + " " +_

"(/)", "    ", _

MessageBoxButtons.OK, MessageBoxIcon.None)

End Sub

         (   MenuStrip).   ,        .

 21.8. -  .

Private Sub AboutToolStripMenuItem_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles AboutToolStripMenuItem.Click

Dim frm As New Form3

frm.Show()

End Sub

     , ,        (   MenuStrip)           .

       Form1 (  Form1    ).

       (    ).        .

  ,        :  Solution Explorer      ,     Add, Existing Item,   Add Existing Item   Files of type  All Files,     (,    ,   ),        Add (      ).

  ,   Solution Explorer            Add, New Item,   Add New Item   Code File,   Name   DPaint.vb    Add.   (   Solution Explorer)   ,     ,       .

 21.9.  .

Public Class DPaint

Private _number As String

Private _position As Point

Private _color As Color

Private _pen As Pen

Private _thick As Integer

Private _width As Integer

Private _brush As SolidBrush

#Region "Property Declaration"

Public Sub New()

'_color = Color.Yellow

'        

' :

_color = Color.Red

_brush = New SolidBrush(_color)

_number = 0

End Sub

Public Sub New(ByVal number As Integer)

Me.number = number

_color = Color.Yellow

_brush = New SolidBrush(_color)

End Sub

Public Property number() As Double

Get

Return CDbl(_number)

End Get

Set(ByVal Value As Double)

_number = Value.ToString

_number = _number.PadLeft(8, "0")

End Set

End Property

Public Property position() As Point

Get

Return _position

End Get

Set(ByVal Value As Point)

_position = Value

End Set

End Property

Public Property thick() As Integer

Get

Return _thick

End Get

Set(ByVal Value As Integer)

_thick = Value

End Set

End Property

Public Property width() As Integer

Get

Return _width

End Get

Set(ByVal Value As Integer)

_width = Value

End Set

End Property

#End Region

#Region "Show digital Number"

Private Function conPol(ByVal i As Integer) As Point()

Dim c, h As Integer

Dim x As Integer = _position.X

Dim y As Integer = _position.Y

Dim poly(3) As Point

Select Case i

Case 1

c = x

h = y  _width  2

poly(0).X = c

poly(0).Y = h

poly(1).X = c + _width

poly(1).Y = h

poly(2).X = c + _width  _thick

poly(2).Y = h + _thick

poly(3).X = c + _thick

poly(3).Y = h + _thick

Return poly

Case 2

c = x + _width

h = y  _width  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 / 2

poly(3).X = c  _thick

poly(3).Y = h + _thick

Return poly

Case 3

c = x + _width

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 4

c = x + _width

h = y + _width + 2

poly(0).X = c

poly(0).Y = h

poly(1).X = c  _width

poly(1).Y = h

poly(2).X = c  _width + _thick

poly(2).Y = h  _thick

poly(3).X = c  _thick

poly(3).Y = h  _thick

Return poly

Case 5

c = x

h = y + _width + 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 / 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

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 > 0Then

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()

End If

While Me.picState = BallState.ZOOMING_BALL

Application.DoEvents()

End While

Me.Image = Nothing

Me.picIndex = -1

Me.picState = BallState.NO_BALL

Me.Tag = ""

End Sub

Protected Overrides Sub OnMouseMove(ByVal e As _

System.Windows.Forms.MouseEventArgs)

If picState = BallState.NORMAL_BALL Or _

picState = BallState.JUMPING_BALL Then

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

End If

End Sub

Protected Overrides Sub OnMouseLeave( _

ByVal e As System.EventArgs)

If picState = BallState.NORMAL_BALL Or picState = _

BallState.JUMPING_BALL Then

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

End If

End Sub

End Class

   (DPaint.vb, mModule.vb, MotionPic.vb, open.ico, save.ico)   Solution Explorer   ,  .     ,    ,   .

       ,    Form2    .

  Form2.vb (, : File, Open, File)         :

Imports System.Drawing.Drawing2D

Imports System.Drawing.Text

Imports System.IO

   Form2       .

 21.12.   .

Dim gr As Graphics

Dim lbrTitle As LinearGradientBrush

Dim lbrBoard As LinearGradientBrush

Dim midPoint As Point

Dim startPoint As PointF

Dim intGradiantStep As Integer = 5

Dim intCurrentGradientShift As Integer = 0

Const colW1 As Integer = 250

Const colW2 As Integer = 150

Const rowH As Integer = 30

Dim AddedPlayer As New Player("", "-1")

Dim ArrPlayer As New ArrayList

Dim intCurrentGradientRow As Integer = 110

Public WriteOnly Property AddPlayer() As Player

Set(ByVal Value As Player)

If Value.PlayerName.Length > 14 Then

Value.PlayerName = _

Value.PlayerName.Substring(0, 14)

End If

AddedPlayer = Value

End Set

End Property

Public Sub drawTable()

Me.BackgroundImage = Nothing

Me.BackColor = Color.Moccasin

Application.DoEvents()

Dim g As Graphics = CreateGraphics()

Dim tpen1 As New Pen(Color.Red, 1)

Dim tpen2 As New Pen(Color.Black, 1)

Dim P1 As New Point(2, 80)

Dim P2 As New Point(400, 80)

For i As Integer = 0 To 11

g.DrawLine(tpen1, P1, P2)

P1.Y += 1

P2.Y += 1

g.DrawLine(tpen2, P1, P2)

P1.Y += rowH  1

P2.Y += rowH  1

Next

P1.Y = 80

P2.X = P1.X

P2.Y -= rowH

g.DrawLine(tpen2, P1, P2)

P1.X += 1

P2.X += 1

g.DrawLine(tpen1, P1, P2)

P1.X += colW1

P2.X += colW1

g.DrawLine(tpen2, P1, P2)

P1.X += 1

P2.X += 1

g.DrawLine(tpen1, P1, P2)

P1.X += colW2  3

P2.X += colW2  3

g.DrawLine(tpen1, P1, P2)

P1.X += 1

P2.X += 1

g.DrawLine(tpen2, P1, P2)

SaveScore()

LoadScore()

Timer1.Enabled = True

Timer2.Enabled = True

End Sub

Public Sub LoadScore()

If Not File.Exists("Score.dat") Then

GoTo newScore

End If

Dim FSR As New StreamReader("Score.dat")

Dim s As String

s = FSR.ReadLine

If Trim(s) <> "#Assignment Line#" Then

FSR.Close()

GoTo newScore

End If

For i As Integer = 0 To 9

s = FSR.ReadLine

Dim PlayerName As String = s.Split(CChar(";"))(0)

Dim PlayerScore As String = s.Split(CChar(";"))(1)

ArrPlayer.Add(New Player(PlayerName, PlayerScore))

Next

FSR.Close()

Exit Sub

newScore:

ArrPlayer.Add(New Player("AAA", "5000"))

ArrPlayer.Add(New Player("AAA", "4500"))

ArrPlayer.Add(New Player("AAA", "4000"))

ArrPlayer.Add(New Player("AAA", "3500"))

ArrPlayer.Add(New Player("AAA", "3000"))

ArrPlayer.Add(New Player("AAA", "2500"))

ArrPlayer.Add(New Player("AAA", "2000"))

ArrPlayer.Add(New Player("AAA", "1500"))

ArrPlayer.Add(New Player("AAA", "1000"))

ArrPlayer.Add(New Player("AAA", "500"))

End Sub

Public Sub SaveScore()

LoadScore()

For i As Integer = 0 To 9

If CDbl(AddedPlayer.PlayerScore) >= _

CDbl(CType(ArrPlayer(i), Player).PlayerScore) Then

ArrPlayer.Insert(i, AddedPlayer)

Exit For

End If

Next

Dim FSW As New StreamWriter("Score.dat")

Dim s As String = "#Assignment Line#"

s += Chr(13) + Chr(10)

For i As Integer = 0 To 9

s += CType(ArrPlayer(i), Player).PlayerName + ";" +_

CType(ArrPlayer(i), Player).PlayerScore

s += Chr(13) + Chr(10)

Next

FSW.Write(s)

FSW.Close()

End Sub

Public Sub PlashScreen()

Me.BackgroundImage = Image.FromFile("GameOver.gif")

Application.DoEvents()

Threading.Thread.Sleep(2000)

End Sub

  Form2       Timer.   ,        .

 21.13. -  Tick.

Private Sub Timer1_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Timer1.Tick

gr = CreateGraphics()

midPoint = New Point(Me.Width \ 2, 10)

Dim strText As String = "Score Board"

Dim fnt As New Font("Microsoft Sans Serif", 30, _

FontStyle.Bold, GraphicsUnit.Point)

Dim strSize As New SizeF(gr.MeasureString(strText, fnt))

Dim ptfGradientStart As New _

PointF(intCurrentGradientShift, 0)

Dim ptfGradientEnd As New PointF(0, intCurrentGradientRow)

lbrTitle = New LinearGradientBrush(ptfGradientStart, _

ptfGradientEnd, Color.SteelBlue, Color.Brown)

startPoint = New PointF(midPoint.X  _

CInt(strSize.Width / 2), midPoint.Y)

gr.DrawString(strText, fnt, lbrTitle, startPoint)

ptfGradientStart = New PointF(0, intCurrentGradientShift)

ptfGradientEnd = New PointF(intCurrentGradientRow, 0)

lbrTitle = New LinearGradientBrush(ptfGradientEnd, _

ptfGradientStart, Color.MediumSlateBlue, _

Color.GhostWhite)

gr.DrawString(strText, fnt, lbrTitle, startPoint.X  2, _

startPoint.Y + 2)

intCurrentGradientShift += intGradiantStep

If intCurrentGradientShift = 400 Then

intGradiantStep = -5

ElseIf intCurrentGradientShift = -400 Then

intGradiantStep = 5

End If

End Sub

  Form2       Timer.   ,        .

 21.14. -  Tick.

Private Sub Timer2_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Timer2.Tick

'showScore()

Dim g As Graphics = CreateGraphics()

Dim fnt As New Font("Courier New", 20, FontStyle.Bold, _

GraphicsUnit.Point)

Dim startPoint As PointF = New PointF(20, 80)

Dim nextPoint As PointF = _

New PointF(startPoint.X + colW1, 80)

Dim ptfGradientStart As New PointF(intCurrentGradientRow, _

startPoint.X)

Dim ptfGradientEnd As New PointF(nextPoint.Y, _

intCurrentGradientRow)

lbrBoard = New LinearGradientBrush(ptfGradientStart, _

ptfGradientEnd, Color.GreenYellow, Color.SlateGray)

Dim PlayerNames As String = "Name" +Chr(13) + Chr(10)

Dim PlayerScores As String = "Score" +Chr(13) + Chr(10)

For i As Integer = 0 To 9

PlayerNames += CType(ArrPlayer(i), Player).PlayerName _

+ Chr(13) + Chr(10)

PlayerScores += CType(ArrPlayer(i), Player).PlayerScore _

+ Chr(13) + Chr(10)

Next

g.DrawString(PlayerNames, fnt, lbrBoard, startPoint)

g.DrawString(PlayerScores, fnt, lbrBoard, nextPoint)

intCurrentGradientRow += intGradiantStep

End Sub

  ,       Beep (-: )  .




21.5.  




       :

Build, Build Selection; Debug, Start Without Debugging.

  Visual Studio    ,      , , 9 x 9    (      ...  Random)     ,    3,  , , 3  ,       ,  3   ,    ,         (           ).

         ,    .          3    .

    ,       5     ,    ( 100       ),      ,     .         .

                      .




 X.        







 22.                







22.1.  




         (Role-playing game  RPG)      ,               (    ).

    ,      CaveManHank.zip (  )  Ivo Salmre  27.6.2002   gotdotnet.com    Visual Studio, ,    (),        Visual Studio,      .

  Solution Explorer (  )             Hank_FacingForward1.bmp (, ,  )        (    ,  ).     Visual Studio    ,         (. 22.1)    .

   Solution Explorer       Jane_FacingForward1a.bmp        (    ,  ).   Visual Studio     (. 22.2).         .















. 22.1.   . . 22.2.   .

     ,            (layers) .

      ( ).         .

     ,    (       ).          ,   ;          (level)   .

  ()    ,             .     ,    .

      ( )     ZharkovPress.ru.




22.2.  


1.           (. 22.3).








. 22.3.  .

         ,      .

   : 0      ,   .

  ,     : Bring me fire!!! (  ).

      .

    ,   :     .

    ,          ,    ,   .      , ,   .

      (  ,   )        (    ),    .

       ,        ,     .

  ,       .   ,      .    ,      .

   .

2.            (    ).

3. ٸ      ,    ,   .      , ,   .

,    ,       .     ,       ,    200  (. 22.4)








. 22.4.   200 .

4.       ,    .              .

ٸ         ,     .

       500  (. 22.5).








. 22.5.   500 .

5. , ,       (  )       ,    .

     ,       .     (  ),     (. 22.6).

   .

6.         .

7.       ,    .      MsgBox       (. 22.7  22.9).

8.      ,    ,     .

            ,        .

, ,               (       ).








. 22.6.  .








. 22.7.   .








. 22.8.   .








. 22.9.   .




22.3.   




    : VS   New Project   Project types    Visual Basic, Windows,   Templates   Windows Forms Application,   Name    HankTheCaveMan   OK.

 ,      ,             ,     Name    .  ,   Form1    (. 22.10).      ,        . ,   Properties ( Form1)   Font     10.       ,    Size , ,  : 405; 456.

   Toolbox           TextBox.

   Button   1.   Properties (  )   Text   .

   Button.   Properties (  )   Name  ButtonNextLevel,    Text  .

   Button.   Properties (  )   Name  buttonInstructions,    Text  .

  ,      ,   .

  Timer.   Properties (     )   Name  timerGame,   Enabled  True,   Interval   40 ,   25       .

        :  Solution Explorer      ,     Add, Existing Item ( Project, Add Existing Item),   Add Existing Item   Files of type  All Files,     (,       )     Ctrl      Add,       Solution Explorer  ,   . 22.9.

  Solution Explorer     (   Ctrl),    Properties   Build Action (  )       Embedded Resource ( )    .

      ,         , , Sounds.      ,   Solution Explorer      ,     Add, New Folder,            Enter.

        :       ,     Add, Existing Item,   Add Existing Item   Files of type  All Files,     (,       )     Ctrl      Add.   Solution Explorer    .















. 22.10.  Form1   .  . 22.11.  Solution Explorer.




22.4.    




  Form1.vb (,  : File, Open, File)           :

Imports System.Reflection '  Assembly.

  Form1       .

 22.1.   .

'

'Offsets on form where we should draw the playfield

'

Const GAME_SCREEN_DX = 2

Const GAME_SCREEN_DY = 1

'Current playfield

Private m_playfieldManager As PlayFieldManager

'Gfx object of the form that we will render the playfield to

Dim m_myFormsGraphics As Graphics

'

'Does the things we need to get get a round running

'

Sub InitializeNewLevel()

'Add a game event handler to get updates on the game

AddHandler m_playfieldManager.GameStateChanged, _

AddressOf GameEventOccured

'Start the game

timerGame.Enabled = True

ButtonNextLevel.Visible = False

'

'Give the text-box focus so we can get keyboard events

'

TextBox1.Focus()

End Sub

'

'Starts a new game

'

Sub StartGame()

'      :

'My.Computer.Audio.Play("..\..\Sounds\drumpad-crash.wav", _

' AudioPlayMode.WaitToComplete)

'      :

My.Computer.Audio.Play("..\..\Sounds\drumpad-crash.wav")

'

'Create Graphics object and cache it

'

If (m_myFormsGraphics Is Nothing) Then

m_myFormsGraphics = Me.CreateGraphics

End If

'

'Create the playfield level we want to start on

'

m_playfieldManager = New Playfield_Level2()

'

'Start the level running

'

InitializeNewLevel()

End Sub

Sub PictureBoxPlayField_MouseDown( _

ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.MouseEventArgs)

'If Hank's around, give him a new destination

'If Not (m_HankTheWonderCaveMan Is Nothing) Then

If Not (m_playfieldManager Is Nothing) Then

m_playfieldManager.HankTheWonderCaveman. _

setHanksDestination(e.X, e.Y)

End If

End Sub

'

'This event-sink is to get called when a game event occurs

'

Sub GameEventOccured(ByVal gameUpdateMessage As _

PlayFieldManager.GameUpdate)

'The level was completed succesfully

If (gameUpdateMessage = PlayFieldManager.GameUpdate. _

levelSuccesfullyCompleted) Then

ButtonNextLevel.Visible = True

End If

End Sub

'       :

'  myAssembly  Assembly   

'     :

Public myAssembly As Assembly = Assembly.GetExecutingAssembly()

'  myAssemblyName

' System.Reflection.AssemblyName   

' ,     ,

'Version, Culture, PublicKeyToken:

Public myAssemblyName As AssemblyName = myAssembly.GetName()

'      Name

'    string:

Public myName_of_project As String = myAssemblyName.Name

  Properties ( Form1)   Events      Load.          .

 22.2.    .

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

Me.Visible = False

'

'Load and cache the global object we need

'

g_InitializeGlobals()

Me.Visible = True

'

'Place the textbox off the screen

'

TextBox1.Width = 4

TextBox1.Multiline = True

TextBox1.Left = -20

'Start the game

StartGame()

End Sub

  Properties ( Form1)   Events      FormClosing.         .

 22.3.    .

Private Sub Form1_FormClosing(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.FormClosingEventArgs) _

Handles MyBase.FormClosing

' '

' 'Cleanup

' '

'

'Free up the form based objects

'

m_playfieldManager = Nothing

If Not (m_myFormsGraphics Is Nothing) Then

m_myFormsGraphics.Dispose()

m_myFormsGraphics = Nothing

End If

'

'Free up all the global objects

'

g_DisposeAndFreeGlobals()

End Sub

      Button   1     (   Properties,   ,   Events      ).         .

 22.4. -  .

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button2.Click

StartGame()

End Sub

      Button    (   Properties,   ,   Events      ).          .

 22.5. -  .

Private Sub ButtonNextLevel_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles ButtonNextLevel.Click

'

'Starts a new level of play

'

'Ask the current level what it's next level is

m_playfieldManager = m_playfieldManager.GetNextLevel()

'Start the level running

InitializeNewLevel()

End Sub

      Button    (   Properties,   ,   Events      ).          .

 22.6. -  .

Private Sub buttonInstructions_Click( _

ByVal sender As System.Object, ByVal e As System.EventArgs) _

Handles buttonInstructions.Click

MsgBox(" :     " +_

"  .   " +_

"    , " +_

"       , " _

+ "    .")

MsgBox("  ,     " +_

"  .   , " +_

"     . " +_

"   , " +_

"     .")

MsgBox("    , " +_

"   .    " +_

"  , , " +_

"  .    " +_

"   , " +_

"   .")

'Bring the focus back to the textbox

'so it gets the keyboard input

TextBox1.Focus()

End Sub

  Properties,   TextBox,   Events      KeyDown.         .

 22.7. - .

Private Sub TextBox1_KeyDown(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.KeyEventArgs) _

Handles TextBox1.KeyDown

'

'This textbox is a way to get the keyboard input

'for the game becuase:

' 1. When you hit the "START" button, it get's the focus

'(so the form no longer gets keydown events)

' 2. The Start Button does not get key-down events

'

If (m_playfieldManager Is Nothing) Then

Return

End If

Dim i As Integer

i = e.KeyValue

Const PocketPC_BUTTON_PUSHED = 134

Const Keyboard_SPACE_PUSHED = 32

Const PocketPC_UP = 38

Const PocketPC_DOWN = 40

Const PocketPC_LEFT = 37

Const PocketPC_RIGHT = 39

Dim hank As HankTheWonderCaveman = _

m_playfieldManager.HankTheWonderCaveman

Const D_MOVEMENT = 14

Const D_MOVEMENT_UP = 70

If (i = PocketPC_BUTTON_PUSHED) Or _

(i = Keyboard_SPACE_PUSHED) Then

hank.MakeHankJump()

e.Handled = True

ElseIf (i = PocketPC_RIGHT) Then

hank.NudgeHanksDirection(D_MOVEMENT, 0)

ElseIf (i = PocketPC_LEFT) Then

hank.NudgeHanksDirection(-D_MOVEMENT, 0)

ElseIf (i = PocketPC_UP) Then

hank.NudgeHanksDirection(0, -D_MOVEMENT_UP)

ElseIf (i = PocketPC_DOWN) Then

hank.NudgeHanksDirection(0, D_MOVEMENT)

End If

TextBox1.Text = ""

End Sub

      Timer (   Properties,   ,   Events      ).          .

 22.8. ,      Interval .

Private Sub timerGame_Tick(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles timerGame.Tick

' '

' 'This timer is the heartbeat if the game.

' 'Every time it gets called we

' 'allow all of the game characters to move,

' 'we check for collisions beween objects,

' 'and we render the board to the screen.

' '

'

'If we are not running, exit the sub

'

If (m_playfieldManager Is Nothing) Then Exit Sub

'

'Give all the characters a chance to move

'

m_playfieldManager.MoveCharactersOnPlayfield()

'

'Render the playfield and all of the objects onto the form

'

m_myFormsGraphics.DrawImage(m_playfieldManager. _

RenderPlayField(), GAME_SCREEN_DX, GAME_SCREEN_DY)

End Sub

  Properties,   Form1,   Events      MouseDown.         .

 22.9. - .

Private Sub Form1_MouseDown(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.MouseEventArgs) _

Handles MyBase.MouseDown

'Make sure there is a game we are playing

If Not (m_playfieldManager Is Nothing) Then

If e.Button = MouseButtons.Right Then

m_playfieldManager.HankTheWonderCaveman. _

MakeHankJump()

Else

'

'Figure out where on the game playfield we clicked

'

Dim x_GAME As Integer

Dim y_GAME As Integer

x_GAME = e.X  GAME_SCREEN_DX

y_GAME = e.Y  GAME_SCREEN_DY

'Let Hank figure out what to do

m_playfieldManager.HankTheWonderCaveman. _

setHanksDestination(x_GAME, y_GAME)

End If

End If

End Sub

       Form1 (  Form1    ).

       (    ).        .

  ,        :  Solution Explorer      ,     Add, Existing Item ( Project, Add Existing Item),   Add Existing Item   Files of type  All Files,     (    , ,  , )     Ctrl     (.vb)    Add,       Solution Explorer  ,   . 22.11.

  ,   Solution Explorer            Add, New Item,   Add New Item   Code File,   Name   BorisTheMenacingBird.vb    Add.   (   Solution Explorer)   ,     ,       .

 22.10.  .

'

'This class represents one of the characters in the game,

' "BorisTheMenacingBird"

'

'It contains logic for the rendering and movement of the character

'

Public Class BorisTheMenacingBird

Inherits DrawablePlayfieldMultiFrameBitmap

Private m_yVelocityBoris As Integer'How fast are _

'we traveling vertically?

Private m_xVelocityBoris As Integer'How fast are we

'traveling vertically?

Const MAX_DY_BORIS_FLYING = 4

Private m_y_accelerationBorris As Integer

Private m_world_I_Inhabit As PlayFieldManager

Private m_myModeOfMovement As ModeOfMovement

Public Enum ModeOfMovement As Integer

Flying = 1

End Enum



'When did we last update a flipped image

Private m_lastTickCountWhenImageFlipped As Integer

Const DTIME_TO_FLAP_WINGS = 400'Every 600 ms we should

'flap our wings

'

'These are the current image states for Hank

'

Private Enum BorisImagesIndexes

flyLeft1 = 1

flyLeft2 = 2

End Enum

'

'[in] X,Y : Position to start Hank at

'[in] worldHankInhabits : Playfield in which Hank lives

'

Sub New(ByVal x As Integer, ByVal y As Integer, _

ByVal world_I_Inhabit As PlayFieldManager)

'

'Get the bitmaps for our character

'

Dim col As Collection

col = g_FlyingBirdPictureCollection()

m_world_I_Inhabit = world_I_Inhabit

ChangeMyMovementState(ModeOfMovement.Flying)

'Start him off as falling.

'Initialize our base class with these

MyBase.Initialize_DrawableMultiPlayfiedBitmapObject( _

x, y, col, True)

'Set the image index

Me.CurrentFrameIndex = BorisImagesIndexes.flyLeft1

'Set Boris' speed

m_xVelocityBoris = -4

m_y_accelerationBorris = 1

'

'Set the collision rectangle for Hank

'

Const BORIS_COLLISION_STARTX = 11

Const BORIS_COLLISION_DX = 31

Const BORIS_COLLISION_STARTY = 6

Const BORIS_COLLISION_DY = 7

Me.CollisionRectangle = New Rectangle( _

BORIS_COLLISION_STARTX, BORIS_COLLISION_STARTY, _

BORIS_COLLISION_DX, BORIS_COLLISION_DY)

End Sub

'

'This function should be called to bring about any change

'of state

'It sets/resets any other variables we need to when we deal

'with state transitions

'

Private Sub ChangeMyMovementState(ByVal newState As _

ModeOfMovement)

m_myModeOfMovement = newState

End Sub

'

'MOVE Boris

'

'This function is called to move the character on the screen




  .


   .

   ,     (https://www.litres.ru/valeriy-zharkov-3244/spravochn-68897934/)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


