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(dealer, isDealer:=True)
 | 
			
		||||
        DealCard(player)
 | 
			
		||||
        DealCard(dealer, isDealer:=True)
 | 
			
		||||
        DealCard(dealer, isDealer:=True, hide:=True)
 | 
			
		||||
        GetTotal(dealer)
 | 
			
		||||
        CheckPlayer(dealer, True)
 | 
			
		||||
        CheckPlayer(player)
 | 
			
		||||
    End Sub
 | 
			
		||||
    Sub CreateDeck()
 | 
			
		||||
| 
						 | 
				
			
			@ -67,24 +69,31 @@
 | 
			
		|||
            deck(rand) = temp
 | 
			
		||||
        Next
 | 
			
		||||
    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)
 | 
			
		||||
        player.hand.Add(card)
 | 
			
		||||
        deck.RemoveAt(0)
 | 
			
		||||
        GetTotal(player)
 | 
			
		||||
        GetTotal(player, hide)
 | 
			
		||||
        Dim cardNumber As String = If(isDealer, (player.hand.count + 5).ToString(), player.hand.count)
 | 
			
		||||
        Dim pictureBox As PictureBox
 | 
			
		||||
        Try
 | 
			
		||||
            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
 | 
			
		||||
            WinMessage.Text = "Error: " + ex.Message
 | 
			
		||||
            EndGame()
 | 
			
		||||
        End Try
 | 
			
		||||
 | 
			
		||||
        pictureBox.Image = GetCardImage(card)
 | 
			
		||||
        SetTotalLabels()
 | 
			
		||||
    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
 | 
			
		||||
        If cards.Count = 0 Then
 | 
			
		||||
            player.total = 0
 | 
			
		||||
| 
						 | 
				
			
			@ -118,29 +127,46 @@
 | 
			
		|||
        PlayerTotal.Text = playerLabelTotal + ": " + player.total.ToString()
 | 
			
		||||
 | 
			
		||||
    End Sub
 | 
			
		||||
    Sub CheckPlayer(player)
 | 
			
		||||
        If player.total = 21 And player.hand.count = 2 Then
 | 
			
		||||
            player.winType = WinCondition.Blackjack
 | 
			
		||||
            player.ingame = False
 | 
			
		||||
            dealer.ingame = False
 | 
			
		||||
            DealerTurn()
 | 
			
		||||
        ElseIf player.total > 21 Then
 | 
			
		||||
            player.winType = WinCondition.Bust
 | 
			
		||||
            player.ingame = False
 | 
			
		||||
            DealerTurn()
 | 
			
		||||
        ElseIf player.total < 22 And player.hand.count = 5 Then
 | 
			
		||||
            player.winType = WinCondition.FiveCard
 | 
			
		||||
            player.ingame = False
 | 
			
		||||
            dealer.ingame = False
 | 
			
		||||
            DealerTurn()
 | 
			
		||||
        End If
 | 
			
		||||
        If player.total = 21 Then
 | 
			
		||||
            player.ingame = False
 | 
			
		||||
            DealerTurn()
 | 
			
		||||
    Sub CheckPlayer(playerToCheck, Optional peek = False)
 | 
			
		||||
        If Not peek Then
 | 
			
		||||
            If playerToCheck.total = 21 And playerToCheck.hand.count = 2 Then
 | 
			
		||||
                playerToCheck.winType = WinCondition.Blackjack
 | 
			
		||||
                playerToCheck.ingame = False
 | 
			
		||||
                dealer.ingame = False
 | 
			
		||||
                DealerTurn()
 | 
			
		||||
            ElseIf playerToCheck.total > 21 Then
 | 
			
		||||
                playerToCheck.winType = WinCondition.Bust
 | 
			
		||||
                playerToCheck.ingame = False
 | 
			
		||||
                DealerTurn()
 | 
			
		||||
            ElseIf playerToCheck.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
 | 
			
		||||
                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 Sub
 | 
			
		||||
    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
 | 
			
		||||
                dealer.winType = WinCondition.Blackjack
 | 
			
		||||
                dealer.ingame = False
 | 
			
		||||
| 
						 | 
				
			
			@ -257,6 +283,7 @@ Public Class Dealer
 | 
			
		|||
    Inherits Player
 | 
			
		||||
 | 
			
		||||
    Public Property limit As Integer = 17
 | 
			
		||||
    Public Property hidden As String
 | 
			
		||||
End Class
 | 
			
		||||
 | 
			
		||||
Enum WinCondition
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue