Convert cards to tuple

master
CrystalMoogle 2023-07-16 15:37:10 +01:00
parent ca2dd78e06
commit eb37ba7c41
4 changed files with 18 additions and 18 deletions

View File

@ -22,7 +22,7 @@
StartGame.Enabled = False StartGame.Enabled = False
End Sub End Sub
Private Sub OnCardDealt(card As String, cardNumber As String, hide As Boolean) Handles game.CardDealt Private Sub OnCardDealt(card As Tuple(Of String, String), cardNumber As String, hide As Boolean) Handles game.CardDealt
Dim pictureBox As PictureBox Dim pictureBox As PictureBox
Debug.Print(cardNumber) Debug.Print(cardNumber)
Try Try

View File

@ -4,15 +4,15 @@
Dim random As New Random() Dim random As New Random()
For x As Integer = 0 To max For x As Integer = 0 To max
Dim rand As Integer = random.Next(0, max) Dim rand As Integer = random.Next(0, max)
Dim temp As String = list(x) Dim temp = list(x)
list(x) = list(rand) list(x) = list(rand)
list(rand) = temp list(rand) = temp
Next Next
Return list Return list
End Function End Function
Public Shared Function GetCardImage(card) As Image Public Shared Function GetCardImage(card As Tuple(Of String, String)) As Image
Dim num As String = card.split(" ")(0) Dim suit As String = card.Item1
Dim suit As String = card.split(" ")(2) Dim num As String = card.Item2
Select Case num Select Case num
Case "K" Case "K"
num = "king" num = "king"

View File

@ -7,7 +7,7 @@
Private player As Player Private player As Player
Private dealer As Dealer Private dealer As Dealer
Private deck As New List(Of String) Private deck As List(Of Tuple(Of String, String))
Public Sub Start() Public Sub Start()
@ -28,7 +28,7 @@
RaiseEvent ResetUI() RaiseEvent ResetUI()
End Sub End Sub
Sub DealCard(playerDealt, Optional isDealer = False, Optional hide = False) Sub DealCard(playerDealt, Optional isDealer = False, Optional hide = False)
Dim card As String = deck(0) Dim card As Tuple(Of String, String) = deck(0)
playerDealt.hand.Add(card) playerDealt.hand.Add(card)
deck.RemoveAt(0) deck.RemoveAt(0)
GetTotal(playerDealt, hide) GetTotal(playerDealt, hide)
@ -44,15 +44,15 @@
If hide Then If hide Then
Exit Sub Exit Sub
End If End If
Dim cards As List(Of String) = playerToCheck.hand Dim cards As List(Of Tuple(Of String, String)) = playerToCheck.hand
If cards.Count = 0 Then If cards.Count = 0 Then
playerToCheck.total = 0 playerToCheck.total = 0
Return Return
End If End If
Dim total As Integer = 0 Dim total As Integer = 0
Dim aceTotal As Integer = 0 Dim aceTotal As Integer = 0
For Each card As String In cards For Each card In cards
Dim num As String = card.Split(" "c)(0) Dim num As String = card.Item2
If num = "K" Or num = "Q" Or num = "J" Then If num = "K" Or num = "Q" Or num = "J" Then
num = 10 num = 10
End If End If
@ -169,16 +169,16 @@
End If End If
Return "error" Return "error"
End Function End Function
Function CreateDeck() Function CreateDeck() As List(Of Tuple(Of String, String))
deck.Clear() Dim response As New List(Of Tuple(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 s As String In suits For Each suit As String In suits
For Each n As String In nums For Each num As String In nums
deck.Add(n + " of " + s) response.Add(Tuple.Create(suit, num))
Next Next
Next Next
Return Utilities.Shuffle(deck) Return Utilities.Shuffle(response)
End Function End Function
End Class End Class

View File

@ -1,5 +1,5 @@
Public Class Player Public Class Player
Public Property hand As New List(Of String) Public Property hand As New List(Of Tuple(Of String, String))
Public Property total As Integer Public Property total As Integer
Public Property ingame As Boolean Public Property ingame As Boolean
Public Property winType As WinCondition Public Property winType As WinCondition
@ -16,5 +16,5 @@ Public Class Dealer
Inherits Player Inherits Player
Public Property limit As Integer = 17 Public Property limit As Integer = 17
Public Property hidden As String Public Property hidden As Tuple(Of String, String)
End Class End Class