2013-10-28 66 views
0

我一直在使用VB 2010中的這個遊戲快車,這是我的第一場比賽。而我正在使用pictureboxes作爲我的角色屋湖箱等。我一直在與它有幾個問題。其中之一就是我讓我的角色(Picturebox1/myplayer)觸摸胸部(Picturebox2)時,它會讓我選擇打開胸部或胸部。如果你的選擇是打開胸部,你會得到10個硬幣。但是當我打開箱子並拿到了10個硬幣時,我無法讓它變得無法使用,所以我可以做到無窮無盡的時間,並且還能獲得硬幣。VB.net如何使一個picturebox不可用

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 

可以any1幫助我嗎?

+1

'picturebox2。 enabled = false'或者'button1.enabled = fale'不確定是否要禁用給出硬幣的圖片框或按鈕 – Plutonix

+0

或者只是設置一個標誌或狀態表示發生了動作,並在隨後的點擊中檢查它。 –

回答

1

這被稱爲「遊戲狀態」。您需要存儲在某處,不知何故胸部已被使用的信息。在一個強大的遊戲中,您可以使用類來表示遊戲中的元素。這將允許您存儲有關每個項目的許多屬性,這些屬性可以通過用戶界面進行查詢和更新。

然而,一個簡單的解決方案是將某些東西存儲在PictureBox2的Tag()屬性中。如果沒有在標籤()屬性,則顯示Chest1:

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

一定要裝上去的標籤()屬性之後,以防止它被再次打開:

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