Start working on a unified card class
parent
2455812fb2
commit
cc8fbf33ee
|
@ -30,17 +30,12 @@
|
|||
Private Sub OnCardDealt(card As Tuple(Of String, String), cardNumber As String, hide As Boolean) _
|
||||
Handles game.CardDealt
|
||||
Dim pictureBox As PictureBox
|
||||
Debug.Print(cardNumber)
|
||||
Try
|
||||
pictureBox = CType(Me.Controls.Find("PlayerCard" + cardNumber, True).First(), PictureBox)
|
||||
If hide Then
|
||||
pictureBox.Image = My.Resources.blue
|
||||
Else
|
||||
pictureBox.Image = Utilities.GetCardImage(card)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
EndGame("Error: " + ex.Message)
|
||||
End Try
|
||||
pictureBox = CType(Me.Controls.Find("PlayerCard" + cardNumber, True).First(), PictureBox)
|
||||
If hide Then
|
||||
pictureBox.Image = My.Resources.blue
|
||||
Else
|
||||
pictureBox.Image = Utilities.GetCardImage(card)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub SetTotalLabels(playerTotalAmount, dealerTotalAmount) Handles game.SetTotalLabels
|
||||
|
@ -69,4 +64,4 @@
|
|||
StandButton.Enabled = False
|
||||
StartGame.Enabled = True
|
||||
End Sub
|
||||
End Class
|
||||
End Class
|
||||
|
|
|
@ -11,7 +11,10 @@
|
|||
Return list
|
||||
End Function
|
||||
|
||||
Public Shared Function GetCardImage(card As Tuple(Of String, String)) As Image
|
||||
Public Shared Function GetCardImage(card As Tuple(Of String, String), Optional hidden As Boolean = False) As Image
|
||||
If hidden Then
|
||||
Return My.Resources.blue
|
||||
End If
|
||||
Dim suit As String = card.Item1
|
||||
Dim num As String = card.Item2
|
||||
Select Case num
|
||||
|
@ -26,6 +29,10 @@
|
|||
End Select
|
||||
|
||||
Dim img As String = suit + "_" + num
|
||||
Return My.Resources.ResourceManager.GetObject(img.ToLower())
|
||||
Try
|
||||
Return My.Resources.ResourceManager.GetObject(img.ToLower())
|
||||
Catch
|
||||
Return My.Resources.blue
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
|
@ -0,0 +1,50 @@
|
|||
Public Class Card
|
||||
Private Shared idCounter As Integer = 1
|
||||
Private id As Integer
|
||||
Private boxId As PictureBox
|
||||
Private cardImage As Image
|
||||
Private cardName As Tuple(Of String, String)
|
||||
Private cardLocation As Point
|
||||
Private cardHidden As Boolean
|
||||
|
||||
Public Sub New(name As Tuple(Of String, String), Optional hidden As Boolean = False)
|
||||
id = idCounter
|
||||
idCounter += 1
|
||||
boxId = New PictureBox()
|
||||
cardName = name
|
||||
cardHidden = hidden
|
||||
cardImage = Utilities.GetCardImage(name, hidden)
|
||||
End Sub
|
||||
|
||||
Public Sub SetLocation(location As point)
|
||||
cardLocation = location
|
||||
End Sub
|
||||
|
||||
Public Sub SetName(name As Tuple(Of String, String))
|
||||
cardName = name
|
||||
End Sub
|
||||
|
||||
Public Sub SetHidden(hidden As Boolean)
|
||||
cardHidden = hidden
|
||||
End Sub
|
||||
|
||||
Public Function GetId()
|
||||
Return id
|
||||
End Function
|
||||
|
||||
Public Function GetBoxId()
|
||||
Return boxId
|
||||
End Function
|
||||
|
||||
Public Function GetName()
|
||||
Return cardName
|
||||
End Function
|
||||
|
||||
Public Function GetLocation()
|
||||
Return cardLocation
|
||||
End Function
|
||||
|
||||
Public Function IsHidden()
|
||||
Return cardHidden
|
||||
End Function
|
||||
End Class
|
|
@ -4,7 +4,7 @@
|
|||
Public Property ingame As Boolean
|
||||
Public Property winType As WinCondition
|
||||
|
||||
Sub Start()
|
||||
Public Sub Start()
|
||||
hand.Clear()
|
||||
total = 0
|
||||
ingame = True
|
||||
|
|
Loading…
Reference in New Issue