我做了一個隨機化功能爲我的再生,它只是使所有在整個形式的對角線重生的事情...代碼是這樣的:隨機位置不是隨機的[vb.net]
Public Function RandomNumber(ByVal MaxNumber As Integer, _
Optional ByVal MinNumber As Integer = 0) As Integer
'initialize random number generator
Dim r As New Random(System.DateTime.Now.Millisecond)
'if passed incorrect arguments, swap them
'can also throw exception,return 0
If MinNumber > MaxNumber Then
Dim t As Integer = MinNumber
MinNumber = MaxNumber
MaxNumber = t
End If
Return r.Next(MinNumber, MaxNumber)
End Function
和1個再生的代碼是這樣的:
'regen coins
z = coin1
z.Location = zloc
z.Hide()
zloc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
If zloc.Y > 595 Then
zloc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
End If
z.Location = zloc
z.Show()
我不知道爲什麼,它只是使對角線,但幫助將是非常感謝!
謝謝..但現在在物體中產卵的東西我該如何阻止它? – user2209912 2013-03-26 03:50:24
我建議改變如果zloc.Y> 595然後進行循環而不是單個測試。 '做雖然zloc.Y> 595:zloc =新點(RandomNumber(playspace.Width),RandomNumber(playspace.Height)):循環' – 2013-03-26 03:56:29
這將阻止它在picturebox1,picturebox2和picturebox3內? Z = COIN1 z.Location = zloc z.Hide() zloc =新點(RandomNumber(playspace.Width),RandomNumber(playspace.Height)) 做,當z.Bounds.IntersectsWith(PictureBox1.Bounds ,PictureBox2.Bounds,PictureBox3.Bounds) zloc =新點(RandomNumber(playspace.Width),RandomNumber(playspace.Height)) 循環 z.Location = zloc z.Show() – user2209912 2013-03-26 04:23:36