I've created a map where I can create/place/drag rooms around to link them up. This is the basis for an adventure story creator.
Name:  roomz-1.jpg
Views: 521
Size:  17.0 KB

I'm trying to write the code to check and determine whether two controls (rooms) are linked (next to each other). While this is simple when all the rooms are the same size, it quickly becomes convoluted when they are different sizes/shapes.

Code:
    Private Sub Room_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs)
        FormEditor.LabelPortals.Text = sender.name & " - Right click to edit. Links to"
        ' detect portals
        For Each ctrl In Me.Controls.Cast(Of Control)().ToArray()
            If ctrl.Tag = "room" And Not ctrl Is sender Then
                ' small rooms
                ' north
                If ctrl.Top + GridSize = sender.top And ctrl.Left = sender.left Then
                    FormEditor.LabelPortals.Text &= " - " & ctrl.Name
                End If
                ' south
                If ctrl.Top = sender.top + GridSize And ctrl.Left = sender.left Then
                    FormEditor.LabelPortals.Text &= " - " & ctrl.Name
                End If
                ' west
                If ctrl.Left = sender.left - GridSize And ctrl.Top = sender.top Then
                    FormEditor.LabelPortals.Text &= " - " & ctrl.Name
                End If
                ' east
                If ctrl.Left = sender.left + GridSize And ctrl.Top = sender.top Then
                    FormEditor.LabelPortals.Text &= " - " & ctrl.Name
                End If
                ' large rooms
                ' north
                If ctrl.Width = GridSize * 2 And ctrl.Height = GridSize * 2 And _
                    ctrl.Top = sender.Top - GridSize * 2 And ctrl.Left = sender.left Or ctrl.Left = sender.left - GridSize Then
                    FormEditor.LabelPortals.Text &= " - " & ctrl.Name
                End If
            End If
        Next
    End Sub
I'm sure there is a better way to do this, but I'm not sure what it would be or what to search for. Any help is appreciated.