' John Doe ' Maze2 ' Per ? Public Class Form1 ' constants Const STARTING_X As Integer = 10 ' x coordinate of player's start position Const STARTING_Y As Integer = 12 ' y coordinate of player's start position ' set up the game Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Setup() End Sub ' draws maze Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint ' instructions e.Graphics.DrawString("RESET left-click - EXIT right-click", New Font("Arial", 8), Brushes.Black, 100, 270) ' boundaries e.Graphics.DrawLine(Pens.Black, 2, 2, 300, 2) ' top boundary e.Graphics.DrawLine(Pens.Black, 2, 300, 300, 300) ' bottom boundary e.Graphics.DrawLine(Pens.Black, 2, 2, 2, 300) ' left boundary e.Graphics.DrawLine(Pens.Black, 300, 2, 300, 300) ' right boundary ' horizontal lines e.Graphics.DrawLine(Pens.Black, 2, 40, 260, 40) ' line 1 e.Graphics.DrawLine(Pens.Yellow, 40, 110, 260, 110) ' line 2 e.Graphics.DrawLine(Pens.Red, 80, 150, 300, 150) ' line 3 ' vertical lines e.Graphics.DrawLine(Pens.Orange, 40, 110, 40, 300) ' line 4 e.Graphics.DrawLine(Pens.Cyan, 80, 150, 80, 300) ' line 5 e.Graphics.DrawLine(Pens.White, 260, 40, 260, 110) ' line 6 ' identifying start & finish e.Graphics.DrawString("Start", New Font("Arial", 8), Brushes.Black, 15, 15) e.Graphics.DrawString("Finish", New Font("Arial", 8), Brushes.Black, 42, 280) End Sub ' moves player through maze Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown ' moves player through maze with arrow keys If (e.KeyCode = Keys.Right Or e.KeyCode = Keys.D Or e.KeyCode = Keys.NumPad6) Then ' moving right picPlayer.Left = picPlayer.Left + 5 ElseIf (e.KeyCode = Keys.Left Or e.KeyCode = Keys.A Or e.KeyCode = Keys.NumPad4) Then ' moving left picPlayer.Left = picPlayer.Left - 5 ElseIf (e.KeyCode = Keys.Up Or e.KeyCode = Keys.W Or e.KeyCode = Keys.NumPad8) Then ' moving up picPlayer.Top = picPlayer.Top - 5 ElseIf (e.KeyCode = Keys.Down Or e.KeyCode = Keys.S Or e.KeyCode = Keys.NumPad2) Then ' moving down picPlayer.Top = picPlayer.Top + 5 End If ' collision detection for horizontal walls ' from below from above from left from right If (picPlayer.Top < 40 And picPlayer.Bottom > 40 And picPlayer.Right > 2 And picPlayer.Left < 260) Then ' line 1 MessageBox.Show("collision with line 1") ' GameReset() ElseIf (picPlayer.Top < 110 And picPlayer.Bottom > 110 And picPlayer.Right > 40 And picPlayer.Left < 260) Then ' line 2 MessageBox.Show("collision with line 2") ' GameReset() ElseIf (picPlayer.Top < 150 And picPlayer.Bottom > 150 And picPlayer.Right > 80 And picPlayer.Left < 300) Then ' line 3 MessageBox.Show("collision with line 3") ' GameReset() End If ' collision detection for vertical walls If (picPlayer.Top < 300 And picPlayer.Bottom > 110 And picPlayer.Right > 40 And picPlayer.Left < 40) Then ' line 4 MessageBox.Show("collision with line 4") ' GameReset() ElseIf (picPlayer.Top < 300 And picPlayer.Bottom > 150 And picPlayer.Right > 80 And picPlayer.Left < 80) Then ' line 5 MessageBox.Show("collision with line 5") ' GameReset() ElseIf (picPlayer.Top < 110 And picPlayer.Bottom > 40 And picPlayer.Right > 260 And picPlayer.Left < 260) Then ' line 6 MessageBox.Show("collision with line 6") ' GameReset() End If ' win detection 'If (picPlayer.Top < ? And picPlayer.Bottom > ? And picPlayer.Right > ? And picPlayer.Left < ?) Then ' finish line ' MessageBox.Show("You finished the maze!") ' ' GameReset() 'End If End Sub ' set up game and player Private Sub Setup() Me.Text = "Maze" ' displaying instructions in form's title bar picPlayer.Left = STARTING_X ' starting position of player picPlayer.Top = STARTING_Y Me.Width = 320 ' setting desired size of form window since it Me.Height = 340 ' is not exactly 300 by 300 Me.BackColor = Color.FromArgb(200, 0, 200) ' setting background to custom shade of purple End Sub ' reset the maze Private Sub GameReset() ' reset the player to the beginning of the maze picPlayer.Left = 12 picPlayer.Top = 39 End Sub ' exit or reset the application Private Sub Form1_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick If (e.Button = Windows.Forms.MouseButtons.Right) Then ' exit application on right-click Application.Exit() ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then ' reset player on left-click picPlayer.Left = STARTING_X picPlayer.Top = STARTING_Y End If End Sub End Class