Condense code a little

master
CrystalMoogle 2023-07-16 16:07:13 +01:00
parent d4511f6ffa
commit 73ace5bcca
2 changed files with 21 additions and 17 deletions

View File

@ -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

View File

@ -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