0

我一直在 VB 2010 express 中制作这款游戏​​,这是我的第一款游戏。我正在使用图片框作为我的角色屋湖箱等。我一直有一些问题。其中之一是当我的角色(Picturebox1/myplayer)触摸胸部(Picturebox2)时,我可以选择打开胸部并离开它。如果您选择打开箱子,您将获得 10 个硬币。但是当我打开箱子并拿到 10 枚硬币时,我无法让它无法使用,所以我可以无限次进行并且仍然可以获得硬币。

Private Sub mymap_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    Dim Loc As Point
    Select Case e.KeyCode
        Case Keys.W
            If Not myplayer.Location.Y - 5 < 0 Then
                Loc = New Point(myplayer.Location.X, myplayer.Location.Y - 5)
                myplayer.Location = Loc
            End If

        Case Keys.S
            If Not myplayer.Location.Y + 5 < 0 Then
                Loc = New Point(myplayer.Location.X, myplayer.Location.Y + 5)
                myplayer.Location = Loc
            End If

        Case Keys.A
            If Not myplayer.Location.X - 5 < 0 Then
                Loc = New Point(myplayer.Location.X - 5, myplayer.Location.Y)
                myplayer.Location = Loc
            End If
        Case Keys.D
            If Not myplayer.Location.X + 5 < 0 Then
                Loc = New Point(myplayer.Location.X + 5, myplayer.Location.Y)
                myplayer.Location = Loc
            End If
    End Select
   If myplayer.Bounds.IntersectsWith(PictureBox2.Bounds) Then
        Chest1.Show()
    End If
End Sub

然后它打开了是否打开箱子的选项。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.Hide()
    MsgBox("You found 10 coins in the chest")
    Form1.ProgressBar1.Increment(10)
    HouseBuy.ProgressBar1.Increment(10)
    HouseSell.ProgressBar1.Increment(10)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Me.Hide()
End Sub

任何人都可以帮助我吗?

4

1 回答 1

1

这被称为“游戏状态”。你需要在某个地方存储已经使用过的信息。在一个健壮的游戏中,您可以使用类来表示游戏中的元素。这将允许您存储有关每个项目的许多属性,这些属性可以由用户界面查询和更新。

然而,一个简单的解决方案是在 PictureBox2 的 Tag() 属性中存储一些内容。如果 Tag() 属性中没有任何内容,则显示 Chest1:

    If myplayer.Bounds.IntersectsWith(PictureBox2.Bounds) Then
        If IsNothing(PictureBox2.Tag) Then
            Chest1.Show()
        End If
    End If

之后一定要在 Tag() 属性中放一些东西,以防止它再次被打开:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Me.Hide()
    MsgBox("You found 10 coins in the chest")
    Form1.ProgressBar1.Increment(10)
    Form1.PictureBox2.Tag = True ' <-- disable the Chest
    HouseBuy.ProgressBar1.Increment(10)
    HouseSell.ProgressBar1.Increment(10)
End Sub
于 2013-10-28T15:29:05.413 回答