Condense code a little
parent
d4511f6ffa
commit
73ace5bcca
|
@ -10,7 +10,6 @@
|
||||||
Private deck As List(Of Tuple(Of String, String))
|
Private deck As List(Of Tuple(Of String, String))
|
||||||
|
|
||||||
Public Sub Start()
|
Public Sub Start()
|
||||||
|
|
||||||
Init()
|
Init()
|
||||||
player.Start()
|
player.Start()
|
||||||
dealer.Start()
|
dealer.Start()
|
||||||
|
@ -41,9 +40,6 @@
|
||||||
RaiseEvent SetTotalLabels(player.total, dealer.total)
|
RaiseEvent SetTotalLabels(player.total, dealer.total)
|
||||||
End Sub
|
End Sub
|
||||||
Sub GetTotal(playerToCheck As Object, Optional hide As Boolean = False)
|
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
|
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
|
||||||
|
@ -67,32 +63,38 @@
|
||||||
aceTotal -= 1
|
aceTotal -= 1
|
||||||
total -= 10
|
total -= 10
|
||||||
End While
|
End While
|
||||||
|
If hide Then
|
||||||
|
playerToCheck.trueTotal = total
|
||||||
|
Else
|
||||||
playerToCheck.total = total
|
playerToCheck.total = total
|
||||||
|
End If
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
Sub CheckPlayer(playerToCheck As Object, Optional peek As Boolean = False)
|
Sub CheckPlayer(playerToCheck As Object, Optional peek As Boolean = False)
|
||||||
If playerToCheck.total = 21 And playerToCheck.hand.Count = 2 And peek Then
|
Dim total As Integer = playerToCheck.total
|
||||||
playerToCheck.winType = WinCondition.Blackjack
|
If peek Then
|
||||||
playerToCheck.ingame = False
|
total = playerToCheck.trueTotal
|
||||||
player.ingame = False
|
|
||||||
DealerTurn()
|
|
||||||
Exit Sub
|
|
||||||
End If
|
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.winType = WinCondition.Blackjack
|
||||||
playerToCheck.ingame = False
|
playerToCheck.ingame = False
|
||||||
|
If peek Then
|
||||||
|
player.ingame = False
|
||||||
|
Else
|
||||||
dealer.ingame = False
|
dealer.ingame = False
|
||||||
|
End If
|
||||||
DealerTurn()
|
DealerTurn()
|
||||||
ElseIf playerToCheck.total > 21 Then
|
ElseIf total > 21 Then
|
||||||
playerToCheck.winType = WinCondition.Bust
|
playerToCheck.winType = WinCondition.Bust
|
||||||
playerToCheck.ingame = False
|
playerToCheck.ingame = False
|
||||||
DealerTurn()
|
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.winType = WinCondition.FiveCard
|
||||||
playerToCheck.ingame = False
|
playerToCheck.ingame = False
|
||||||
dealer.ingame = False
|
dealer.ingame = False
|
||||||
DealerTurn()
|
DealerTurn()
|
||||||
End If
|
End If
|
||||||
If playerToCheck.total = 21 Then
|
If total = 21 Then
|
||||||
playerToCheck.ingame = False
|
playerToCheck.ingame = False
|
||||||
DealerTurn()
|
DealerTurn()
|
||||||
End If
|
End If
|
||||||
|
@ -171,7 +173,8 @@
|
||||||
End Function
|
End Function
|
||||||
Function CreateDeck() As List(Of Tuple(Of String, String))
|
Function CreateDeck() As List(Of Tuple(Of String, String))
|
||||||
Dim response As New 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"}
|
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
|
||||||
|
|
|
@ -17,4 +17,5 @@ Public Class Dealer
|
||||||
|
|
||||||
Public Property limit As Integer = 17
|
Public Property limit As Integer = 17
|
||||||
Public Property hidden As Tuple(Of String, String)
|
Public Property hidden As Tuple(Of String, String)
|
||||||
|
Public Property trueTotal As Integer
|
||||||
End Class
|
End Class
|
||||||
|
|
Loading…
Reference in New Issue