我正在制作一个二十一点游戏,而且我很难在没有“硬编码”每张图片的情况下获得卡片的图片,而是我传递的值。
当前代码(不想要,但有效):
Public Function Return_Card(CardVal As String, CardSuit As String) As Image
If CardVal = "Ace" And CardSuit = "Clubs" Then
Return My.Resources.AceOfClubs
ElseIf CardVal = "Two" And CardSuit = "Clubs" Then
Return My.Resources.TwoOfClubs
ElseIf CardVal = "Three" And CardSuit = "Clubs" Then
Return My.Resources.ThreeOfClubs
' Need the other 49 cards to complete deck
End If
End Function
期望代码:
Public Function Return_Card(CardVal As String, CardSuit As String) As Image
' Return any picture of a card based on what is being passed in CardVal and CardSuit
Return My.Resources.CardValOfCardSuit
End Function
凸块
答案 0 :(得分:1)
Public Function Return_Card(CardVal As String, CardNum As String) As Image
Return My.Resources.ResourceManager.GetObject(CardVal + "Of" + CardNum)
End Function