VB用符号创建一个迷宫并用右手算法解决

时间:2019-12-07 23:59:02

标签: vb.net

我得到了这段代码,以24x24格式打印标签,但是当使用matrix.lenght时,我无法使“ for”使用矩阵的长度作为限制,但是在Controls.Add(lbl);处出现了错误如果我使用“ 23”作为限制,它将起作用。这是到目前为止的代码:

Public matrix(23, 23) As Integer
    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 23
            Dim x As Integer = 12
            For j = 0 To 23
                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 = "#"
                End If
                If j = 0 Or j = 23 Then
                    lbl.Text = "#"
                End If
                lbl.Text = "#"
                Controls.Add(lbl)
                x += 21
                counter += 1
            Next
            y += 13
        Next
    End Sub
End Class

我还需要在“#”和“。”之间随机选择。做迷宫。那里的if用于迷宫的边界墙。预先感谢。

0 个答案:

没有答案