0

私はこのゲームを VB 2010 Express で作成しており、これが初めてのゲームです。そして、キャラクターの家の湖のチェストなどとしてピクチャーボックスを使用しています。そして、私はそれでいくつかの問題を抱えています。そのうちの 1 つは、キャラクター (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 に答える