loop if statements for a black jack game
I'm using Visual Basic 2008 express edition to design a black jack game and I'm trying to figure out how to loop a set of if states for the money won and lost during the game. I've included what I've come up with so far for the statements, but I'm having trouble figuring out how to properly place them in a do loop and what I should associate them with so that the loop will continue running when the deal button, hit buttons and stand button are pressed but the money will reset if the new game button is pressed. I was considering an association with the moneyLabelBox. Any suggestions would help. Thanks.
Code:
Dim moneyDefault As Integer
Dim moneyAdd As Integer
Dim moneySub As Integer
Dim moneyBJAdd As Integer
Dim moneyDraw As Integer
Dim dealerTotal As Integer
Dim playerTotal As Integer
Integer.TryParse(dealerLabelBox.Text, dealerTotal)
Integer.TryParse(playerLabelBox.Text, playerTotal)
money amounts
moneyDefault = 500
moneyAdd = 10
moneySub = 10
moneyBJAdd = 20
moneyDraw = 5
' if statements
If playerTotal > dealerTotal AndAlso playerTotal < 21 Then
moneyDefault = moneyDefault + moneyAdd
End If
If playerTotal = 21 AndAlso dealerTotal < 22 Then
moneyDefault = moneyDefault + moneyBJAdd
End If
If playerTotal < dealerTotal AndAlso dealerTotal < 22 Then
moneyDefault = moneyDefault - moneySub
End If
If playerTotal = dealerTotal AndAlso playerTotal < 21 Then
moneyDefault = moneyDefault + moneyDraw
End If
' show money amount
moneyLabelBox.Text = moneyDefault.ToString("C2")
Re: loop if statements for a black jack game
I would put them after your hand evaluation routine, which you should be calling after every new card is drawn. I'd also remove the third condition. Subtract their money when the game starts, and if the dealer wins, then there is no change to moneyDefault. When betting, you always subtract the player's money when it hits the table because it's no longer theirs... it's the game's.
Re: loop if statements for a black jack game
After much trial and error, placing a Select Case piece of code inside a function seems to have worked with solving my problem.