VERSION 5.00 Begin VB.Form frmATC2 BackColor = &H00FFFF80& Caption = "Air Traffic Control Simulation" ClientHeight = 5670 ClientLeft = 60 ClientTop = 345 ClientWidth = 6735 LinkTopic = "Form1" ScaleHeight = 5670 ScaleWidth = 6735 StartUpPosition = 3 'Windows Default Begin VB.PictureBox picPlane BorderStyle = 0 'None ClipControls = 0 'False Height = 495 Index = 1 Left = 3000 ScaleHeight = 495 ScaleWidth = 495 TabIndex = 10 Top = 2280 Width = 495 End Begin VB.PictureBox picPlane BorderStyle = 0 'None Height = 495 Index = 0 Left = 3000 ScaleHeight = 495 ScaleWidth = 495 TabIndex = 9 Top = 2280 Width = 495 End Begin VB.OptionButton optActivePlane BackColor = &H00FFFF80& Caption = "1" Height = 375 Index = 1 Left = 2160 TabIndex = 8 Top = 3480 Width = 615 End Begin VB.OptionButton optActivePlane BackColor = &H00FFFF80& Caption = "0" Height = 375 Index = 0 Left = 960 TabIndex = 7 Top = 3480 Value = -1 'True Width = 495 End Begin VB.CommandButton cmdLand Caption = "Land" Height = 375 Left = 2280 TabIndex = 6 Top = 5160 Width = 1095 End Begin VB.CommandButton cmdTakeOff Caption = "Take off" Height = 375 Left = 2280 TabIndex = 5 Top = 4080 Width = 1095 End Begin VB.CommandButton cmdLower Caption = "Lower" Height = 375 Left = 720 TabIndex = 4 Top = 5040 Width = 855 End Begin VB.CommandButton cmdHigher Caption = "Higher" Height = 375 Left = 720 TabIndex = 3 Top = 4080 Width = 855 End Begin VB.CommandButton cmdRight Caption = "Right" Height = 375 Left = 1200 TabIndex = 1 Top = 4560 Width = 975 End Begin VB.CommandButton cmdLeft Caption = "Left" Height = 375 Left = 120 TabIndex = 0 Top = 4560 Width = 855 End Begin VB.Timer Timer1 Interval = 500 Left = 5760 Top = 4680 End Begin VB.Image imgAirport Height = 735 Left = 2880 Picture = "ATC2.frx":0000 Stretch = -1 'True Top = 2160 Width = 735 End Begin VB.Label lblOutput BackStyle = 0 'Transparent Caption = "X: Y: Alt:" Height = 375 Left = 2400 TabIndex = 2 Top = 4800 Width = 2295 End Begin VB.Image imgStore Height = 495 Index = 7 Left = 6120 Picture = "ATC2.frx":1D502 Stretch = -1 'True Top = 1920 Visible = 0 'False Width = 495 End Begin VB.Image imgStore Height = 495 Index = 6 Left = 6120 Picture = "ATC2.frx":1E99C Stretch = -1 'True Top = 1320 Visible = 0 'False Width = 495 End Begin VB.Image imgStore Height = 495 Index = 5 Left = 6120 Picture = "ATC2.frx":1FBAE Stretch = -1 'True Top = 720 Visible = 0 'False Width = 495 End Begin VB.Image imgStore Height = 495 Index = 4 Left = 6120 Picture = "ATC2.frx":20E58 Stretch = -1 'True Top = 120 Visible = 0 'False Width = 495 End Begin VB.Image imgStore Height = 495 Index = 3 Left = 5280 Picture = "ATC2.frx":221FA Stretch = -1 'True Top = 1920 Visible = 0 'False Width = 495 End Begin VB.Image imgStore Height = 495 Index = 2 Left = 5280 Picture = "ATC2.frx":235EC Stretch = -1 'True Top = 1320 Visible = 0 'False Width = 495 End Begin VB.Image imgStore Height = 495 Index = 1 Left = 5280 Picture = "ATC2.frx":247FE Stretch = -1 'True Top = 720 Visible = 0 'False Width = 495 End Begin VB.Image imgStore Height = 495 Index = 0 Left = 5280 Picture = "ATC2.frx":25904 Stretch = -1 'True Top = 120 Visible = 0 'False Width = 495 End End Attribute VB_Name = "frmATC2" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False 'ATC2 'A simple air traffic control simulator 'demonstrates OOP in VB 'Just like ATC, but uses an array of aircraft to simulate 'a busy airport. 'Andy Harris, 2/99 Dim plane(2) As New Aircraft Dim currentPlane As Integer Private Sub cmdHigher_Click() plane(currentPlane).altitude = plane(currentPlane).altitude + 5 End Sub Private Sub cmdLand_Click() Dim direcOK As Boolean 'check the direction 'this airport has Runways going N, S, E, and W, 'but NW, NE, SW, SE not legal directions direcOK = False If plane(currentPlane).direction = NORTH Then direcOK = True ElseIf plane(currentPlane).direction = SOUTH Then direcOK = True ElseIf plane(currentPlane).direction = EAST Then direcOK = True ElseIf plane(currentPlane).direction = WEST Then direcOK = True End If 'ensure plane is on airport If picPlane(currentPlane).Left > imgAirport.Left Then If picPlane(currentPlane).Left < (imgAirport.Left + imgAirport.Width - picPlane(currentPlane).Width) Then If picPlane(currentPlane).Top < imgAirport.Top Then If picPlane(currentPlane).Top > (imgAirport.Top - imgAirport.Height + picPlane(currentPlane).Height) Then plane(currentPlane).land MsgBox "Nice Landing" Else MsgBox "Too far South!" End If Else MsgBox "too far North!" End If Else MsgBox "too far East!" End If Else MsgBox "too far West!" End If End Sub Private Sub cmdLeft_Click() plane(currentPlane).turnLeft End Sub Private Sub cmdLower_Click() If plane(currentPlane).altitude <= 5 Then MsgBox "You cannot go lower than 500 feet!!" Else plane(currentPlane).altitude = plane(currentPlane).altitude - 5 End If End Sub Private Sub cmdRight_Click() plane(currentPlane).turnRight End Sub Private Sub cmdTakeOff_Click() plane(currentPlane).takeOff End Sub Private Sub Form_Load() frmATC2.Scale (-100, 100)-(100, -100) Dim i As Integer For i = 0 To 1 plane(i).x = picPlane(i).Left plane(i).y = picPlane(i).Top Next i currentPlane = 0 End Sub Private Sub imgAirport_Click() Debug.Print "Top: " + Str(imgAirport.Top) Debug.Print "Left: " + Str(imgAirport.Left) End Sub Private Sub optActivePlane_Click(Index As Integer) currentPlane = Index End Sub Private Sub Timer1_Timer() Dim temp As String Dim i As Integer For i = 0 To 1 plane(i).move picPlane(i).Picture = imgStore(plane(i).direction).Picture picPlane(i).Left = plane(i).x picPlane(i).Top = plane(i).y picPlane(i).Cls picPlane(i).Print i Next i temp = Str(currentPlane) + ": " temp = temp + "X: " + Str(plane(currentPlane).x) temp = temp + " Y: " + Str(plane(currentPlane).y) temp = temp + " Alt: " + Str(plane(currentPlane).altitude) + "00 ft" lblOutput.Caption = temp End Sub