动态引用资源图像

时间:2017-10-20 03:50:51

标签: vb.net

我正在制作一个二十一点游戏,而且我很难在没有“硬编码”每张图片的情况下获得卡片的图片,而是我传递的值。

当前代码(不想要,但有效):

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

凸块

1 个答案:

答案 0 :(得分:1)

Public Function Return_Card(CardVal As String, CardNum As String) As Image
    Return My.Resources.ResourceManager.GetObject(CardVal + "Of" + CardNum)
End Function