-4

我在本节中遇到多个错误,试图找出计算机获胜、用户获胜或平局。任何人都可以帮助编辑我的代码吗?我刚刚达到了我的能力的尽头。我猜我必须使用对象?但我一直在编辑我的代码,从这里开始只会变得更糟。如果有人可以帮助我,我将非常感激!

' 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
4

1 回答 1

2

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

为了回应您在下面的评论,尝试这样的事情......

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

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

if card1.FaceValue> card2.FaceValue then
    'blahblahblah
End if
于 2013-05-01T14:39:21.493 回答