|
戯れに作ってみて、ごみ箱に捨てるのもアレなので載っけておきます。
Dim 方向 As Point = New Point(1, 0)
Dim 乱数 As Random = New Random()
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim 移動量 As Integer = 乱数.Next(1, 11)
For i As Integer = 1 To 4
Dim 進んだ先 As Rectangle = New Rectangle(PictureBox1.Location + New Point(方向.X * 移動量, 方向.Y * 移動量), PictureBox1.Size)
' 進んだ先も画面内かな?
If Me.ClientRectangle.Contains(進んだ先) Then
' それじゃ、安心して進もうか
PictureBox1.Location += New Point(方向.X * 移動量, 方向.Y * 移動量)
Return
End If
' 時計回りに方向転換
方向 = New Point(-方向.Y, 方向.X)
Next
' どうやっても進めない
Timer1.Stop()
MessageBox.Show("隊長、これ以上進めないであります><")
End Sub
|