Results 1 to 3 of 3

Thread: loop if statements for a black jack game

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    2

    Question 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")

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    2

    Resolved 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width