-4

私は現在、作られたゲームでいくつかのものを再生成するための巨大なコードを持っています。コードは非常に大きく、圧縮できると思いますが、その方法がわかりません。これはコードPrivateSubregen()です

    '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()


    z = coin2


    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()

    z = coin3


    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()

    z = coin4


    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()

    z = coin5


    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()

    z = coin6


    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()

    z = coin7


    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()

    z = coin8


    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()

    z = coin9

    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()

    z = coin10


    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()

    z = coin11


    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()

    z = coin12


    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()

    z = coin13


    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()

    z = coin14


    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()

    z = coin15


    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()

    z = coin16


    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()

    z = coin17


    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()

    z = coin18


    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()

    z = coin19


    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()

    z = coin20


    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()

    z = coin21


    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()

    z = coin22


    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()

    z = coin23


    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()

    z = coin24


    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()

    z = coin25


    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()

    z = coin26


    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()

    z = coin27


    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()

    z = coin28


    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()

    z = coin29


    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()

    z = coin30


    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()

    z = coin31


    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()

    z = coin32


    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()

    'regen medcoins

    p = medcoin1


    p.Location = ploc
    p.Hide()
    ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If ploc.Y > 595 Then
        ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    p.Location = ploc
    p.Show()

    p = medcoin2

    p.Location = ploc
    p.Hide()
    ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If ploc.Y > 595 Then
        ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    p.Location = ploc
    p.Show()

    p = medcoin3


    p.Location = ploc
    p.Hide()
    ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If ploc.Y > 595 Then
        ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    p.Location = ploc
    p.Show()

    p = medcoin4


    p.Location = ploc
    p.Hide()
    ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If ploc.Y > 595 Then
        ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    p.Location = ploc
    p.Show()

    p = medcoin5


    p.Location = ploc
    p.Hide()
    ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If ploc.Y > 595 Then
        ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    p.Location = ploc
    p.Show()

    p = medcoin6


    p.Location = ploc
    p.Hide()
    ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If ploc.Y > 595 Then
        ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    p.Location = ploc
    p.Show()

    p = medcoin7


    p.Location = ploc
    p.Hide()
    ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If ploc.Y > 595 Then
        ploc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    p.Location = ploc
    p.Show()



    'regens hcoins

    h = hcoin1


    h.Location = hloc
    h.Hide()
    hloc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If hloc.Y > 595 Then
        hloc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    h.Location = hloc
    h.Show()

    h = hcoin2



    h.Location = hloc
    h.Hide()
    hloc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If hloc.Y > 595 Then
        hloc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    h.Location = hloc
    h.Show()

    h = hcoin3


    h.Location = hloc
    h.Hide()
    hloc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    If hloc.Y > 595 Then
        hloc = New Point(RandomNumber(playspace.Width), RandomNumber(playspace.Height))
    End If
    h.Location = hloc
    h.Show()



End Sub

ご覧のとおり、これは一連のコードです。

4

1 に答える 1

0

関数を作成し、それにコインを渡します。

Sub DoStuff(z as coin)
     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()
End Sub

その後、他の場所からそれを呼び出します

DoStuff (coin1)
DoStuff (coin2)
DoStuff (coin3)

配列についても読みたいと思うかもしれません...

于 2013-03-27T00:31:09.773 に答える