2013-05-01 2 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

+1

특정 문제에 대해보다 구체적으로 설명하고 문제를 해결하는 가장 작은 금액으로 코드를 트리밍 할 수 있습니까? 그렇게하면 원인을 알 수 있습니다. –

+0

'cardXPictureBox'는 PictureBox 컨트롤에서 파생 되었습니까? – ajakblackgoat

답변

2

.FaceValue는 PictureBox의 속성이 아닙니다. 대신 생성 된 카드를 기반으로 갑판에서 FaceValue를 가져와야합니다.

아래에 귀하의 코멘트에 대한 응답으로, 당신은 PictureBoxes 중 하나를 설정하는 방법

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

그래서, 그 ...이 같은 을 시도합니다. 두 번째 작업을 수행 할 수 있습니다. 그렇다면 비교를 통해 누가 이겼는지 확인하십시오 ...

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

당신은 나를 때렸어. 그것은 실제로 문제의 원인입니다. –

+1

Joe가 StackOverflow 계정을 생성하고 컴파일러가 그를 알려주지 만 코드 벽을 붙여 넣으려면 Joe가 모든 시간을 보냈다면 슬 be습니다. 'FaceValue'는 'System.Windows.Forms.PictureBox'**의 멤버가 아닙니다. – djv

+0

@Dan Verdolino 슬픈 일입니다. 내가 뭘 넣으려고했는지 상관없이. 나는 그것을 작동시킬 수 없습니다. – Joe

관련 문제