Vb.net 如何使用PictureBox.Bounds.IntersectsWith使五个PictureBox不相互重叠

Vb.net 如何使用PictureBox.Bounds.IntersectsWith使五个PictureBox不相互重叠,vb.net,picturebox,Vb.net,Picturebox,我正在做一个骰子游戏,玩家掷五个骰子,其中的骰子显示在图片框中。我想要一个逼真的投掷,我已经做了两个小时了。我已经使用PictureBox.Bounds.IntersectsWith属性来确保它们在抛出时不会相互重叠。问题是它们总是重叠。你们中有专家知道我如何使用IntersectsWith属性来确保骰子之间没有重叠吗。我试了又试,但没能想出解决办法。有人有什么建议吗?谢谢尼尔 这是我的密码: Private PictureBoxDie(4) As PictureBox Private intD

我正在做一个骰子游戏,玩家掷五个骰子,其中的骰子显示在图片框中。我想要一个逼真的投掷,我已经做了两个小时了。我已经使用PictureBox.Bounds.IntersectsWith属性来确保它们在抛出时不会相互重叠。问题是它们总是重叠。你们中有专家知道我如何使用IntersectsWith属性来确保骰子之间没有重叠吗。我试了又试,但没能想出解决办法。有人有什么建议吗?谢谢尼尔

这是我的密码:

Private PictureBoxDie(4) As PictureBox
Private intDieMaxTop = 16
Private intDieMaxLeft = 6
Private intDieMaxRight = 392
Private intDieMaxBottom = 328
Private rndRandomClass As New Random()

Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub ButtonRoll_Click(sender As Object, e As EventArgs) Handles ButtonRoll.Click
    Dim i As Integer = 0
    For i = 0 To 4
        GroupBoxRoll.Controls.Remove(PictureBoxDie(i))
    Next

    For i = 0 To 4
        PictureBoxDie(i) = New PictureBox
        With PictureBoxDie(i)
            .BorderStyle = BorderStyle.FixedSingle
            .Size = New Size(67, 67)
            .Location = GenerateDieLocation()
        End With
    Next

    i = 0
    For i = 0 To 4
        GroupBoxRoll.Controls.Add(PictureBoxDie(i))
    Next
End Sub

Private Function GenerateDieLocation() As Point
    Dim x As Integer = 0
    Dim y As Integer = 0
    x = rndRandomClass.Next(16, 392)
    y = rndRandomClass.Next(16, 392)
    Return New Point(x, y)
End Function

Private Sub CheckDieIntersectsWith()
    Dim booIntersetsWith(4) As Boolean
    Dim x As Integer = 0
    Dim y As Integer = 0
    Do
        For y = 1 To 4
            For x = 0 To 4
                If PictureBoxDie(x).Bounds.IntersectsWith(PictureBoxDie(y).Bounds) Then
                    booIntersetsWith(x) = True
                    PictureBoxDie(x).Location = GenerateDieLocation()
                    Exit For
                Else
                    booIntersetsWith(x) = False
                End If
            Next
        Next

        If booIntersetsWith(0) = False And booIntersetsWith(1) = False And booIntersetsWith(2) = False _
            And booIntersetsWith(3) = False And booIntersetsWith(4) = False Then
            Exit Do
        End If
    Loop
End Sub

在移动PicBoxA之前,请使用
IntersectsWith
测试新位置是否合法。如果没有,请选择一个新位置。或者,只需制作一个翻滚模具的动画GIF,在每个模具中显示,只需将图片框向下移动到掷骰区域,而不是尝试使用PictureBoxe模拟翻滚。这是翻滚GIF的一个好主意。谢谢如果我搞不懂图片盒,我就试试看。