From eb37ba7c4139ec42f7de5e4338338a5ed9ff3fd5 Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Sun, 16 Jul 2023 15:37:10 +0100 Subject: [PATCH] Convert cards to tuple --- BlackjackGUI/GameWindow.vb | 2 +- BlackjackGUI/Utilities.vb | 8 ++++---- BlackjackGUI/game.vb | 22 +++++++++++----------- BlackjackGUI/player.vb | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/BlackjackGUI/GameWindow.vb b/BlackjackGUI/GameWindow.vb index ebe944a..f6b8d3b 100644 --- a/BlackjackGUI/GameWindow.vb +++ b/BlackjackGUI/GameWindow.vb @@ -22,7 +22,7 @@ StartGame.Enabled = False 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 Debug.Print(cardNumber) Try diff --git a/BlackjackGUI/Utilities.vb b/BlackjackGUI/Utilities.vb index 796ddfc..1240495 100644 --- a/BlackjackGUI/Utilities.vb +++ b/BlackjackGUI/Utilities.vb @@ -4,15 +4,15 @@ Dim random As New Random() For x As Integer = 0 To max Dim rand As Integer = random.Next(0, max) - Dim temp As String = list(x) + Dim temp = list(x) list(x) = list(rand) list(rand) = temp Next Return list End Function - Public Shared Function GetCardImage(card) As Image - Dim num As String = card.split(" ")(0) - Dim suit As String = card.split(" ")(2) + Public Shared Function GetCardImage(card As Tuple(Of String, String)) As Image + Dim suit As String = card.Item1 + Dim num As String = card.Item2 Select Case num Case "K" num = "king" diff --git a/BlackjackGUI/game.vb b/BlackjackGUI/game.vb index 4949fd9..e3e8382 100644 --- a/BlackjackGUI/game.vb +++ b/BlackjackGUI/game.vb @@ -7,7 +7,7 @@ Private player As Player Private dealer As Dealer - Private deck As New List(Of String) + Private deck As List(Of Tuple(Of String, String)) Public Sub Start() @@ -28,7 +28,7 @@ RaiseEvent ResetUI() End Sub 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) deck.RemoveAt(0) GetTotal(playerDealt, hide) @@ -44,15 +44,15 @@ If hide Then Exit Sub 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 playerToCheck.total = 0 Return End If Dim total As Integer = 0 Dim aceTotal As Integer = 0 - For Each card As String In cards - Dim num As String = card.Split(" "c)(0) + For Each card In cards + Dim num As String = card.Item2 If num = "K" Or num = "Q" Or num = "J" Then num = 10 End If @@ -169,16 +169,16 @@ End If Return "error" End Function - Function CreateDeck() - deck.Clear() + Function CreateDeck() As List(Of Tuple(Of String, String)) + 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 suits As String() = {"Hearts", "Diamonds", "Spades", "Clubs"} - For Each s As String In suits - For Each n As String In nums - deck.Add(n + " of " + s) + For Each suit As String In suits + For Each num As String In nums + response.Add(Tuple.Create(suit, num)) Next Next - Return Utilities.Shuffle(deck) + Return Utilities.Shuffle(response) End Function End Class diff --git a/BlackjackGUI/player.vb b/BlackjackGUI/player.vb index afa169d..9121f21 100644 --- a/BlackjackGUI/player.vb +++ b/BlackjackGUI/player.vb @@ -1,5 +1,5 @@ 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 ingame As Boolean Public Property winType As WinCondition @@ -16,5 +16,5 @@ Public Class Dealer Inherits Player Public Property limit As Integer = 17 - Public Property hidden As String + Public Property hidden As Tuple(Of String, String) End Class