Visual Basic tutorial for beginners users.
Free ebook.   Winsock  Free game download VB Game  Free kids game eBook

    [ Page 2 ]     
    [ Russian Game ]
Get Links at, the online directory for high quality websites.


Visual Basic Tutorial

Ebook. Free User Tutorial - How to make a new logic game on Visual BASIC - training guide for beginners users. Guidelines for programmers in VB 6.0 for new logical game programming. The ebook includes rules of the game, step-by-step programming process description in Word and EXE e-book formats, screenshots and 9 complete VB-projects (listings for each development step).

    Game algorithm description:
     Game is conducted on a game field, which is optional size field (limited only to display size or convenience of programming). Since later on we’ll describe the process of developing the game graphic and PDA-versions, we have chosen 8x5 for the game table.
    vb tutorial

     All cells of the game field (table) are filled with symbols denoting the cell nominal values:
    [-1,-5,-10,-15,-25] - deduct the indicated points from your account.
    [1,5,10,15,25] - add the indicated points to your account.
    [B] - deducts 200 points from your account.
    [P] - adds 100 points to your account.
    [T] - adds 500 points to your account.
    [Z] - zeroes your account.
    [END] - ends the game.
    Account - your game account.

     The player can perform only 2 actions on the game field:
    1 – put “marker” on any cell of the game field bottom line only once at the game start (by clicking on the cell field).
    2 – on putting the “marker”, the player can move it right or left along the game field bottom line by means of left and right arrows (keyboard button).
    To Left and to Right buttons    

     All cell nominal values to be “visited” by the player “marker” will be added to score. “Marker” is a cell highlighted in blue Blue color marker. Example.. To put a marker, click on any cell of the game field bottom line. “Marker” may be put only once. Then it can be moved many times.

     As soon as the player has put the marker, game starts. Game is conducted for time. A linear color indicator counts time intervals, at which all lines of game field are moved one line down. At that, a cell with a losing value may fall on the player “marker”. The player goal is to move the marker along winning cells, increase the score as possible, and watch the “marker” not to be “caught” by the cell from above with a losing nominal value (e.g., |Z|- score zeroing).

     Game is not as simple as it may seem. Its program has additional functions: acceleration and slowing down of game, changing winning cells frequency at the player large score. Game Oflameron may be realized in
its static version, with no account of time. This version may have its benefits in the game process.

     Game goal is to increase the score. Game (theoretically endless) may be stopped in the following situations: 1) the player “marker” falls to a cell with |End| nominal 2) the player score becomes negative 3) game has time limitation. Such flexibility of game algorithm allows to create a great number of its versions – with accumulation of “lives”, introduction of extra bonuses (cell nominal values), loading graphic design from the Internet, network versions for 2 players (static version) and
paper version.

GAME Programming

     Create Project EXE and Form1, its size being 2,715õ5,745. A Frame element is to be placed at the Form, while elements Label1 – Label55 are to be placed at the Frame element, where Label1 – Label6 is a Level column, Label 7 – Label 46 are nominal playing area cells, Label 47-48 present control footing information. A lower color indicator is formed by Label 49-Label 55.

    Game form - table 8õ5
     Number arrays correspond to a Level element column and a playing area.
    Game Levels Array Dim level(5)
    Game table Array Dim field(8, 6)

    Brief description of a VB version game

     The game is started by a payer’s marker being placed in any cell of the bottom row (by clicking a mouse). The cell is highlighted in blue:
    Game pointer - marker
    and the nominal of the cell occupied is added to or subtracted from a player’s score. A lower colour linear indicator Colour linear indicator is becoming shorter. Before the indicator disappears a player can move a game marker along the bottom row  to the right or to the left off its current position by pressing |Right| or |Left| keyboard arrows. Nominals of all cells that the player goes through are added to or subtracted from a player’s score. As soon as the linear colour indicator disappears a player cannot move his marker for a moment, while nominals of all cells are shifted top down for one row. A playing area top row is filled with new values by a random-number generator. At that the nominal of a cell that was shifted from above to the one where the marker is placed, is also added to the score, thus changing your score considerably. After that a linear color indicator is restored and is getting shorter again, while a player can move the marker again.
    The game score is tracked in an orange cell:
     The game goes on until a player’s score equals to zero or the marker gets into a cell with an |End| nominal.
     The game is not as simple as it may seem. It is very easy to move a marker to the cells |Z| (score mulling) or |End| (end of the game).
     Here a programming process of a “text-only version” of a logical tabular game "Oflameron" is described. The cell nominals are presented at the screen as symbols, while the cells are Label elements.
    Now, fill in playing area cells (field(8, 6) array) with random-number generator values. Calculate number of seconds in current time, and run the random-number generator cycle corresponding number of times:
    TM = Time   'Get time
    TTMS = Len(TM)   'Time string lenght
    TTM = Mid$(TM, 7, 2)   'Extract seconds position
    For i = 0 To TTM   ‘Repeat
      Form1.Caption = Int((20 * Rnd) + 1) ‘Print to Form1 caption
    Next i
     The procedure looks like the following:
    Private Sub Set_Nominal()
    TM = Time   'Get time
    TTMS = Len(TM)   'Time string lenght
    TTM = Mid$(TM, 7, 2)   'Extract seconds position
    For i = 0 To TTM   'Repeat
      Form1.Caption = Int((20 * Rnd) + 1) ‘Print to Form1 caption
    Next i
    ' fill in playing area cells field(8, 5)
    For i = 0 To 7
     For j = 0 To 4
     field(i, j) = Int((20 * Rnd) + 1)
     Next j
    Next i
    End Sub
     Now a test procedure Private Sub Fdraw() can be written to see how field(8, 6) array is filled. The procedure Private Sub Fdraw() looks like the following:
(see code)
     I.e., every cell is recorded in each cell Caption. Such method is not to be considered as an optimal one; further on other programming methods can be used. To see the results it is necessary to insert two procedures call: Private Sub Set_Nominal() and Private Sub Fdraw() in a program autostart (for a while):
    Private Sub Form_Load()
    End Sub
     A complete Visual Basic project of this game development stage is in the file
    Now it is necessary to create a procedure to analyze field(8, 6) array cell content, and depending on their values, to form a required symbol value (nominal) of a playing area cell and specify a required symbol and cell background colour.
    Now, overwrite Fdraw() procedure in another one. Create another Label56 to temporarily store a generated cell nominal and its colour attributes (highlighted at the figure).
    Game form
    Cell for copy - Label56
    Source code Private Sub Color_Chars() see
    Now add copying values and Label56 cell attributes in the playing area cell, and use several cycles to process the whole field(8, 6) array:
    - copying example
    Label7.Caption = Label56.Caption
    Label7.BackColor = Label56.BackColor
    Label7.ForeColor = Label56.ForeColor
    As a result there appears a nominal copying Sub Field_Fill() procedure from a responsible cell Label56, while a procedure Color_Chars() is changed in the following way -
see code.
    Such variant of filling a playing area with START values (at the start of the game) cannot be considered as an optimal one. However it is very demonstrable for algorithm understanding.
     Form_Load() procedure looks like following:
    Private Sub Form_Load()
    End Sub
    To see how it works add another Form_Click() procedure (for a while, for the program debugging):
    Private Sub Form_Click()
    Set_Nominal  ‘Fill array field(i,j)
    Fdraw  ‘Draw field(i,j) – for debug
    Field_Fill  ‘Print real nominals
    End Sub
     - it is absolutely identical to Form_Load() procedure
    To draw real cell nominals and colour attributes. Now, clicking the mouse to Form1 field (only forms) you can see if the cell nominals values and their colour attributes are changed correctly.
    A complete Visual Basic project of this game development stage is in the file
     Form_Click() procedure can be deleted.
    Now develop Num_Move() procedure to overwrite playing area cells’ values and colour attributes in a row-wise top-down way and to fill a playing area top row with new values (i.e., new cell values are input in the game from the top row). The procedure contains copying operators. You can develop a more optimal copying algorithm.
    Private Sub Num_Move()
    For j = 0 To 4
     For i = 0 To 7
      field(i, j) = field(i, j + 1)
     Next i
    Next j
    End Sub
    To see how top-down copying values and cell attributes works, create a temporary click handling procedure at Frame1:
    Private Sub Frame1_Click()
    End Sub
    A complete Visual Basic project of this game development stage is in the file
    Now it necessary to add Private Sub Up_Str_App() code to fill in the playing area top row with new values -
see code.
    Attach the Frame1.Click procedure call
    A complete Visual Basic project of this game development stage is in the file
    Click the mouse to the Frame1 field and see how it works!
    Now it is necessary to write a handling code for player’s placing a game marker in any bottom row cell of the playing area.
     The procedure to save colour attributes of all bottom row cells before placing the marker:
    Private Sub Save_Color()
    savecolor(0) = Label7.BackColor   'Save bgcolor Label7
    savecolor(1) = Label8.BackColor   'Save bgcolor Label8
    savecolor(2) = Label9.BackColor   'Save bgcolor Label9
    savecolor(3) = Label10.BackColor   'Save bgcolor Label10
    savecolor(4) = Label11.BackColor   'Save bgcolor Label11
    savecolor(5) = Label12.BackColor   'Save bgcolor Label12
    savecolor(6) = Label13.BackColor   'Save bgcolor Label13
    savecolor(7) = Label14.BackColor   'Save bgcolor Label14
    End Sub
    Create a trigger firstset = 0
    Trigger=0, if a marker has not been placed in the bottom row yet.
    General code fragment that handles marker placing in the bottom row -
see code.
    Pointer - marker
    Save_Color() procedure is used to restore cell colour when moving the marker horizontally (along the bottom row of the playing area).
    Create a markersave variable to memorize an array ELEMENT NUMBER savecolor(j), the variable corresponding to the marker cell (i.e. the cell, in which the marker has been placed).
    The possibility of placing a marker on one cell only can be checked. Now it is necessary to provide a marker being saved (in terms of cell turning blue) when shifting cells top – down.
    The procedure of marker colour restoring after playing area cells shifting top-down:
    Private Sub Marker_Reset()
    If markersave = 0 Then Label7.BackColor = &HFF0000
    If markersave = 1 Then Label8.BackColor = &HFF0000
    If markersave = 2 Then Label9.BackColor = &HFF0000
    If markersave = 3 Then Label10.BackColor = &HFF0000
    If markersave = 4 Then Label11.BackColor = &HFF0000
    If markersave = 5 Then Label12.BackColor = &HFF0000
    If markersave = 6 Then Label13.BackColor = &HFF0000
    If markersave = 7 Then Label14.BackColor = &HFF0000
    End Sub
    Now activate Marker_Reset() procedure to operate in a top-down shift procedure. In the bottom of Frame1_Click() procedure insert the following code (marked as underline):
    Private Sub Frame1_Click()
    Num_Move  'Shift the values of all rows one row down
    Up_Str_App  'Fill in the top row with new nomimals
    Marker_Reset  'Marker redraw
    End Sub
    A complete Visual Basic project of this game development stage is in the file
    Write a score count procedure when placing a marker in the beginning of the game -
see code.
    Now attach a score count procedure in each of click procedures for bottom row cells:
    Private Sub Label7_Click()
    If firstset = 0 Then Save_Color  'Save bgcolor
    If firstset = 0 Then Label7.BackColor = &HFF0000  'Set new bgcolor (blue)
    If firstset = 0 Then firstset = 1  'No use again
    markersave = 0
    Set_Marker_Count ‘Rewrite counter
    End Sub
    For other bottom row cells the procedure is exactly the same.
    Now write a score counting procedure at cells’ shifting top-down. Procedure looks like extremely simple:
    Private Sub Dn_Count()
    n = 0 ‘Temporarily to resolve work of procedure Set_Marker_Count
    Set_Marker_Count  ‘Procedure of calculation of glasses after installation of a marker
    End Sub
    To demonstrate the procedure operation, insert the procedure call in a top-down cell row shifting procedure Frame1_Click():
    Private Sub Frame1_Click()
    Num_Move  'To move values of all cells from above - downwards
    Up_Str_App  'To fill in the top line of a game field new values
    Marker_Reset  'Rewrite marker
    Dn_Count  'To count up glasses at moving lines from above - downwards
    End Sub
    A complete Visual Basic project of this game development stage is in the file
    Create a procedure of linear colour indicator operation. Add Timer1 to the form and enable it at once.
see code.
    You can see how the indicator works.
    Now you should disable the timer and enable it after the market has been placed in a playing area bottom row. Insert timer enabling in a marker placing procedure in a playing area bottom row (to be more exact – in a score counting procedure after marker placing Set_Marker_Count(), since the procedure is common for all cells of a lower level). At the end of the procedure Set_Marker_Count() there is a line:
    Timer1.Enabled = True  'The timer is ON since the marker is put
    A complete Visual Basic project of this game development stage is in the file
    When a linear colour indicator disappears completely, it is necessary to shift down all rows with playing area cells (Frame1_Click() procedure) to the marker, count scores and fill in a playing area top row with new nominal values.
    Timer1 operation procedure looks like the following way:
    Private Sub Timer1_Timer()
    IndLent = IndLent + 1
    If IndLent = 9 Then
      IndLent = 0
      Timer1.Interval = 500
      Frame1_Click 'To move levels
    End If
    Print_Ind  'Draw indicator
    End Sub
    Keyboard  Now it is necessary to write handling of pressing down the key and marker’s moving to the [right] / [left] along the bottom row of playing area cells.
    Place another timer (Timer2) at Form1. Set a time interval Timer2 = 50 and place a key status test code in a printer operation procedure. Declare procedure operation functions:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    And a handling code as such -
see code.
    Inscriptions in Left and Right form header are presented only for debugging purposes. Markersave variable shows a unique playing area bottom row cell that contains a marker. Write a procedure of marker moving to the left / right along the bottom row -
see code.
    Now it is necessary to create only one procedure – a procedure of shifting the numbering of current gaming level |Level|:
    Private Sub Level_Count()
    Label6.Caption = Label6.Caption + 1
    Label5.Caption = Label6.Caption + 1
    Label4.Caption = Label5.Caption + 1
    Label3.Caption = Label4.Caption + 1
    Label2.Caption = Label3.Caption + 1
    End Sub
    Attach a shifting procedure to the operations, for example:
    Private Sub Dn_Count()
    n = 0
    Level_Count 'Move Level
    End Sub
    A complete Visual Basic project of this game development stage is in the file    [ Make EXE file ]
    Now, this is a demonstrative moment: all software-realization procedures of the game Oflameron are ready. In other words, you have created a completely operable logical gaming program in Visual Basic. It is still early to introduce it as a commercial product as it still contains many faults. For example, when clicking the Frame object the game starts without placing the marker. Removing such faults and configuring the game as a commercial product are dealt in the 2nd & 3d parts of the guidelines.
    One of the 2nd parts variants (with system of bonuses , variants of complication of game , connect to Internet) - in file
      Oflameron    Copyright (c) by Valery V Shmeleff     

Online trading exchange market - Trade, Exchange, Swap and Barter without any cost or obligations.

     Java Game    XFlood    Register online    Kid game    Game builder    Java    Delphi