Change how suit/number is handled in the card class, change the layout of the card tuples.

remotes/origin/master
CrystalMoogle 2023-07-21 21:24:37 +01:00
parent f381a1806e
commit 959b3cd71d
5 changed files with 16 additions and 20 deletions

View File

@ -3,19 +3,15 @@
Private id As Integer Private id As Integer
Private boxId As PictureBox Private boxId As PictureBox
Private cardImage As Image Private cardImage As Image
Private cardName As Tuple(Of String, String) Private card As (suit As String, number As String)
Private cardSuit As String
Private cardNumber as String
Private cardLocation As Point Private cardLocation As Point
Private cardHidden As Boolean Private cardHidden As Boolean
Public Sub New(name As Tuple(Of String, String), Optional hidden As Boolean = False) Public Sub New(name As (String, String), Optional hidden As Boolean = False)
id = idCounter id = idCounter
idCounter += 1 idCounter += 1
boxId = New PictureBox() boxId = New PictureBox()
cardName = name card = name
cardSuit = name.item1
cardNumber = name.item2
cardHidden = hidden cardHidden = hidden
cardImage = Utilities.GetCardImage(name, hidden) cardImage = Utilities.GetCardImage(name, hidden)
End Sub End Sub
@ -24,8 +20,8 @@
cardLocation = location cardLocation = location
End Sub End Sub
Public Sub SetName(name As Tuple(Of String, String)) Public Sub SetName(name As (String, String))
cardName = name card = name
End Sub End Sub
Public Sub SetHidden(hidden As Boolean) Public Sub SetHidden(hidden As Boolean)
@ -41,15 +37,15 @@
End Function End Function
Public Function GetName() Public Function GetName()
Return cardName Return card
End Function End Function
Public Function GetSuit() As String Public Function GetSuit() As String
Return cardSuit Return card.suit
End Function End Function
Public Function GetNumber() As String Public Function GetNumber() As String
Return cardNumber Return card.number
End Function End Function
Public Function GetLocation() Public Function GetLocation()
Return cardLocation Return cardLocation

View File

@ -9,7 +9,7 @@
Private player As Player Private player As Player
Private dealer As Dealer Private dealer As Dealer
Private deck As List(Of Tuple(Of String, String)) Private deck As List(Of (String, String))
Private WithEvents dealerDelay As Timer Private WithEvents dealerDelay As Timer
Public Sub Start() Public Sub Start()
@ -32,7 +32,7 @@
End Sub End Sub
Sub DealCard(playerDealt As Object, Optional hide As Boolean = False) Sub DealCard(playerDealt As Object, Optional hide As Boolean = False)
Dim card As Tuple(Of String, String) = deck(0) Dim card As (String, String) = deck(0)
Dim playingCard = New Card(card, hide) Dim playingCard = New Card(card, hide)
playerDealt.hand.Add(playingCard) playerDealt.hand.Add(playingCard)
deck.RemoveAt(0) deck.RemoveAt(0)
@ -189,13 +189,13 @@
End Select End Select
End Function End Function
Shared Function CreateDeck() As List(Of Tuple(Of String, String)) Shared Function CreateDeck() As List(Of (String,String))
Dim response As New List(Of Tuple(Of String, String)) Dim response As New List(Of (String, String))
Dim nums As String() = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"} Dim nums As String() = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}
Dim suits As String() = {"Hearts", "Diamonds", "Spades", "Clubs"} Dim suits As String() = {"Hearts", "Diamonds", "Spades", "Clubs"}
For Each suit As String In suits For Each suit As String In suits
For Each num As String In nums For Each num As String In nums
response.Add(Tuple.Create(suit, num)) response.Add((suit, num))
Next Next
Next Next
Return Utilities.Shuffle(response) Return Utilities.Shuffle(response)

View File

@ -34,7 +34,7 @@
If hide Then If hide Then
pictureBox.Image = My.Resources.blue pictureBox.Image = My.Resources.blue
Else Else
pictureBox.Image = Utilities.GetCardImage(Tuple.create(card.GetSuit(), card.GetNumber())) pictureBox.Image = Utilities.GetCardImage((card.GetSuit(), card.GetNumber()))
End If End If
End Sub End Sub

View File

@ -16,6 +16,6 @@ Public Class Dealer
Inherits Player Inherits Player
Public Property limit As Integer = 17 Public Property limit As Integer = 17
Public Property hidden As Tuple(Of String, String) Public Property hidden As (String, String)
Public Property trueTotal As Integer Public Property trueTotal As Integer
End Class End Class

View File

@ -11,7 +11,7 @@
Return list Return list
End Function End Function
Public Shared Function GetCardImage(card As Tuple(Of String, String), Optional hidden As Boolean = False) As Image Public Shared Function GetCardImage(card As (String, String), Optional hidden As Boolean = False) As Image
If hidden Then If hidden Then
Return My.Resources.blue Return My.Resources.blue
End If End If