Results 1 to 17 of 17

Thread: More Blackjack card game trouble. Help??

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    More Blackjack card game trouble. Help??

    soo..... problems:
    -some of the cards won't flip (this appears to be random)
    -BIG issue working out how to get the program to always use all three cards for computer even when user ends with just two.

    i know its messy, and still a long way from finished, but id REALLLYY appreciate some feedback

    thx!

    Code:
    Public Class Form2
    
        Dim com1 As Integer     'computers three random cards
        Dim com2 As Integer     'will be used in case select for card pix
        Dim com3 As Integer
    
        Dim play1 As Integer    'players three random cards
        Dim play2 As Integer
        Dim play3 As Integer
    
        Dim ace1 As Integer = 1 'lets player choose ace val
        Dim ace2 As Integer = 11
    
        Dim playScore As Integer = 0    'players total score
        Dim comScore As Integer = 0    'coms total score
    
        Const MIN As Integer = 1
        Const MAX As Integer = 13
    
        Dim turn As Integer = 0
        Const SCORE As Integer = 21   'goal (equal or under)
    
    
        Private Sub frm21_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Randomize() 'randomize card values
            com1 = Int((MAX - MIN + 1) * Rnd() * MIN)
            com2 = Int((MAX - MIN + 1) * Rnd() * MIN)
            com3 = Int((MAX - MIN + 1) * Rnd() * MIN)
    
            play1 = Int((MAX - MIN + 1) * Rnd() * MIN)
            play2 = Int((MAX - MIN + 1) * Rnd() * MIN)
    
            Select Case turn
                Case 2
                    play3 = 0
                    imgCard6.Visible = False
                Case 3
                    play3 = Int((MAX - MIN + 1) * Rnd() * MIN)
                    imgCard6.Visible = True
            End Select
    
            btnAgain.Visible = False
            btnAgain.Enabled = False
            btnDraw.Visible = True
            btnDraw.Enabled = True
            btnCheck.Visible = False
            btnCheck.Enabled = False
    
        End Sub
    
        Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
    
            turn += 1
    
            Select Case turn
                Case 1
                    lblComDeal.Visible = True
                    imgCard1.Visible = True
                    lblPlayDeal.Visible = True
                    imgCard4.Visible = True
                Case 2
                    imgCard1.Visible = True
                    imgCard4.Visible = True
    
                    imgCard2.Visible = True
                    imgCard5.Visible = True
    
                    lblChoose.Visible = True
                    btnCheck.Enabled = True
                    btnCheck.Visible = True
                Case 3
                    imgCard1.Visible = True
                    imgCard4.Visible = True
    
                    imgCard2.Visible = True
                    imgCard5.Visible = True
    
                    imgCard3.Visible = True
                    imgCard6.Visible = True
    
                    lblChoose.Visible = False
                    btnDraw.Enabled = False
    
            End Select
    
        End Sub
    
        Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
    
            lblChoose.Visible = False
    
            Select Case turn
                Case 2
                    Select Case com1
                        Case 1
                            If Form1.cmbAce.Text = "Play with ace as one" Then
                                comScore += 1
                            ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
                                comScore += 11
                            End If
                            imgCard1.Image = Blackjack_Fix.My.Resources.sa
                        Case 2
                            imgCard1.Image = Blackjack_Fix.My.Resources.d_2
                            comScore += 2
                        Case 3
                            imgCard1.Image = Blackjack_Fix.My.Resources.club_3
                            comScore += 3
                        Case 4
                            imgCard1.Image = Blackjack_Fix.My.Resources.h4
                            comScore += 4
                        Case 5
                            imgCard1.Image = Blackjack_Fix.My.Resources.s5
                            comScore += 5
                        Case 6
                            imgCard1.Image = Blackjack_Fix.My.Resources.d_6
                            comScore += 6
                        Case 7
                            imgCard1.Image = Blackjack_Fix.My.Resources.club_7
                            comScore += 7
                        Case 8
                            imgCard1.Image = Blackjack_Fix.My.Resources.h8
                            comScore += 8
                        Case 9
                            imgCard1.Image = Blackjack_Fix.My.Resources.s9
                            comScore += 9
                        Case 10
                            imgCard1.Image = Blackjack_Fix.My.Resources.d_10
                            comScore += 10
                        Case 11
                            imgCard1.Image = Blackjack_Fix.My.Resources.jackdiamond
                            comScore += 11
                        Case 12
                            imgCard1.Image = Blackjack_Fix.My.Resources.queenheart
                            comScore += 12
                        Case 13
                            imgCard1.Image = Blackjack_Fix.My.Resources.kingheart
                            comScore += 13
                    End Select
    
                    Select Case com2
                        Case 1
                            If Form1.cmbAce.Text = "Play with ace as one" Then
                                comScore += 1
                            ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
                                comScore += 11
                            End If
                            imgCard2.Image = Blackjack_Fix.My.Resources.sa
                        Case 2
                            imgCard2.Image = Blackjack_Fix.My.Resources.d_2
                            comScore += 2
                        Case 3
                            imgCard2.Image = Blackjack_Fix.My.Resources.club_3
                            comScore += 3
                        Case 4
                            imgCard2.Image = Blackjack_Fix.My.Resources.h4
                            comScore += 4
                        Case 5
                            imgCard2.Image = Blackjack_Fix.My.Resources.s5
                            comScore += 5
                        Case 6
                            imgCard2.Image = Blackjack_Fix.My.Resources.d_6
                            comScore += 6
                        Case 7
                            imgCard2.Image = Blackjack_Fix.My.Resources.club_7
                            comScore += 7
                        Case 8
                            imgCard2.Image = Blackjack_Fix.My.Resources.h8
                            comScore += 8
                        Case 9
                            imgCard2.Image = Blackjack_Fix.My.Resources.s9
                            comScore += 9
                        Case 10
                            imgCard2.Image = Blackjack_Fix.My.Resources.d_10
                            comScore += 10
                        Case 11
                            imgCard2.Image = Blackjack_Fix.My.Resources.jackdiamond
                            comScore += 11
                        Case 12
                            imgCard2.Image = Blackjack_Fix.My.Resources.queenheart
                            comScore += 12
                        Case 13
                            imgCard2.Image = Blackjack_Fix.My.Resources.kingheart
                            comScore += 13
                    End Select
    
                    Select Case com3
                        Case 1
                            If Form1.cmbAce.Text = "Play with ace as one" Then
                                comScore += 1
                            ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
                                comScore += 11
                            End If
                            imgCard3.Image = Blackjack_Fix.My.Resources.sa
                        Case 2
                            imgCard3.Image = Blackjack_Fix.My.Resources.d_2
                            comScore += 2
                        Case 3
                            imgCard3.Image = Blackjack_Fix.My.Resources.club_3
                            comScore += 3
                        Case 4
                            imgCard3.Image = Blackjack_Fix.My.Resources.h4
                            comScore += 4
                        Case 5
                            imgCard3.Image = Blackjack_Fix.My.Resources.s5
                            comScore += 5
                        Case 6
                            imgCard3.Image = Blackjack_Fix.My.Resources.d_6
                            comScore += 6
                        Case 7
                            imgCard3.Image = Blackjack_Fix.My.Resources.club_7
                            comScore += 7
                        Case 8
                            imgCard3.Image = Blackjack_Fix.My.Resources.h8
                            comScore += 8
                        Case 9
                            imgCard3.Image = Blackjack_Fix.My.Resources.s9
                            comScore += 9
                        Case 10
                            imgCard3.Image = Blackjack_Fix.My.Resources.d_10
                            comScore += 10
                        Case 11
                            imgCard3.Image = Blackjack_Fix.My.Resources.jackdiamond
                            comScore += 11
                        Case 12
                            imgCard3.Image = Blackjack_Fix.My.Resources.queenheart
                            comScore += 12
                        Case 13
                            imgCard3.Image = Blackjack_Fix.My.Resources.kingheart
                            comScore += 13
                    End Select
    
                    comScore = com1 + com2 + com3

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    Re: More Blackjack card game trouble. Help??

    part 2 of code (its too long T.T)
    vb Code:
    1. Select Case play1
    2.                     Case 1
    3.                         If Form1.cmbAce.Text = "Play with ace as one" Then
    4.                             playScore += 1
    5.                         ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
    6.                             playScore += 11
    7.                         End If
    8.                         imgCard4.Image = Blackjack_Fix.My.Resources.sa
    9.                     Case 2
    10.                         imgCard4.Image = Blackjack_Fix.My.Resources.d_2
    11.                         playScore += 2
    12.                     Case 3
    13.                         imgCard4.Image = Blackjack_Fix.My.Resources.club_3
    14.                         playScore += 3
    15.                     Case 4
    16.                         imgCard4.Image = Blackjack_Fix.My.Resources.h4
    17.                         playScore += 4
    18.                     Case 5
    19.                         imgCard4.Image = Blackjack_Fix.My.Resources.s5
    20.                         playScore += 5
    21.                     Case 6
    22.                         imgCard4.Image = Blackjack_Fix.My.Resources.d_6
    23.                         playScore += 6
    24.                     Case 7
    25.                         imgCard4.Image = Blackjack_Fix.My.Resources.club_7
    26.                         playScore += 7
    27.                     Case 8
    28.                         imgCard4.Image = Blackjack_Fix.My.Resources.h8
    29.                         playScore += 8
    30.                     Case 9
    31.                         imgCard4.Image = Blackjack_Fix.My.Resources.s9
    32.                         playScore += 9
    33.                     Case 10
    34.                         imgCard4.Image = Blackjack_Fix.My.Resources.d_10
    35.                         playScore += 10
    36.                     Case 11
    37.                         imgCard4.Image = Blackjack_Fix.My.Resources.jackdiamond
    38.                         playScore += 11
    39.                     Case 12
    40.                         imgCard4.Image = Blackjack_Fix.My.Resources.queenheart
    41.                         playScore += 12
    42.                     Case 13
    43.                         imgCard4.Image = Blackjack_Fix.My.Resources.kingheart
    44.                         playScore += 13
    45.                 End Select
    46.  
    47.                 Select Case play2
    48.                     Case 1
    49.                         If Form1.cmbAce.Text = "Play with ace as one" Then
    50.                             playScore += 1
    51.                         ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
    52.                             playScore += 11
    53.                         End If
    54.                         imgCard5.Image = Blackjack_Fix.My.Resources.sa
    55.                     Case 2
    56.                         imgCard5.Image = Blackjack_Fix.My.Resources.d_2
    57.                         playScore += 2
    58.                     Case 3
    59.                         imgCard5.Image = Blackjack_Fix.My.Resources.club_3
    60.                         playScore += 3
    61.                     Case 4
    62.                         imgCard5.Image = Blackjack_Fix.My.Resources.h4
    63.                         playScore += 4
    64.                     Case 5
    65.                         imgCard5.Image = Blackjack_Fix.My.Resources.s5
    66.                         playScore += 5
    67.                     Case 6
    68.                         imgCard5.Image = Blackjack_Fix.My.Resources.d_6
    69.                         playScore += 6
    70.                     Case 7
    71.                         imgCard5.Image = Blackjack_Fix.My.Resources.club_7
    72.                         playScore += 7
    73.                     Case 8
    74.                         imgCard5.Image = Blackjack_Fix.My.Resources.h8
    75.                         playScore += 8
    76.                     Case 9
    77.                         imgCard5.Image = Blackjack_Fix.My.Resources.s9
    78.                         playScore += 9
    79.                     Case 10
    80.                         imgCard5.Image = Blackjack_Fix.My.Resources.d_10
    81.                         playScore += 10
    82.                     Case 11
    83.                         imgCard5.Image = Blackjack_Fix.My.Resources.jackdiamond
    84.                         playScore += 11
    85.                     Case 12
    86.                         imgCard5.Image = Blackjack_Fix.My.Resources.queenheart
    87.                         playScore += 12
    88.                     Case 13
    89.                         imgCard5.Image = Blackjack_Fix.My.Resources.kingheart
    90.                         playScore += 13
    91.                 End Select
    92.  
    93.                 playScore = play1 + play2
    94.  
    95.             Case 3
    96.                 'computers cards
    97.                 Select Case com1
    98.                     Case 1
    99.                         If Form1.cmbAce.Text = "Play with ace as one" Then
    100.                             comScore += 1
    101.                         ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
    102.                             comScore += 11
    103.                         End If
    104.                         imgCard1.Image = Blackjack_Fix.My.Resources.sa
    105.                     Case 2
    106.                         imgCard1.Image = Blackjack_Fix.My.Resources.d_2
    107.                         comScore += 2
    108.                     Case 3
    109.                         imgCard1.Image = Blackjack_Fix.My.Resources.club_3
    110.                         comScore += 3
    111.                     Case 4
    112.                         imgCard1.Image = Blackjack_Fix.My.Resources.h4
    113.                         comScore += 4
    114.                     Case 5
    115.                         imgCard1.Image = Blackjack_Fix.My.Resources.s5
    116.                         comScore += 5
    117.                     Case 6
    118.                         imgCard1.Image = Blackjack_Fix.My.Resources.d_6
    119.                         comScore += 6
    120.                     Case 7
    121.                         imgCard1.Image = Blackjack_Fix.My.Resources.club_7
    122.                         comScore += 7
    123.                     Case 8
    124.                         imgCard1.Image = Blackjack_Fix.My.Resources.h8
    125.                         comScore += 8
    126.                     Case 9
    127.                         imgCard1.Image = Blackjack_Fix.My.Resources.s9
    128.                         comScore += 9
    129.                     Case 10
    130.                         imgCard1.Image = Blackjack_Fix.My.Resources.d_10
    131.                         comScore += 10
    132.                     Case 11
    133.                         imgCard1.Image = Blackjack_Fix.My.Resources.jackdiamond
    134.                         comScore += 11
    135.                     Case 12
    136.                         imgCard1.Image = Blackjack_Fix.My.Resources.queenheart
    137.                         comScore += 12
    138.                     Case 13
    139.                         imgCard1.Image = Blackjack_Fix.My.Resources.kingheart
    140.                         comScore += 13
    141.                 End Select
    142.  
    143.                 Select Case com2
    144.                     Case 1
    145.                         If Form1.cmbAce.Text = "Play with ace as one" Then
    146.                             comScore += 1
    147.                         ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
    148.                             comScore += 11
    149.                         End If
    150.                         imgCard2.Image = Blackjack_Fix.My.Resources.sa
    151.                     Case 2
    152.                         imgCard2.Image = Blackjack_Fix.My.Resources.d_2
    153.                         comScore += 2
    154.                     Case 3
    155.                         imgCard2.Image = Blackjack_Fix.My.Resources.club_3
    156.                         comScore += 3
    157.                     Case 4
    158.                         imgCard2.Image = Blackjack_Fix.My.Resources.h4
    159.                         comScore += 4
    160.                     Case 5
    161.                         imgCard2.Image = Blackjack_Fix.My.Resources.s5
    162.                         comScore += 5
    163.                     Case 6
    164.                         imgCard2.Image = Blackjack_Fix.My.Resources.d_6
    165.                         comScore += 6
    166.                     Case 7
    167.                         imgCard2.Image = Blackjack_Fix.My.Resources.club_7
    168.                         comScore += 7
    169.                     Case 8
    170.                         imgCard2.Image = Blackjack_Fix.My.Resources.h8
    171.                         comScore += 8
    172.                     Case 9
    173.                         imgCard2.Image = Blackjack_Fix.My.Resources.s9
    174.                         comScore += 9
    175.                     Case 10
    176.                         imgCard2.Image = Blackjack_Fix.My.Resources.d_10
    177.                         comScore += 10
    178.                     Case 11
    179.                         imgCard2.Image = Blackjack_Fix.My.Resources.jackdiamond
    180.                         comScore += 11
    181.                     Case 12
    182.                         imgCard2.Image = Blackjack_Fix.My.Resources.queenheart
    183.                         comScore += 12
    184.                     Case 13
    185.                         imgCard2.Image = Blackjack_Fix.My.Resources.kingheart
    186.                         comScore += 13
    187.                 End Select

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    Re: More Blackjack card game trouble. Help??

    vb Code:
    1. Select Case com3
    2.                     Case 1
    3.                         If Form1.cmbAce.Text = "Play with ace as one" Then
    4.                             comScore += 1
    5.                         ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
    6.                             comScore += 11
    7.                         End If 
    8.                         imgCard3.Image = Blackjack_Fix.My.Resources.sa
    9.                     Case 2
    10.                         imgCard3.Image = Blackjack_Fix.My.Resources.d_2
    11.                         comScore += 2
    12.                     Case 3
    13.                         imgCard3.Image = Blackjack_Fix.My.Resources.club_3
    14.                         comScore += 3
    15.                     Case 4
    16.                         imgCard3.Image = Blackjack_Fix.My.Resources.h4
    17.                         comScore += 4
    18.                     Case 5
    19.                         imgCard3.Image = Blackjack_Fix.My.Resources.s5
    20.                         comScore += 5
    21.                     Case 6
    22.                         imgCard3.Image = Blackjack_Fix.My.Resources.d_6
    23.                         comScore += 6
    24.                     Case 7
    25.                         imgCard3.Image = Blackjack_Fix.My.Resources.club_7
    26.                         comScore += 7
    27.                     Case 8
    28.                         imgCard3.Image = Blackjack_Fix.My.Resources.h8
    29.                         comScore += 8
    30.                     Case 9
    31.                         imgCard3.Image = Blackjack_Fix.My.Resources.s9
    32.                         comScore += 9
    33.                     Case 10
    34.                         imgCard3.Image = Blackjack_Fix.My.Resources.d_10
    35.                         comScore += 10
    36.                     Case 11
    37.                         imgCard3.Image = Blackjack_Fix.My.Resources.jackdiamond
    38.                         comScore += 11
    39.                     Case 12
    40.                         imgCard3.Image = Blackjack_Fix.My.Resources.queenheart
    41.                         comScore += 12
    42.                     Case 13
    43.                         imgCard3.Image = Blackjack_Fix.My.Resources.kingheart
    44.                         comScore += 13
    45.                 End Select
    46.  
    47.                 comScore = com1 + com2 + com3
    48. Select Case play1
    49.                     Case 1
    50.                         If Form1.cmbAce.Text = "Play with ace as one" Then
    51.                             playScore += 1
    52.                         ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
    53.                             playScore += 11
    54.                         End If
    55.                         imgCard4.Image = Blackjack_Fix.My.Resources.sa
    56.                     Case 2
    57.                         imgCard4.Image = Blackjack_Fix.My.Resources.d_2
    58.                         playScore += 2
    59.                     Case 3
    60.                         imgCard4.Image = Blackjack_Fix.My.Resources.club_3
    61.                         playScore += 3
    62.                     Case 4
    63.                         imgCard4.Image = Blackjack_Fix.My.Resources.h4
    64.                         playScore += 4
    65.                     Case 5
    66.                         imgCard4.Image = Blackjack_Fix.My.Resources.s5
    67.                         playScore += 5
    68.                     Case 6
    69.                         imgCard4.Image = Blackjack_Fix.My.Resources.d_6
    70.                         playScore += 6
    71.                     Case 7
    72.                         imgCard4.Image = Blackjack_Fix.My.Resources.club_7
    73.                         playScore += 7
    74.                     Case 8
    75.                         imgCard4.Image = Blackjack_Fix.My.Resources.h8
    76.                         playScore += 8
    77.                     Case 9
    78.                         imgCard4.Image = Blackjack_Fix.My.Resources.s9
    79.                         playScore += 9
    80.                     Case 10
    81.                         imgCard4.Image = Blackjack_Fix.My.Resources.d_10
    82.                         playScore += 10
    83.                     Case 11
    84.                         imgCard4.Image = Blackjack_Fix.My.Resources.jackdiamond
    85.                         playScore += 11
    86.                     Case 12
    87.                         imgCard4.Image = Blackjack_Fix.My.Resources.queenheart
    88.                         playScore += 12
    89.                     Case 13
    90.                         imgCard4.Image = Blackjack_Fix.My.Resources.kingheart
    91.                         playScore += 13
    92.                 End Select
    93.  
    94.                 Select Case play2
    95.                     Case 1
    96.                         If Form1.cmbAce.Text = "Play with ace as one" Then
    97.                             playScore += 1
    98.                         ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
    99.                             playScore += 11
    100.                         End If
    101.                         imgCard5.Image = Blackjack_Fix.My.Resources.sa
    102.                     Case 2
    103.                         imgCard5.Image = Blackjack_Fix.My.Resources.d_2
    104.                         playScore += 2
    105.                     Case 3
    106.                         imgCard5.Image = Blackjack_Fix.My.Resources.club_3
    107.                         playScore += 3
    108.                     Case 4
    109.                         imgCard5.Image = Blackjack_Fix.My.Resources.h4
    110.                         playScore += 4
    111.                     Case 5
    112.                         imgCard5.Image = Blackjack_Fix.My.Resources.s5
    113.                         playScore += 5
    114.                     Case 6
    115.                         imgCard5.Image = Blackjack_Fix.My.Resources.d_6
    116.                         playScore += 6
    117.                     Case 7
    118.                         imgCard5.Image = Blackjack_Fix.My.Resources.club_7
    119.                         playScore += 7
    120.                     Case 8
    121.                         imgCard5.Image = Blackjack_Fix.My.Resources.h8
    122.                         playScore += 8
    123.                     Case 9
    124.                         imgCard5.Image = Blackjack_Fix.My.Resources.s9
    125.                         playScore += 9
    126.                     Case 10
    127.                         imgCard5.Image = Blackjack_Fix.My.Resources.d_10
    128.                         playScore += 10
    129.                     Case 11
    130.                         imgCard5.Image = Blackjack_Fix.My.Resources.jackdiamond
    131.                         playScore += 11
    132.                     Case 12
    133.                         imgCard5.Image = Blackjack_Fix.My.Resources.queenheart
    134.                         playScore += 12
    135.                     Case 13
    136.                         imgCard5.Image = Blackjack_Fix.My.Resources.kingheart
    137.                         playScore += 13
    138.                 End Select
    139.  
    140.                 Select Case play3
    141.                     Case 1
    142.                         If Form1.cmbAce.Text = "Play with ace as one" Then
    143.                             playScore += 1
    144.                         ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
    145.                             playScore += 11
    146.                         End If
    147.                         imgCard6.Image = Blackjack_Fix.My.Resources.sa
    148.                     Case 2
    149.                         imgCard6.Image = Blackjack_Fix.My.Resources.d_2
    150.                         playScore += 2
    151.                     Case 3
    152.                         imgCard6.Image = Blackjack_Fix.My.Resources.club_3
    153.                         playScore += 3
    154.                     Case 4
    155.                         imgCard6.Image = Blackjack_Fix.My.Resources.h4
    156.                         playScore += 4
    157.                     Case 5
    158.                         imgCard6.Image = Blackjack_Fix.My.Resources.s5
    159.                         playScore += 5
    160.                     Case 6
    161.                         imgCard6.Image = Blackjack_Fix.My.Resources.d_6
    162.                         playScore += 6
    163.                     Case 7
    164.                         imgCard6.Image = Blackjack_Fix.My.Resources.club_7
    165.                         playScore += 7
    166.                     Case 8
    167.                         imgCard6.Image = Blackjack_Fix.My.Resources.h8
    168.                         playScore += 8
    169.                     Case 9
    170.                         imgCard6.Image = Blackjack_Fix.My.Resources.s9
    171.                         playScore += 9
    172.                     Case 10
    173.                         imgCard6.Image = Blackjack_Fix.My.Resources.d_10
    174.                         playScore += 10
    175.                     Case 11
    176.                         imgCard6.Image = Blackjack_Fix.My.Resources.jackdiamond
    177.                         playScore += 11
    178.                     Case 12
    179.                         imgCard6.Image = Blackjack_Fix.My.Resources.queenheart
    180.                         playScore += 12
    181.                     Case 13
    182.                         imgCard6.Image = Blackjack_Fix.My.Resources.kingheart
    183.                         playScore += 13
    184.                 End Select
    185.  
    186.                 playScore = play1 + play2 + play3
    Last edited by si_the_geek; Mar 28th, 2011 at 01:12 PM. Reason: corrected tags

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,433

    Re: More Blackjack card game trouble. Help??

    There is an awful lot of unnecessary code there...

    The first part is Select Case turn in frm21_Load , because at that point the value of turn will be 0, so none of the cases will run.


    The much bigger part is the code in btnCheck_Click, which repeats what is essentially the same block of code. If you create a sub/function that contains the part that gets repeated (and pass parameters as apt), all of your code would have fit in one post.

    The sub could be like this (I'm not sure "as Image" is correct):
    Code:
    Private Function AddScore(p_Card as Integer, p_Image as Image) as Integer
      Select Case p_Card
          Case 1
              p_Image = Blackjack_Fix.My.Resources.sa
              If Form1.cmbAce.Text = "Play with ace as one" Then
                  Return 1
              ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
                  Return 11
              End If
          Case 2
              p_Image = Blackjack_Fix.My.Resources.d_2
              Return 2
          Case 3
              p_Image = Blackjack_Fix.My.Resources.club_3
              Return 3
          Case 4
              p_Image = Blackjack_Fix.My.Resources.h4
              Return 4
          Case 5
              p_Image = Blackjack_Fix.My.Resources.s5
              Return 5
          Case 6
              p_Image = Blackjack_Fix.My.Resources.d_6
              Return 6
          Case 7
              p_Image = Blackjack_Fix.My.Resources.club_7
              Return 7
          Case 8
              p_Image = Blackjack_Fix.My.Resources.h8
              Return 8
          Case 9
              p_Image = Blackjack_Fix.My.Resources.s9
              Return 9
          Case 10
              p_Image = Blackjack_Fix.My.Resources.d_10
              Return 10
          Case 11
              p_Image = Blackjack_Fix.My.Resources.jackdiamond
              Return 11
          Case 12
              p_Image = Blackjack_Fix.My.Resources.queenheart
              Return 12
          Case 13
              p_Image = Blackjack_Fix.My.Resources.kingheart
              Return 13
      End Select
    End Function
    Then you can replace the "Select Case com1/com2/com3" blocks with this:
    Code:
    comScore += AddScore(com1, imgCard1.Image)
    comScore += AddScore(com2, imgCard2.Image)
    comScore += AddScore(com3, imgCard3.Image)
    ...and similar for the rest of the code in that routine.


    Once you have made those changes, it should be much easier to work out what is going wrong.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    Re: More Blackjack card game trouble. Help??

    thanks si that was a huge help I've been working on getting the computer to always draw three cards even when the player ends with only 2. im thinking 2 different counters- one for com and one for player. your edits were a huge help but now i cant seem to get the images of the cards to show up. any ideas?

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,433

    Re: More Blackjack card game trouble. Help??

    Nothing springs to mind... so it is probably best to show your current code.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    Re: More Blackjack card game trouble. Help??

    ive included a picture of the form after clicking check scores. the pictures of the card backs should have changed to show the value
    vb.net Code:
    1. Public Class Form2
    2.  
    3.    
    4.     Dim com1 As Integer    
    5.     Dim com2 As Integer    
    6.     Dim com3 As Integer
    7.  
    8.     Dim play1 As Integer    
    9.     Dim play2 As Integer
    10.     Dim play3 As Integer
    11.  
    12.     Dim ace1 As Integer = 1 'lets player choose ace val
    13.     Dim ace2 As Integer = 11
    14.  
    15.     Dim playScore As Integer = 0    
    16.     Dim comScore As Integer = 0    
    17.  
    18.     Const MIN As Integer = 1
    19.     Const MAX As Integer = 13
    20.  
    21.     Dim playTurn As Integer = 0
    22.     Dim comTurn As Integer = 0
    23.  
    24.     Const SCORE As Integer = 21   'goal (equal or under)
    25.  
    26.  
    27.     Private Sub frm21_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    28.  
    29.         Randomize() 'randomize card values
    30.         com1 = Int((MAX - MIN + 1) * Rnd() * MIN)
    31.         com2 = Int((MAX - MIN + 1) * Rnd() * MIN)
    32.         com3 = Int((MAX - MIN + 1) * Rnd() * MIN)
    33.  
    34.         play1 = Int((MAX - MIN + 1) * Rnd() * MIN)
    35.         play2 = Int((MAX - MIN + 1) * Rnd() * MIN)
    36.         play3 = Int((MAX - MIN + 1) * Rnd() * MIN)
    37.  
    38.         btnAgain.Visible = False
    39.         btnAgain.Enabled = False
    40.         btnDraw.Visible = True
    41.         btnDraw.Enabled = True
    42.         btnCheck.Visible = False
    43.         btnCheck.Enabled = False
    44.  
    45.     End Sub
    46.  
    47.     Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
    48.  
    49.         playTurn += 1
    50.         comTurn += 1
    51.  
    52.         Select Case comTurn
    53.             Case 1
    54.                 lblPlayDeal.Visible = True
    55.                 imgCard1.Visible = True
    56.             Case 2
    57.                 imgCard1.Visible = True
    58.                 imgCard2.Visible = True
    59.  
    60.                 lblChoose.Visible = True
    61.                 btnCheck.Enabled = True
    62.                 btnCheck.Visible = True
    63.             Case 3
    64.                 imgCard1.Visible = True
    65.                 imgCard2.Visible = True
    66.                 imgCard3.Visible = True
    67.  
    68.                 lblChoose.Visible = False
    69.                 btnDraw.Enabled = False
    70.  
    71.         End Select
    72.  
    73.         Select Case playTurn
    74.             Case 1
    75.                 lblPlayDeal.Visible = True
    76.                 imgCard4.Visible = True
    77.             Case 2
    78.                 imgCard4.Visible = True
    79.                 imgCard5.Visible = True
    80.  
    81.                 lblChoose.Visible = True
    82.                 btnCheck.Enabled = True
    83.                 btnCheck.Visible = True
    84.             Case 3
    85.                 imgCard4.Visible = True
    86.                 imgCard5.Visible = True
    87.                 imgCard6.Visible = True
    88.  
    89.                 lblChoose.Visible = False
    90.                 btnDraw.Enabled = False
    91.  
    92.         End Select
    93.  
    94.     End Sub
    95.  
    96.     Private Function AddScore(ByVal p_Card As Integer, ByVal p_Image As Image) As Integer
    97.         Select Case p_Card
    98.             Case 1
    99.                 p_Image = Blackjack_Fix.My.Resources.sa
    100.                 If Form1.cmbAce.Text = "Play with ace as one" Then
    101.                     Return 1
    102.                 ElseIf Form1.cmbAce.Text = "Play with ace as eleven" Then
    103.                     Return 11
    104.                 End If
    105.             Case 2
    106.                 p_Image = Blackjack_Fix.My.Resources.d_2
    107.                 Return 2
    108.             Case 3
    109.                 p_Image = Blackjack_Fix.My.Resources.club_3
    110.                 Return 3
    111.             Case 4
    112.                 p_Image = Blackjack_Fix.My.Resources.h4
    113.                 Return 4
    114.             Case 5
    115.                 p_Image = Blackjack_Fix.My.Resources.s5
    116.                 Return 5
    117.             Case 6
    118.                 p_Image = Blackjack_Fix.My.Resources.d_6
    119.                 Return 6
    120.             Case 7
    121.                 p_Image = Blackjack_Fix.My.Resources.club_7
    122.                 Return 7
    123.             Case 8
    124.                 p_Image = Blackjack_Fix.My.Resources.h8
    125.                 Return 8
    126.             Case 9
    127.                 p_Image = Blackjack_Fix.My.Resources.s9
    128.                 Return 9
    129.             Case 10
    130.                 p_Image = Blackjack_Fix.My.Resources.d_10
    131.                 Return 10
    132.             Case 11
    133.                 p_Image = Blackjack_Fix.My.Resources.jackdiamond
    134.                 Return 11
    135.             Case 12
    136.                 p_Image = Blackjack_Fix.My.Resources.queenheart
    137.                 Return 12
    138.             Case 13
    139.                 p_Image = Blackjack_Fix.My.Resources.kingheart
    140.                 Return 13
    141.         End Select
    142.     End Function
    143.  
    144.     Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
    145.  
    146.         lblChoose.Visible = False
    147.  
    148.         Select Case playTurn
    149.             Case 2
    150.                 playScore += AddScore(play1, imgCard4.Image)
    151.                 playScore += AddScore(play2, imgCard5.Image)
    152.                
    153.                 imgCard6.Visible = False
    154.             Case 3
    155.                 playScore += AddScore(play1, imgCard4.Image)
    156.                 playScore += AddScore(play2, imgCard5.Image)
    157.                 playScore += AddScore(play3, imgCard6.Image)
    158.  
    159.         End Select
    160.         comScore += AddScore(com1, imgCard1.Image)
    161.         comScore += AddScore(com2, imgCard2.Image)
    162.         comScore += AddScore(com3, imgCard3.Image)
    163.         comScore += AddScore(com1, imgCard1.Image)
    164.         comScore += AddScore(com2, imgCard2.Image)
    165.         comScore += AddScore(com3, imgCard3.Image)
    166.         lblComScore.Text = comScore
    167.         lblPlayScore.Text = playScore
    168.  
    169.         btnDraw.Enabled = False
    170.         btnDraw.Visible = False
    171.  
    172.         btnAgain.Visible = True
    173.         btnAgain.Enabled = True
    174.  
    175.         If playScore = comScore And comScore < SCORE Then   'scores are equal and under 21
    176.             MessageBox.Show("It’s a tie!")
    177.         End If
    178.  
    179.         If comScore < playScore And playScore < SCORE Then  'player is over computer but less than 21
    180.             MessageBox.Show("You win!!!")
    181.  
    182.         End If
    183.  
    184.         If playScore > comScore And comScore > SCORE Then   'player is over computer and over 21
    185.             MessageBox.Show("You lose. :(")
    186.         End If
    187.  
    188.         playScore = 0
    189.         comScore = 0
    190.  
    191.     End Sub
    192.  
    193.     Private Sub btnAgain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgain.Click
    194.  
    195.         Me.Close()
    196.         Form1.Show()
    197.         Form1.cmbAce.Text = Nothing
    198.  
    199.     End Sub
    200. End Class
    Attached Images Attached Images  
    Last edited by si_the_geek; Mar 29th, 2011 at 04:55 PM. Reason: c

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,433

    Re: More Blackjack card game trouble. Help??

    This is likely to be it:
    Private Function AddScore(ByVal p_Card As Integer, ByVal p_Image As Image) As Integer
    ByVal basically means "read only", which is not what you want... change it to ByRef and see if it works then

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    Re: More Blackjack card game trouble. Help??

    still nothing :/

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,433

    Re: More Blackjack card game trouble. Help??

    In that case change p_Image inside the routine to p_Image.Image , and when you call the routine pass the control name (you are likely to need to change p_Image As Image too, to the type of the control).

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    Re: More Blackjack card game trouble. Help??

    WOW ok sorry im in basic programming. as in just now learning Do Loop. could you simplify that last post a bit??

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,433

    Re: More Blackjack card game trouble. Help??

    Change the first line of the routine:
    Code:
        Private Function AddScore(ByVal p_Card As Integer, ByRef p_Image As PictureBox) As Integer
    (PictureBox is a guess, it should be the type of control that imgCard1 is)

    ..and add .Image to each of the parts of the routine that set p_Image, eg:
    Code:
                    p_Image.Image = Blackjack_Fix.My.Resources.sa
    ..and remove .Image from each place you call it, eg:
    Code:
            comScore += AddScore(com1, imgCard1)

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    Re: More Blackjack card game trouble. Help??

    ok that helped, but now ive got this going on:
    (this is com's score, by the way)
    Attached Images Attached Images  

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,433

    Re: More Blackjack card game trouble. Help??

    I presume something is wrong there, but as you didn't explain what is wrong (and what happened to get to that stage), I don't know what it is.

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    Re: More Blackjack card game trouble. Help??

    oh sorry. i clicked draw twice, so the player would have 2 cards. after two cards you can check the scores and end the game. ive been trying to make it so the computer always gets three cards- in the picture it's either now drawing three but the third one doesnt show up, or just b.s.ing the score (which it has been doing lately. the coms score is almost always in the low fifties.).

    edit:
    i've put in labels in form load to show the values before i draw the cards so i can verify the values. this is what i got: (i cut up the pic a bit to make it smaller)
    Attached Images Attached Images  
    Last edited by Carmelsundae; Apr 1st, 2011 at 12:12 PM.

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,433

    Re: More Blackjack card game trouble. Help??

    I see what is causing it.

    In btnCheck_Click you increase playScore and comScore based on the current cards, but you also re-add the values of the previous cards (eg: comScore always increases by the value of all 3 cards, and even does it twice!).

    You should either add the values for only the new cards, or reset the variables and then add the values for all cards.

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    22

    Re: More Blackjack card game trouble. Help??

    BASIC programming lol. english please???

Tags for this Thread

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