locked
create a maze game RRS feed

  • General discussion

  • How to create a maze game

    Visual Basic: Maze game

    to do this use the given information.


    Allow time to reverse.


    • Edited by Paul Ishak Thursday, February 7, 2013 6:13 PM Pointless reference to obscure thread, bad title
    Tuesday, December 25, 2012 7:47 AM

All replies

  • If you want to create a maze game you need to know touchness of objects.

    Ist create a window form application.

    and then use the following code

    Public Class Form1
        Public I As New Label
        Public Not_Touch As New List(Of Label)
        Public Solids_Color As Color = Color.Red
        Public Win As New Label With {.AutoSize = False, .Left = 411 - 70, .Top = 376 - 60, .Height = 20, .Width = 20, .BackColor = Color.White}
        Private Sub Form1_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated
        End Sub
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me.Text = "My Game 1"
            Me.Width = 411
            Me.Height = 376
            Me.BackColor = Color.Black
            I.Left = 0
            I.Top = 0
            I.ForeColor = Color.Red
            I.Height = 10
            I.Width = 10
            I.BackColor = Color.Yellow
            Me.Controls.Add(I)
            Not_Touch.Add(New Label With {.Left = 60, .Top = 0, .Width = 36, .Height = 277, .AutoSize = False, .BackColor = Solids_Color})
            Not_Touch.Add(New Label With {.Left = 0, .Top = 314, .Width = 333, .Height = 22, .AutoSize = False, .BackColor = Solids_Color})
            Not_Touch.Add(New Label With {.Left = 122, .Top = 37, .Width = 36, .Height = 277, .AutoSize = False, .BackColor = Solids_Color})
            Not_Touch.Add(New Label With {.Left = 184, .Top = 0, .Width = 36, .Height = 277, .AutoSize = False, .BackColor = Solids_Color})
            Not_Touch.Add(New Label With {.Left = 241, .Top = 37, .Width = 36, .Height = 277, .AutoSize = False, .BackColor = Solids_Color})
            Not_Touch.Add(New Label With {.Left = 302, .Top = 0, .Width = 36, .Height = 277, .AutoSize = False, .BackColor = Solids_Color})
            Not_Touch.Add(New Label With {.Left = 362, .Top = 0, .Width = 50, .Height = 377, .AutoSize = False, .BackColor = Solids_Color})
            Me.Controls.Add(Win)
            For Each a As Label In Not_Touch
                Me.Controls.Add(a)
            Next
            MsgBox("Use key up down left right to move")
        End Sub
        Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
            If e.KeyCode = Keys.Up And I.Top > 0 Then I.Top = I.Top - 5
            If e.KeyCode = Keys.Down Then I.Top = I.Top + 5
            If e.KeyCode = Keys.Left And I.Left > 0 Then I.Left = I.Left - 5
            If e.KeyCode = Keys.Right Then I.Left = I.Left + 5
            For Each a As Label In Not_Touch
                If OTO(I, a) = True Then
                    MsgBox("Game Over")
                    Me.Close()
                End If
            Next
            If OTO(I, Win) = True Then
                MsgBox("You Win")
                Me.Close()
            End If
        End Sub
        Public Function OTO(ByVal Obj1 As Object, ByVal Obj2 As Object) As Boolean
            OTO = False
            If Obj1.Left + Obj1.Width >= Obj2.Left Then
                If Obj1.Left <= Obj2.Left + Obj2.Width Then
                    If Obj1.Top + Obj1.Height >= Obj2.Top Then
                        If Obj1.Top <= Obj2.Top + Obj2.Height Then
                            OTO = True
                        End If
                    End If
                End If
            End If
        End Function
    
        'This code is not used. you can use this to improve your games
        Structure Sides
            Public Top As Boolean
            Public Bottom As Boolean
            Public Left As Boolean
            Public Right As Boolean
        End Structure
        Public Function OTO_Sides(ByVal Obj1 As Object, ByVal Obj2 As Object) As Sides
            With OTO_Sides
                .Left = False
                .Bottom = False
                .Right = False
                .Top = False
            End With
            If Obj1.left + Obj1.width = Obj2.left And Obj1.top <= Obj2.top + Obj2.height And Obj1.top + Obj1.height >= Obj2.top Then OTO_Sides.Left = True
            If Obj1.left = Obj2.left + Obj2.width And Obj1.top <= Obj2.top + Obj2.height And Obj1.top + Obj1.height >= Obj2.top Then OTO_Sides.Right = True
            If Obj1.top = Obj2.top + Obj2.height And Obj1.left <= Obj2.left + Obj2.width And Obj1.left + Obj1.width >= Obj2.left Then OTO_Sides.Bottom = True
            If Obj1.top + Obj1.height = Obj2.top And Obj1.left <= Obj2.left + Obj2.width And Obj1.left + Obj1.width >= Obj2.left Then OTO_Sides.Top = True
        End Function
        'Here the unused code is ended
    End Class

    You can see the game:

    enjoy the game.

    You can also edit this game...


    Allow time to reverse.


    • Edited by Abdu Rahman Tuesday, December 25, 2012 10:31 AM
    Tuesday, December 25, 2012 10:27 AM
  • Hi Abdu

    thanks for you solution, I like it too.


    No code, No fact.

    Thursday, December 27, 2012 8:45 AM