Convert more functions to use card class

remotes/origin/master
CrystalMoogle 2023-07-21 18:20:03 +01:00
parent c286b08521
commit a368d0af41
5 changed files with 67 additions and 5 deletions

View File

@ -4,6 +4,8 @@
Private boxId As PictureBox
Private cardImage As Image
Private cardName As Tuple(Of String, String)
Private cardSuit As String
Private cardNumber as String
Private cardLocation As Point
Private cardHidden As Boolean
@ -12,6 +14,8 @@
idCounter += 1
boxId = New PictureBox()
cardName = name
cardSuit = name.item1
cardNumber = name.item2
cardHidden = hidden
cardImage = Utilities.GetCardImage(name, hidden)
End Sub
@ -40,6 +44,13 @@
Return cardName
End Function
Public Function GetSuit() As String
Return cardSuit
End Function
Public Function GetNumber() As String
Return cardNumber
End Function
Public Function GetLocation()
Return cardLocation
End Function

View File

@ -33,6 +33,7 @@
Sub DealCard(playerDealt As Object, Optional hide As Boolean = False)
Dim card As Tuple(Of String, String) = deck(0)
Dim playingCard = New Card(card, hide)
playerDealt.hand.Add(card)
deck.RemoveAt(0)
GetTotal(playerDealt, hide)
@ -47,7 +48,7 @@
End Sub
Sub GetTotal(playerToCheck As Object, Optional hide As Boolean = False)
Dim cards As List(Of Tuple(Of String, String)) = playerToCheck.hand
Dim cards As List(Of Card) = playerToCheck.hand
If cards.Count = 0 Then
playerToCheck.total = 0
Return
@ -55,7 +56,7 @@
Dim total = 0
Dim aceTotal = 0
For Each card In cards
Dim num As String = card.Item2
Dim num As String = card.GetNumber()
If num = "K" Or num = "Q" Or num = "J" Then
num = 10
End If

View File

@ -27,14 +27,14 @@
StartGame.Enabled = False
End Sub
Private Sub OnCardDealt(card As Tuple(Of String, String), cardNumber As String, hide As Boolean) _
Private Sub OnCardDealt(card As Card, cardNumber As String, hide As Boolean) _
Handles game.CardDealt
Dim pictureBox As PictureBox
pictureBox = CType(Me.Controls.Find("PlayerCard" + cardNumber, True).First(), PictureBox)
If hide Then
pictureBox.Image = My.Resources.blue
Else
pictureBox.Image = Utilities.GetCardImage(card)
pictureBox.Image = Utilities.GetCardImage(Tuple.create(card.GetSuit(), card.GetNumber()))
End If
End Sub

View File

@ -1,5 +1,5 @@
Public Class Player
Public Property hand As New List(Of Tuple(Of String, String))
Public Property hand As New List(Of Card)
Public Property total As Integer
Public Property ingame As Boolean
Public Property winType As WinCondition

50
card.vb 100644
View File

@ -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() As Integer
Return id
End Function
Public Function GetBoxId() As PictureBox
Return boxId
End Function
Public Function GetName() As Tuple(Of String, String)
Return cardName
End Function
Public Function GetLocation() As Point
Return cardLocation
End Function
Public Function IsHidden() As Boolean
Return cardHidden
End Function
End Class