2013-05-01 50 views
-4

我在本節中得到多個錯誤,試圖找出電腦贏,用戶贏或領帶。任何人都可以請幫助編輯我的代碼?我剛剛結束了我的能力。我猜我必須使用對象?但是我一直在編輯我的代碼,而且從這裏只會變得更糟。如果有人能幫助我,我會非常感謝!VB.net ..使用對象時出錯?

' Card shuffling and dealing application. 
Public Class DeckOfCardsTest 
    Dim userwin As Integer 
    Dim compwin As Integer 
    Dim ties As Integer 

    Private deck As New DeckOfCards() ' create the deck of cards 

    ' shuffle the deck when user clicks the Shuffle Button 
    Private Sub shuffleButton_Click(ByVal sender As System.Object, 
     ByVal e As System.EventArgs) Handles shuffleButton.Click 

     deck.Shuffle() ' shuffles the deck 
     card1PictureBox.Image = Nothing ' clear image 
     card2PictureBox.Image = Nothing ' clear image 
     dealButton.Enabled = True ' allow user to click the Deal Button 
     MessageBox.Show("Deck is shuffled") 
    End Sub ' shuffleButton_Click 

    Private Sub dealButton_Click(ByVal sender As System.Object, 
     ByVal e As System.EventArgs) Handles dealButton.Click 

    End Sub ' dealButton_Click 

    ' return an image for the Card argument 
    Private Function GetCardImage(ByVal card As Card) As Image 
     If card IsNot Nothing Then 
      ' retrieve specific card image from resources 
      Dim pictureResource = My.Resources.ResourceManager.GetObject(
       card.ToString().Replace(" ", "")) 
      Return CType(pictureResource, Image) ' return Image 
     Else 
      dealButton.Enabled = False ' disable the Deal Button 
      Return Nothing ' no more cards 
     End If 



    End Function ' GetCardImage 
End Class ' DeckOfCardsTest 
+1

這個功課? – stevehipwell 2013-05-01 12:27:07

+1

您能否更具體地瞭解一個特定的問題,並將代碼修剪到仍然存在問題的最小量。這樣做可能會告訴你原因是什麼。 – 2013-05-01 12:28:37

+0

'cardXPictureBox'派生自PictureBox控件嗎? – ajakblackgoat 2013-05-01 12:28:43

回答

2

問題是.FaceValue不是PictureBox的屬性。您將需要根據生成的卡片從您的卡組中抓取FaceValue。

在回答下面的評論,嘗試一些這...

Dim card1 as new card = deck.DealCard() 
card1PictureBox.Image = GetCardImage(card1) 

所以,這就是你如何設置PictureBoxes之一。你可以做第二個。然後在你的比較中看誰贏了...

if card1.FaceValue> card2.FaceValue then 
    'blahblahblah 
End if 
+0

你打敗了我。這確實是問題的原因。 – 2013-05-01 14:47:29

+1

如果Joe花費所有時間來創建一個StackOverflow帳戶並粘貼代碼牆,儘管編譯器告訴他**'FaceValue'不是'System.Windows.Forms.PictureBox'**的成員,那將會很難過。 – djv 2013-05-01 15:23:07

+0

@丹Verdolino這是傷心..因爲無論我已經試圖放在那裏..我無法得到它的工作。 – Joe 2013-05-01 17:59:01