I'm creating a maze from labels using symbols using "#" as the walls and "." as the pathways. I've got to the point that I can create the surrounding wall however I'm having issues filling it with both walls and pathways. I used a random generator to create paths per line and to place walls based on the pathways placed. The first problem I'm having is that it won't place neither the dot to place the walls, and when it did, only 1 or 2 lines tops, leaving the rest of the square empty or with empty spaces in those lines. I've tried playing with the if order with no progress. Each label is linked to a matrix spot as I later need to create an algorithm to solve the maze created.
This is what I've done so far:
Public Class Form1
Public matrix(23, 23) As String
Dim counter As Integer = 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btngen.Click
Dim y As Integer = 9
For i = 0 To matrix.GetLength(0) - 1
Dim x As Integer = 12
For j = 0 To matrix.GetLength(0) - 1
Dim lbl As New Label()
lbl.Name = "lbl" & counter
lbl.Size = New Size(15, 13)
lbl.Location = New Point(x, y)
If i = 0 Or i = 23 Then
lbl.Text = "#"
matrix(i, j) = lbl.Text
End If
If j = 0 Or j = 23 Then
lbl.Text = "#"
matrix(i, j) = lbl.Text
End If
If i > i And matrix(i, j) = "#" Then
Randomize()
Dim k As Integer = CInt(Int((2 * Rnd()) + 1))
If k = 1 Then
lbl.Text = "."
matrix(i, j) = lbl.Text
End If
If i >= i And j >= j And matrix(i, j - 1) = "." Then
lbl.Text = "#"
matrix(i, j) = lbl.Text
End If
End If
'lbl.Text = "#"
Controls.Add(lbl)
x += 21
counter += 1
Next
y += 13
Next
End Sub
End Class
Aucun commentaire:
Enregistrer un commentaire