Module DataPath
    Public Function Path() As String
        Path = Application.StartupPath.ToLower.Replace("\enigma\enigma\bin\debug", "\Data\")
        Return Path
    End Function
End Module


' Direction.vb
Public Enum Direction
    Up
    Down
    Left
    Right
End Enum


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.ComponentModel

Public Class frmDesigner
    Const INDENT As Integer = 20
    Const SQCOUNTX As Integer = 15
    Const SQCOUNTY As Integer = 11

    ReadOnly HS(100) As HatchStyle
    Dim MButtons As String
    Dim SQSizeX As Integer
    Dim SQSizeY As Integer
    Dim PicX As Integer
    Dim picy As Integer
    ReadOnly SQ(SQCOUNTX, SQCOUNTY) As Integer
    Dim oldX, oldY As Integer
    Dim SQLocX, SQLocY As Integer
    Dim MouseIsDown As Boolean
    Dim CurrentHatch As HatchStyle = HatchStyle.Cross
    Dim Hatchcolor1 As Color = Color.Black
    Dim Hatchcolor2 As Color = Color.Blue
    Dim highlightColorFlag As Boolean = False
    Dim mouseMoving As Boolean = False
    Dim highlightedX As Integer
    Dim highlightedY As Integer
    Dim flashCounter As Integer = 0

    Private Sub frmDesigner_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        PicGame.Image = New Bitmap(Width, Height)
        For Y As Integer = 1 To SQCOUNTY
            For X As Integer = 1 To SQCOUNTX
                SQ(X, Y) = 1
            Next
        Next
        For I = 1 To lstHatch.Items.Count - 1
            HS(I) = CType(System.Enum.Parse(GetType(HatchStyle), lstHatch.Items.Item(I)), HatchStyle)
        Next

        Dim SS As String = ""
        FileOpen(1, Path() + "Premades.txt", OpenMode.Input)

        While Not EOF(1)
            Input(1, SS)
            lstPremades.Items.Add(SS)
            Input(1, SS)
            Input(1, SS)
            Input(1, SS)
        End While
        FileClose()
    End Sub

    Private Sub PicGame_MouseMove(sender As Object, e As MouseEventArgs) Handles PicGame.MouseMove
        Dim G As Drawing.Graphics = PicGame.CreateGraphics
        G.DrawRectangle(Pens.Black, oldX, oldY, SQSizeX, SQSizeY)

        PicX = CInt(PicGame.Size.Width - (INDENT * 2))
        picy = CInt(PicGame.Size.Height - (INDENT * 2))
        SQSizeX = CInt(PicX / SQCOUNTX)
        SQSizeY = CInt(picy / SQCOUNTY)

        Dim X As Integer = e.Location.X
        Dim Y As Integer = e.Location.Y
        Dim XXX, YYY As Integer

        If X >= INDENT Then SQLocX = 1
        For XXX = 1 To SQCOUNTX
            If X + 2 > (XXX * SQSizeX) + INDENT Then
                SQLocX = XXX + 1
            End If
        Next
        If Y >= INDENT Then SQLocY = 1
        For YYY = 1 To SQCOUNTY
            If Y + 2 > (SQLocY * SQSizeY) + INDENT Then
                SQLocY = YYY + 1
            End If
        Next

        If SQLocX > 0 And SQLocX < SQCOUNTX + 1 And SQLocY > 0 And SQLocY < SQCOUNTY + 1 Then
            highlightedX = SQLocX
            highlightedY = SQLocY
        End If

        oldX = ((SQLocX - 1) * SQSizeX) + INDENT - 1
        oldY = ((SQLocY - 1) * SQSizeY) + INDENT

        Bar1.Text = "X: " + CStr(X) + " Y: " + CStr(Y)
        Bar2.Text = "SqX: " + CStr(SQLocX) + " SqY: " + CStr(SQLocY)

        If MouseIsDown Then
            Select Case MButtons
                Case "Left"
                    If SQ(SQLocX, SQLocY) <> 1 Then
                        SQ(SQLocX, SQLocY) = 1
                        DrawGame()
                    End If
                Case "Right"
                    If SQ(SQLocX, SQLocY) <> 0 Then
                        SQ(SQLocX, SQLocY) = 0
                        DrawGame()
                    End If
            End Select
        End If

        mouseMoving = True
        DrawGame() ' Add this line to redraw the game
    End Sub


    Private Sub DrawGame()
        Dim buffer As New Bitmap(PicGame.Width, PicGame.Height)
        Dim G As Graphics = Graphics.FromImage(buffer)

        G.FillRectangle(Brushes.Black, 0, 0, PicGame.Size.Width, PicGame.Size.Height)

        Dim X, Y, XX, YY As Integer

        XX = INDENT
        YY = INDENT + 1
        For Y = 1 To SQCOUNTY
            For X = 1 To SQCOUNTX
                If SQ(X, Y) > 0 Then
                    G.FillRectangle(New HatchBrush(CurrentHatch, Hatchcolor1, Hatchcolor2), XX, YY, SQSizeX - 1, SQSizeY - 1)
                End If
                XX += SQSizeX
            Next
            XX = INDENT
            YY += SQSizeY
        Next

        If highlightedX > 0 And highlightedX < SQCOUNTX + 1 And highlightedY > 0 And highlightedY < SQCOUNTY + 1 Then
            Dim color As Pen = If(highlightColorFlag, Pens.White, Pens.Black)
            G.DrawRectangle(color, ((highlightedX - 1) * SQSizeX) + INDENT, ((highlightedY - 1) * SQSizeY) + INDENT, SQSizeX - 1, SQSizeY - 1)
        End If

        PicGame.Image = buffer
    End Sub

    Private Sub tmrTick_Tick(sender As Object, e As EventArgs) Handles tmrTick.Tick
        flashCounter += 1
        If flashCounter >= 10 Then
            highlightColorFlag = Not highlightColorFlag
            flashCounter = 0
        End If
        DrawGame() ' Add this line to redraw the game
        mouseMoving = False
    End Sub

    Private Sub DrawHighlight()
        If highlightedX > 0 And highlightedX < SQCOUNTX + 1 And highlightedY > 0 And highlightedY < SQCOUNTY + 1 Then
            Dim color As Pen = If(highlightColorFlag, Pens.White, Pens.Black)
            Dim G As Graphics = PicGame.CreateGraphics
            G.DrawRectangle(color, ((highlightedX - 1) * SQSizeX) + INDENT, ((highlightedY - 1) * SQSizeY) + INDENT, SQSizeX - 1, SQSizeY - 1)
        End If
    End Sub

    Private Sub RoomView_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        DrawGame()
    End Sub

    Private Sub RoomView_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        PicGame.Width = col9.Location.X - 10
        PicGame.Height = Me.Height - 100
        DrawGame()
    End Sub

    Private Sub btnMax_Click(sender As Object, e As EventArgs) Handles btnMax.Click
        PicGame.Width = Me.Width
        PicGame.Height = Me.Height
        DrawGame()
    End Sub

    Private Sub Stuff_Click(sender As Object, e As EventArgs) Handles Stuff1.Click, Stuff2.Click, Stuff3.Click, Stuff4.Click, Stuff5.Click, Stuff6.Click, Stuff7.Click, Stuff8.Click, Stuff9.Click, Stuff10.Click, Stuff11.Click, Stuff12.Click, Stuff13.Click, Stuff14.Click, Stuff15.Click, Stuff16.Click, Stuff17.Click, Stuff18.Click
        Dim P As PictureBox = DirectCast(sender, PictureBox)
        For Each C As Control In Tab1.Controls
            If TypeOf C Is PictureBox Then
                DirectCast(C, PictureBox).BorderStyle = BorderStyle.FixedSingle
            End If
        Next
        P.BorderStyle = BorderStyle.Fixed3D
    End Sub

    Private Sub lstHatch_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstHatch.SelectedIndexChanged
        CurrentHatch = HS(lstHatch.SelectedIndex)
        DrawGame()
    End Sub

    Private Sub col_Click(sender As Object, e As EventArgs) Handles col1.Click, col2.Click, col3.Click, col4.Click, col5.Click, col6.Click, col7.Click, col8.Click, col9.Click, col10.Click, col11.Click, col12.Click, col13.Click, col14.Click, col15.Click, col16.Click, col17.Click, col18.Click, col19.Click, col20.Click, col21.Click, col22.Click, col23.Click, col24.Click, col25.Click, col26.Click, col27.Click, col28.Click, col29.Click, col30.Click, col31.Click, col32.Click, col33.Click, col34.Click, col35.Click, col36.Click, col37.Click, col38.Click, col39.Click, col40.Click, col41.Click, col42.Click, col43.Click, col44.Click, col45.Click, col46.Click, col47.Click, col48.Click
        Dim control As Control = DirectCast(sender, Control)
        Hatchcolor1 = control.BackColor
        DrawGame()
    End Sub

    Private Sub col_Click2(sender As Object, e As EventArgs) Handles col51.Click, col52.Click, col53.Click, col54.Click, col55.Click, col56.Click, col57.Click, col58.Click, col59.Click, col60.Click, col61.Click, col62.Click, col63.Click, col64.Click, col65.Click, col66.Click, col67.Click, col68.Click, col69.Click, col70.Click, col71.Click, col72.Click, col73.Click, col74.Click, col75.Click, col76.Click, col77.Click, col78.Click, col79.Click, col80.Click, col81.Click, col82.Click, col83.Click, col84.Click, col85.Click, col86.Click, col87.Click, col88.Click, col89.Click, col90.Click, col91.Click, col92.Click, col93.Click, col94.Click, col95.Click, col96.Click, col97.Click, col98.Click
        Dim control As Control = DirectCast(sender, Control)
        Hatchcolor2 = control.BackColor
        DrawGame()
    End Sub

    Private Sub PicGame_MouseDown(sender As Object, e As MouseEventArgs) Handles PicGame.MouseDown
        MouseIsDown = True
        Select Case e.Button
            Case MouseButtons.Left
                MButtons = "Left"
            Case MouseButtons.Right
                MButtons = "Right"
        End Select
    End Sub

    Private Sub PicGame_MouseUp(sender As Object, e As MouseEventArgs) Handles PicGame.MouseUp
        MouseIsDown = False
    End Sub
End Class


' frmGame.vb
Imports System.Threading
Imports System.Windows.Forms

Public Class frmGame
    Inherits Form

    Private plannedMoves As New List(Of PlannedMove)()
    Private moveLock As New Object()
    Private moveThread As Thread
    Private gameRunning As Boolean = True

    Private currentPlayer As Player
    Private gameMap As GameMap
    Private gameObjects As List(Of GameObject)

    ' Constructor accepting parameters
    Public Sub New(clonedGridRenderer As GridRenderer, levelName As String, clonedGameObjects As List(Of GameObject))
        ' This call is required by the designer.
        InitializeComponent()

        ' Assign the cloned grid renderer and game objects
        Me.gameMap = New GameMap(clonedGridRenderer)
        Me.gameObjects = clonedGameObjects

        ' Initialize the current player at a starting position (you can modify the position as needed)
        currentPlayer = New Player(New Point(1, 1)) ' Starting at position (1,1)

        ' Set the form's title to the level name
        Me.Text = "Game - " & levelName

        ' Start the move processing thread
        moveThread = New Thread(AddressOf ProcessMoves)
        moveThread.IsBackground = True
        moveThread.Start()

        ' Attach the KeyDown event handler to capture key presses
        AddHandler Me.KeyDown, AddressOf frmGame_KeyDown

        ' Ensure the form is focused to receive keyboard input
        Me.KeyPreview = True

        ' Optionally, initialize any other UI elements or controls here
    End Sub

    ' KeyDown event handler
    Private Sub frmGame_KeyDown(sender As Object, e As KeyEventArgs)
        Dim direction As Direction

        Select Case e.KeyCode
            Case Keys.W
                direction = Direction.Up
            Case Keys.A
                direction = Direction.Left
            Case Keys.S
                direction = Direction.Down
            Case Keys.D
                direction = Direction.Right
            Case Else
                Exit Sub ' Exit if another key is pressed
        End Select

        ' Queue the planned move
        Dim plannedMove As New PlannedMove(currentPlayer, direction)
        SyncLock moveLock
            plannedMoves.Add(plannedMove)
        End SyncLock
    End Sub

    ' ProcessMoves method
    Private Sub ProcessMoves()
        While gameRunning
            Dim movesToProcess As List(Of PlannedMove)

            ' Copy and clear the planned moves safely
            SyncLock moveLock
                movesToProcess = New List(Of PlannedMove)(plannedMoves)
                plannedMoves.Clear()
            End SyncLock

            ' Process each move
            For Each plannedMove In movesToProcess
                plannedMove.Player.MovePlayer(plannedMove.Direction, gameMap)
            Next

            ' Update the game UI after processing moves
            If Me.IsHandleCreated AndAlso Not Me.IsDisposed Then
                Me.Invoke(Sub()
                              ' Update any UI elements to reflect the new game state
                              ' For example, if you're using PictureBoxes or Panels to represent the game
                          End Sub)
            End If

            ' Sleep to control the processing rate
            Thread.Sleep(50) ' Adjust as needed
        End While
    End Sub

    ' FormClosing event handler
    Protected Overrides Sub OnFormClosing(e As FormClosingEventArgs)
        ' Stop the game loop when the form is closing
        gameRunning = False
        If moveThread IsNot Nothing AndAlso moveThread.IsAlive Then
            moveThread.Join()
        End If

        MyBase.OnFormClosing(e)
    End Sub

End Class


' GameMap.vb
Public Class GameMap
    Public Property Width As Integer
    Public Property Height As Integer
    Public Tiles(,) As Tile

    ' Parameterless constructor
    Public Sub New()
        ' Set default dimensions
        Width = 15
        Height = 11
        ReDim Tiles(Width - 1, Height - 1)
        InitializeTiles()
    End Sub

    ' Constructor accepting a GridRenderer
    Public Sub New(gridRenderer As GridRenderer)
        ' Initialize dimensions based on the gridRenderer
        Width = gridRenderer.WallX.GetLength(0) - 1
        Height = gridRenderer.WallY.GetLength(1) - 1
        ReDim Tiles(Width - 1, Height - 1)
        InitializeTiles(gridRenderer)
    End Sub

    ' Method to initialize tiles
    Private Sub InitializeTiles(Optional gridRenderer As GridRenderer = Nothing)
        For x As Integer = 0 To Width - 1
            For y As Integer = 0 To Height - 1
                If gridRenderer IsNot Nothing Then
                    If gridRenderer.IsCellBlocked(x, y) Then
                        Tiles(x, y) = New Tile(TileType.Wall)
                    Else
                        Tiles(x, y) = New Tile(TileType.Floor)
                    End If
                Else
                    ' Default to floor if no gridRenderer
                    Tiles(x, y) = New Tile(TileType.Floor)
                End If
            Next
        Next
    End Sub
End Class


' GameObject.vb
Imports System.Drawing

Public Class GameObject
    Public Property Image As Image
    Public Property CellX As Integer
    Public Property CellY As Integer
    Public Property ImageTag As String

    Public Sub New(img As Image, x As Integer, y As Integer, imgTag As String)
        Me.Image = img
        Me.CellX = x
        Me.CellY = y
        Me.ImageTag = imgTag
    End Sub

    ' Method to clone the GameObject
    Public Function Clone() As GameObject
        Return New GameObject(Me.Image, Me.CellX, Me.CellY, Me.ImageTag)
    End Function
End Class


' GridRenderer.vb
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class GridRenderer
    ' Fields for wall arrays
    Public WallX(,) As Boolean
    Public WallY(,) As Boolean

    ' Properties for hatch styles and colors
    Public Property wallsHatchStyle As HatchStyle = HatchStyle.Cross
    Public Property wallsColor1 As Color = Color.Gray
    Public Property wallsColor2 As Color = Color.DarkGray
    Public Property floorsHatchStyle As HatchStyle = HatchStyle.SmallCheckerBoard
    Public Property floorsColor1 As Color = Color.LightGray
    Public Property floorsColor2 As Color = Color.White

    ' Calculated square sizes
    Public SQSizeX As Integer
    Public SQSizeY As Integer

    ' Constructor
    Public Sub New()
        ' Initialize the wall arrays
        WallX = New Boolean(15, 11) {}
        WallY = New Boolean(15, 11) {}

        ' Set all walls to true (walls exist everywhere by default)
        For i As Integer = 0 To WallX.GetLength(0) - 1
            For j As Integer = 0 To WallX.GetLength(1) - 1
                WallX(i, j) = True
            Next
        Next

        For i As Integer = 0 To WallY.GetLength(0) - 1
            For j As Integer = 0 To WallY.GetLength(1) - 1
                WallY(i, j) = True
            Next
        Next
    End Sub

    ' Method to calculate square sizes
    Public Sub CalculateSquareSizes(clientWidth As Integer, clientHeight As Integer, SQCOUNTX As Integer, SQCOUNTY As Integer, WALL_THICKNESS As Integer)
        SQSizeX = (clientWidth - 2 * 20 - (SQCOUNTX + 1) * WALL_THICKNESS) \ SQCOUNTX
        SQSizeY = (clientHeight - 2 * 20 - (SQCOUNTY + 1) * WALL_THICKNESS) \ SQCOUNTY
    End Sub

    ' Method to draw the grid
    Public Sub DrawGrid(g As Graphics, clientWidth As Integer, clientHeight As Integer, INDENT As Integer, SQCOUNTX As Integer, SQCOUNTY As Integer, WALL_THICKNESS As Integer)
        ' Drawing logic for walls and floors
        Dim xOrigin As Integer = INDENT
        Dim yOrigin As Integer = INDENT

        ' Draw floors
        For x As Integer = 0 To SQCOUNTX - 1
            For y As Integer = 0 To SQCOUNTY - 1
                Dim floorRect As New Rectangle(xOrigin + x * (SQSizeX + WALL_THICKNESS) + WALL_THICKNESS \ 2,
                                               yOrigin + y * (SQSizeY + WALL_THICKNESS) + WALL_THICKNESS \ 2,
                                               SQSizeX,
                                               SQSizeY)

                Using floorBrush As New HatchBrush(floorsHatchStyle, floorsColor1, floorsColor2)
                    g.FillRectangle(floorBrush, floorRect)
                End Using
            Next
        Next

        ' Draw walls (vertical)
        For x As Integer = 0 To SQCOUNTX
            For y As Integer = 0 To SQCOUNTY - 1
                If WallX(x, y) Then
                    Dim wallRect As New Rectangle(xOrigin + x * (SQSizeX + WALL_THICKNESS) - WALL_THICKNESS \ 2,
                                                  yOrigin + y * (SQSizeY + WALL_THICKNESS) + WALL_THICKNESS \ 2,
                                                  WALL_THICKNESS,
                                                  SQSizeY)

                    Using wallBrush As New HatchBrush(wallsHatchStyle, wallsColor1, wallsColor2)
                        g.FillRectangle(wallBrush, wallRect)
                    End Using
                End If
            Next
        Next

        ' Draw walls (horizontal)
        For x As Integer = 0 To SQCOUNTX - 1
            For y As Integer = 0 To SQCOUNTY
                If WallY(x, y) Then
                    Dim wallRect As New Rectangle(xOrigin + x * (SQSizeX + WALL_THICKNESS) + WALL_THICKNESS \ 2,
                                                  yOrigin + y * (SQSizeY + WALL_THICKNESS) - WALL_THICKNESS \ 2,
                                                  SQSizeX,
                                                  WALL_THICKNESS)

                    Using wallBrush As New HatchBrush(wallsHatchStyle, wallsColor1, wallsColor2)
                        g.FillRectangle(wallBrush, wallRect)
                    End Using
                End If
            Next
        Next
    End Sub

    ' Method to determine if a cell is blocked
    Public Function IsCellBlocked(x As Integer, y As Integer) As Boolean
        If WallX(x, y) OrElse WallX(x + 1, y) OrElse WallY(x, y) OrElse WallY(x, y + 1) Then
            Return True
        End If
        Return False
    End Function

    ' Method to clone the GridRenderer
    Public Function Clone() As GridRenderer
        Dim newRenderer As New GridRenderer()
        newRenderer.WallX = CType(Me.WallX.Clone(), Boolean(,))
        newRenderer.WallY = CType(Me.WallY.Clone(), Boolean(,))
        newRenderer.wallsHatchStyle = Me.wallsHatchStyle
        newRenderer.wallsColor1 = Me.wallsColor1
        newRenderer.wallsColor2 = Me.wallsColor2
        newRenderer.floorsHatchStyle = Me.floorsHatchStyle
        newRenderer.floorsColor1 = Me.floorsColor1
        newRenderer.floorsColor2 = Me.floorsColor2
        Return newRenderer
    End Function
End Class


' PlannedMove.vb
Public Class PlannedMove
    Public Property Player As Player
    Public Property Direction As Direction

    Public Sub New(player As Player, direction As Direction)
        Me.Player = player
        Me.Direction = direction
    End Sub
End Class


' Player.vb
Imports System.Drawing

Public Class Player
    Public Property Position As Point

    Public Sub New(startPosition As Point)
        Position = startPosition
    End Sub

    Public Sub MovePlayer(direction As Direction, gameMap As GameMap)
        Dim newPosition As Point = Position

        Select Case direction
            Case Direction.Up
                newPosition.Y -= 1
            Case Direction.Down
                newPosition.Y += 1
            Case Direction.Left
                newPosition.X -= 1
            Case Direction.Right
                newPosition.X += 1
        End Select

        If IsValidMove(newPosition, gameMap) Then
            Position = newPosition
        End If
    End Sub

    Private Function IsValidMove(newPosition As Point, gameMap As GameMap) As Boolean
        If newPosition.X < 0 OrElse newPosition.X >= gameMap.Width OrElse
           newPosition.Y < 0 OrElse newPosition.Y >= gameMap.Height Then
            Return False
        End If

        If gameMap.Tiles(newPosition.X, newPosition.Y).Type = TileType.Wall Then
            Return False
        End If

        Return True
    End Function
End Class


' Tile.vb
Public Class Tile
    Public Property Type As TileType

    Public Sub New(type As TileType)
        Me.Type = type
    End Sub
End Class

Public Enum TileType
    Floor
    Wall
End Enum


The above is my code. I've made a lot of mistakes moving files about etc, renaming forms. And I'm stuck! Here are my errors. Please help..


Severity	Code	Description	Project	File	Line	Suppression State
Error		Two output file names resolved to the same output path: "obj\Debug\Enigma.frmDesigner.resources"	Enigma			
Warning		The file '..\..\Enigma\Enigma\frmDesigner.Designer.vb' could not be added to the project.  Cannot add a link to the file D:\01 - Grags\Visual Studio\Enigma\Enigma\Enigma\frmDesigner.Designer.vb. This file is within the project directory tree.	Enigma			
Warning		The parent file, 'frmDesigner.vb', for file '..\..\Enigma\Enigma\frmDesigner.resx' cannot be found in the project file.	Enigma			
Warning		The file '..\..\Enigma\Enigma\frmDesigner.resx' could not be added to the project.  Cannot add a link to the file D:\01 - Grags\Visual Studio\Enigma\Enigma\Enigma\frmDesigner.resx. This file is within the project directory tree.	Enigma			
Warning		The file '..\..\Enigma\Enigma\frmDesigner.vb' could not be added to the project.  Cannot add a link to the file D:\01 - Grags\Visual Studio\Enigma\Enigma\Enigma\frmDesigner.vb. This file is within the project directory tree.	Enigma			
Warning		The parent file, 'frmDesigner.vb', for file '..\..\Enigma\Enigma\frmDesigner.Designer.vb' cannot be found in the project file.	Enigma