Setting Values of Cards

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EXotiX
    New Member
    • Jun 2007
    • 2

    #1

    Setting Values of Cards

    Hey I have a blackjack game and I am unsure on how to set the values of the cards can anyone help?

    [CODE=vb]Option Explicit
    Const NumItems As Integer = 53

    Public Sub RandomizeCards( )
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim l As Integer
    Dim m As Integer
    Dim n As Integer
    Dim o As Integer
    Dim p As Integer

    Dim tmp As Integer
    Dim Count As Integer


    imgUser(2).Visi ble = False
    imgUser(3).Visi ble = False
    imgUser1(2).Vis ible = False
    imgUser1(3).Vis ible = False

    ' Randomize the array.
    Randomize

    For Count = 1 To NumItems - 1

    ' Pick a random entry.

    j = Int((Rnd * 53) + 1)
    i = Int((Rnd * 53) + 1)
    k = Int((Rnd * 53) + 1)
    l = Int((Rnd * 53) + 1)
    m = Int((Rnd * 53) + 1)
    n = Int((Rnd * 53) + 1)
    o = Int((Rnd * 53) + 1)
    p = Int((Rnd * 53) + 1)

    ' Swap the numbers.

    'imgCards(tmp) = imgCards(j)
    'imgCards(j) = imgCards(i)
    'imgCards(i) = imgCards(tmp)
    Next Count

    'Player one cards
    imgUser(0) = imgCards(j)
    imgUser(1) = imgCards(i)
    imgUser(2) = imgCards(k)
    imgUser(3) = imgCards(l)

    'Player two cards
    imgUser1(0) = imgCards(m)
    imgUser1(1) = imgCards(n)
    imgUser1(2) = imgCards(o)
    imgUser1(3) = imgCards(p)
    End Sub

    Private Sub cmdDeal_Click()
    RandomizeCards
    cmdDeal.Visible = False
    cmdTwist.Visibl e = True
    cmdStick.Visibl e = True
    cmdTwist1.Visib le = True
    cmdStick1.Visib le = True
    End Sub

    Private Sub cmdStick_Click( )
    End
    End Sub

    Private Sub cmdStick1_Click ()
    End
    End Sub

    Private Sub cmdTwist_Click( )

    If imgUser(0) And imgUser(1) <= 100 Then

    imgUser(2).Visi ble = True

    End If

    'imgUser(2).Vis ible = True
    'imgUser(3).Vis ible = True
    End Sub

    Private Sub cmdTwist1_Click ()
    imgUser1(2).Vis ible = True
    imgUser1(3).Vis ible = True
    End Sub

    Private Sub Form_Load()
    cmdTwist.Visibl e = False
    cmdStick.Visibl e = False
    cmdTwist1.Visib le = False
    cmdStick1.Visib le = False
    End Sub[/CODE]

    Any Ideas?
    Last edited by Killer42; Jun 21 '07, 10:07 AM. Reason: Added [CODE=vb] tag
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    hi!!

    well first of all why dont you use an array instead l m n o p q as integers

    This will allow you to make a randomize that doesnt repeat cards... something like

    [CODE=vb]dim Int(1 to 8) as integer
    dim i as integer
    dim j as integer
    dim Boo1 as boolean

    int(1) = int(52 * rnd) + 1

    for i = 2 to 8
    boo1=false
    while boo1=false
    int(i)= int(52 * rnd) + 1
    boo1=true
    for j = 1 to i
    if int(i) = int(j) then
    boo1=false
    end if
    next
    wend
    next[/CODE]

    Voilá now you have 8 different numbers from 1 to 52

    Next thing is to create an array where you're going to store the values, something like

    [CODE=vb]dim Int2(1 to 8) as integer

    for i = 1 to 8
    int2(i) = int(i) mod 13
    if int2(i) >10 or int2(i) = 0 then
    int2(i) = 10
    elseif int2(i) = 1 then
    int2(i) = 11
    end if
    next[/CODE]

    Now they all have their right values, but the A that will be alwas 11.
    And finally, to make it "intelligen t" just check that if the sum is greater than 21, if any of the cards value is 11, change it to 1.
    Something like

    [CODE=vb]Dim Player1 as integer

    Player1 = Int2(1)+Int2(2) +Int2(3)+Int2(4 )

    if Player1 > 21 then
    for i= 1 to 4
    if int2(i) =11 then
    int2(i) = 1
    end if
    next
    end if

    Player1 = Int2(1)+Int2(2) +Int2(3)+Int2(4 )
    if Player1 > 21 then
    msgbox ("player1 sucks")
    end if[/CODE]

    Hope this helps
    (i didn't revise the code, so it might have syntax errors, but it can give you an idea)

    Good Luck
    KAD

    Comment

    Working...