Programming Games with Visual Basic: An Intermediate Step by Step Tutorial by Philip Conrod & Lou Tylee
Author:Philip Conrod & Lou Tylee [Conrod, Philip]
Language: eng
Format: azw3
ISBN: 9781937161859
Publisher: Kidware Software LLC
Published: 2017-07-02T04:00:00+00:00
Form Design – Building Delivery Grid
For the Pizza Delivery game, we want a delivery grid that looks like this:
Notice we have labeling information for the columns and rows and a 20 x 20 grid used to display orders. Individual elements in the grid are referred to by a column letter and a row number (like Excel spreadsheets). We will build this grid in the pnlGrid control using 441 (21 x 21) square label controls. Let’s see how to do this.
The process is fairly straightforward. For each of the 441 label controls, we create the control, set properties (particularly Left, Top, Width, Height for proper positioning) and place the control in the panel control. The first row in the grid will be used to label the columns; the first column will be used to label the rows. We will ignore the label control in the upper left corner. The remaining 20 x 20 grid of label controls will be used to display orders and car motion.
First, define a form level two-dimensional array of label controls:
Dim DeliveryGrid(20, 20) As Label
We will use the 0th elements of DeliveryGrid to represent the column and row labels. We ignore DeliveryGrid(0, 0), the upper left corner in the grid.
The code to establish this grid and display it in the panel control (pnlGrid) goes in the frmPizzaDelivery Load event procedure:
Private Sub frmPizzaDelivery_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim I As Integer, J As Integer
Dim W As Integer = pnlGrid.Width / 24
Dim L As Integer = W
Dim T As Integer = W
'J is row, I is column; build one row at a time
For J = 0 To 20
For I = 0 To 20
DeliveryGrid(I, J) = New Label
DeliveryGrid(I, J).Width = W
DeliveryGrid(I, J).Height = W
DeliveryGrid(I, J).Top = T
DeliveryGrid(I, J).Left = L
DeliveryGrid(I, J).Font = New Font("Microsoft Sans Serif", 10, FontStyle.Bold)
DeliveryGrid(I, J).TextAlign = ContentAlignment.MiddleCenter
If I = 0 Then
If J <> 0 Then
'row numbers
DeliveryGrid(I, J).Text = J.ToString
DeliveryGrid(I, J).Width = 1.5 * W
DeliveryGrid(I, J).Left = 0.5 * W
DeliveryGrid(I, J).ForeColor = Color.DarkBlue
End If
ElseIf J = 0 Then
If I <> 0 Then
'column letters
DeliveryGrid(I, J).Text = Chr(I + 64)
DeliveryGrid(I, J).ForeColor = Color.DarkBlue
End If
Else
DeliveryGrid(I, J).BorderStyle = BorderStyle.FixedSingle
DeliveryGrid(I, J).BackColor = Color.White
DeliveryGrid(I, J).ForeColor = Color.Yellow
End If
pnlGrid.Controls.Add(DeliveryGrid(I, J))
L += W
Next
'new row
L = W
T += W
Next
End Sub
This code builds the label control grid, one row at a time. Each control is first declared, and assigned a Top, Left, Width and Height property. We assume square controls, with the size based on the width of the panel – (1/24th of the panel, which allows for some margin space). We start at the upper left corner, working our way to the right. Once a row is finished, the Top property is incremented down one row and the Left property returned to the left “margin.” Other properties are assigned based on locations. Controls with column labels (J = 0) and row labels (I = 0) have no border and are given an appropriate letter or number. Notice how the row labels are shifted a bit to the left to allow 2 digit numbers.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Pale Blue Dot by Carl Sagan(4628)
Cracking the GRE Premium Edition with 6 Practice Tests, 2015 (Graduate School Test Preparation) by Princeton Review(4053)
Pocahontas by Joseph Bruchac(4036)
Unfiltered by Lily Collins(3913)
The Emotionary: A Dictionary of Words That Don't Exist for Feelings That Do by Eden Sher(3225)
The Daily Stoic by Holiday Ryan & Hanselman Stephen(3112)
Factfulness_Ten Reasons We're Wrong About the World_and Why Things Are Better Than You Think by Hans Rosling(3052)
The President Has Been Shot!": The Assassination of John F. Kennedy by Swanson James L(2976)
Sapiens and Homo Deus by Yuval Noah Harari(2850)
Rogue Trader by Leeson Nick(2831)
The 48 laws of power by Robert Greene & Joost Elffers(2818)
The Rape Of Nanking by Iris Chang(2653)
Almost Adulting by Arden Rose(2590)
Gettysburg by Iain C. Martin(2581)
The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution by Walter Isaacson(2513)
500 Must-Know AP Microeconomics/Macroeconomics Questions(2478)
The Plant Paradox by Dr. Steven R. Gundry M.D(2435)
In the Woods by Tana French(2422)
Make by Mike Westerfield(2205)
