From 73ace5bcca5be3280d73fa8184f4bf896321718d Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Sun, 16 Jul 2023 16:07:13 +0100 Subject: [PATCH] Condense code a little --- BlackjackGUI/game.vb | 37 ++++++++++++++++++++----------------- BlackjackGUI/player.vb | 1 + 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/BlackjackGUI/game.vb b/BlackjackGUI/game.vb index 838f276..1e6bcf0 100644 --- a/BlackjackGUI/game.vb +++ b/BlackjackGUI/game.vb @@ -10,7 +10,6 @@ Private deck As List(Of Tuple(Of String, String)) Public Sub Start() - Init() player.Start() dealer.Start() @@ -41,9 +40,6 @@ RaiseEvent SetTotalLabels(player.total, dealer.total) End Sub Sub GetTotal(playerToCheck As Object, Optional hide As Boolean = False) - If hide Then - Exit Sub - End If Dim cards As List(Of Tuple(Of String, String)) = playerToCheck.hand If cards.Count = 0 Then playerToCheck.total = 0 @@ -67,32 +63,38 @@ aceTotal -= 1 total -= 10 End While - playerToCheck.total = total + If hide Then + playerToCheck.trueTotal = total + Else + playerToCheck.total = total + End If + End Sub Sub CheckPlayer(playerToCheck As Object, Optional peek As Boolean = False) - If playerToCheck.total = 21 And playerToCheck.hand.Count = 2 And peek Then - playerToCheck.winType = WinCondition.Blackjack - playerToCheck.ingame = False - player.ingame = False - DealerTurn() - Exit Sub + Dim total As Integer = playerToCheck.total + If peek Then + total = playerToCheck.trueTotal End If - If playerToCheck.total = 21 And playerToCheck.hand.Count = 2 Then + If total = 21 And playerToCheck.hand.Count = 2 Then playerToCheck.winType = WinCondition.Blackjack playerToCheck.ingame = False - dealer.ingame = False + If peek Then + player.ingame = False + Else + dealer.ingame = False + End If DealerTurn() - ElseIf playerToCheck.total > 21 Then + ElseIf total > 21 Then playerToCheck.winType = WinCondition.Bust playerToCheck.ingame = False DealerTurn() - ElseIf playerToCheck.total < 22 And playerToCheck.hand.Count = 5 Then + ElseIf total < 22 And playerToCheck.hand.Count = 5 Then playerToCheck.winType = WinCondition.FiveCard playerToCheck.ingame = False dealer.ingame = False DealerTurn() End If - If playerToCheck.total = 21 Then + If total = 21 Then playerToCheck.ingame = False DealerTurn() End If @@ -171,7 +173,8 @@ End Function 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 nums As String() = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"} + Dim nums As String() = {"A", "10", "K", "Q", "J"} Dim suits As String() = {"Hearts", "Diamonds", "Spades", "Clubs"} For Each suit As String In suits For Each num As String In nums diff --git a/BlackjackGUI/player.vb b/BlackjackGUI/player.vb index 9121f21..e575b93 100644 --- a/BlackjackGUI/player.vb +++ b/BlackjackGUI/player.vb @@ -17,4 +17,5 @@ Public Class Dealer Public Property limit As Integer = 17 Public Property hidden As Tuple(Of String, String) + Public Property trueTotal As Integer End Class