Hide second Dealer card/total from Player unless Dealer has Blackjack. Fix possible crash cause for dealer drawing too many cards.
parent
0c5c9e115b
commit
1295bdbc09
|
@ -43,7 +43,9 @@
|
||||||
DealCard(player)
|
DealCard(player)
|
||||||
DealCard(dealer, isDealer:=True)
|
DealCard(dealer, isDealer:=True)
|
||||||
DealCard(player)
|
DealCard(player)
|
||||||
DealCard(dealer, isDealer:=True)
|
DealCard(dealer, isDealer:=True, hide:=True)
|
||||||
|
GetTotal(dealer)
|
||||||
|
CheckPlayer(dealer, True)
|
||||||
CheckPlayer(player)
|
CheckPlayer(player)
|
||||||
End Sub
|
End Sub
|
||||||
Sub CreateDeck()
|
Sub CreateDeck()
|
||||||
|
@ -67,24 +69,31 @@
|
||||||
deck(rand) = temp
|
deck(rand) = temp
|
||||||
Next
|
Next
|
||||||
End Sub
|
End Sub
|
||||||
Sub DealCard(player, Optional suppress = False, Optional isDealer = False)
|
Sub DealCard(player, Optional suppress = False, Optional isDealer = False, Optional hide = False)
|
||||||
Dim card = deck(0)
|
Dim card = deck(0)
|
||||||
player.hand.Add(card)
|
player.hand.Add(card)
|
||||||
deck.RemoveAt(0)
|
deck.RemoveAt(0)
|
||||||
GetTotal(player)
|
GetTotal(player, hide)
|
||||||
Dim cardNumber As String = If(isDealer, (player.hand.count + 5).ToString(), player.hand.count)
|
Dim cardNumber As String = If(isDealer, (player.hand.count + 5).ToString(), player.hand.count)
|
||||||
Dim pictureBox As PictureBox
|
Dim pictureBox As PictureBox
|
||||||
Try
|
Try
|
||||||
pictureBox = CType(Me.Controls.Find("PlayerCard" + cardNumber, True).First(), PictureBox)
|
pictureBox = CType(Me.Controls.Find("PlayerCard" + cardNumber, True).First(), PictureBox)
|
||||||
|
If hide Then
|
||||||
|
pictureBox.Image = My.Resources.blue
|
||||||
|
player.hidden = card
|
||||||
|
Else
|
||||||
|
pictureBox.Image = GetCardImage(card)
|
||||||
|
End If
|
||||||
|
SetTotalLabels()
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
WinMessage.Text = "Error: " + ex.Message
|
WinMessage.Text = "Error: " + ex.Message
|
||||||
EndGame()
|
EndGame()
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
pictureBox.Image = GetCardImage(card)
|
|
||||||
SetTotalLabels()
|
|
||||||
End Sub
|
End Sub
|
||||||
Sub GetTotal(player)
|
Sub GetTotal(player, Optional hide = False)
|
||||||
|
If hide Then
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
Dim cards As List(Of String) = player.hand
|
Dim cards As List(Of String) = player.hand
|
||||||
If cards.Count = 0 Then
|
If cards.Count = 0 Then
|
||||||
player.total = 0
|
player.total = 0
|
||||||
|
@ -118,29 +127,46 @@
|
||||||
PlayerTotal.Text = playerLabelTotal + ": " + player.total.ToString()
|
PlayerTotal.Text = playerLabelTotal + ": " + player.total.ToString()
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
Sub CheckPlayer(player)
|
Sub CheckPlayer(playerToCheck, Optional peek = False)
|
||||||
If player.total = 21 And player.hand.count = 2 Then
|
If Not peek Then
|
||||||
player.winType = WinCondition.Blackjack
|
If playerToCheck.total = 21 And playerToCheck.hand.count = 2 Then
|
||||||
player.ingame = False
|
playerToCheck.winType = WinCondition.Blackjack
|
||||||
dealer.ingame = False
|
playerToCheck.ingame = False
|
||||||
DealerTurn()
|
dealer.ingame = False
|
||||||
ElseIf player.total > 21 Then
|
DealerTurn()
|
||||||
player.winType = WinCondition.Bust
|
ElseIf playerToCheck.total > 21 Then
|
||||||
player.ingame = False
|
playerToCheck.winType = WinCondition.Bust
|
||||||
DealerTurn()
|
playerToCheck.ingame = False
|
||||||
ElseIf player.total < 22 And player.hand.count = 5 Then
|
DealerTurn()
|
||||||
player.winType = WinCondition.FiveCard
|
ElseIf playerToCheck.total < 22 And playerToCheck.hand.count = 5 Then
|
||||||
player.ingame = False
|
playerToCheck.winType = WinCondition.FiveCard
|
||||||
dealer.ingame = False
|
playerToCheck.ingame = False
|
||||||
DealerTurn()
|
dealer.ingame = False
|
||||||
End If
|
DealerTurn()
|
||||||
If player.total = 21 Then
|
End If
|
||||||
player.ingame = False
|
If playerToCheck.total = 21 Then
|
||||||
DealerTurn()
|
playerToCheck.ingame = False
|
||||||
|
DealerTurn()
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
If playerToCheck.total = 21 And playerToCheck.hand.count = 2 Then
|
||||||
|
playerToCheck.winType = WinCondition.Blackjack
|
||||||
|
playerToCheck.ingame = False
|
||||||
|
player.ingame = False
|
||||||
|
DealerTurn()
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
Sub DealerTurn()
|
Sub DealerTurn()
|
||||||
If dealer.ingame Then
|
PlayerCard7.Image = GetCardImage(dealer.hidden)
|
||||||
|
GetTotal(dealer)
|
||||||
|
SetTotalLabels()
|
||||||
|
If player.winType = WinCondition.Bust Then
|
||||||
|
CheckGame()
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
If dealer.ingame And dealer.hand.Count < 5 Then
|
||||||
If dealer.total = 21 And dealer.hand.Count = 2 Then
|
If dealer.total = 21 And dealer.hand.Count = 2 Then
|
||||||
dealer.winType = WinCondition.Blackjack
|
dealer.winType = WinCondition.Blackjack
|
||||||
dealer.ingame = False
|
dealer.ingame = False
|
||||||
|
@ -257,6 +283,7 @@ Public Class Dealer
|
||||||
Inherits Player
|
Inherits Player
|
||||||
|
|
||||||
Public Property limit As Integer = 17
|
Public Property limit As Integer = 17
|
||||||
|
Public Property hidden As String
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
Enum WinCondition
|
Enum WinCondition
|
||||||
|
|
Loading…
Reference in New Issue