Maze+-+Level+Form


 * This is the sample code for what happens in each particular level of my maze game. It is here also, where the key pressing is detected, screen colour is detected and Elmo's movement takes place!!!!!!!!**

Public Class frmLevel1

Dim lstWalls As New List(Of Label) Dim intCounter As Integer = 0 Dim xMove As Integer Dim yMove As Integer

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown xMove = 0 yMove = 0 If e.KeyCode = Keys.Left Then xMove = -5 ElseIf e.KeyCode = Keys.Right Then xMove = 5 ElseIf e.KeyCode = Keys.Up Then yMove = -5 ElseIf e.KeyCode = Keys.Down Then yMove = 5 End If End Sub

Public Function didHitWall As Boolean For Each wall In lstWalls If pbxElmo.Bounds.IntersectsWith(wall.Bounds) Then Return True End If Next

Return False End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load intLevelNumb = 1 'Dim arrControls As Control Dim cControl As Control For Each cControl In Me.Controls If (TypeOf cControl Is Label) Then If cControl.BackColor = Color.Blue Then lstWalls.Add(cControl) End If End If Next cControl

tmrGame.Start tmrGame.Interval = 1000 tmrElmo.Interval = 50 tmrElmo.Start End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGame.Tick intCounter += 1 lblTimer.Text = intCounter End Sub

Private Sub lblFinish1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblFinish1.Click

End Sub

Private Sub tmrElmo_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrElmo.Tick pbxElmo.Location = New Point(pbxElmo.Location.X + xMove, pbxElmo.Location.Y + yMove) If didHitWall = True Then pbxElmo.Location = New Point(pbxElmo.Location.X - xMove, pbxElmo.Location.Y - yMove) End If

If pbxElmo.Bounds.IntersectsWith(lblFinish1.Bounds) Then Me.Hide frmExit1.Show End If End Sub End Class