VB.net ..使用对象时出错?

时间:2013-05-01 12:16:01

标签: 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 个答案:

答案 0 :(得分:2)

问题是.FaceValue不是PictureBox的属性。您需要根据生成的卡片从Deck中获取FaceValue。

在回复下面的评论时,请尝试 这个......

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

所以,这就是你设置一个PictureBox的方法。你可以做第二个。然后在你的比较中看看谁赢了...

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