Simple BlackJack game

Discussion in 'Share Your Creations' started by ExcludeReality, Aug 6, 2009.

  1. ExcludeReality

    ExcludeReality Active Member Licensed User

    UPDATE:
    As a response to Derez the game now features a full bettting system, real cards and some animations.

    Please post your feedback

    ---------------------------

    This is just a simple blackjack game, nothing fancy.
    I wanted to share it because it's such a nice piece of code :)

    It took me almost an hour to make, not to brag though

    Screenshot
    [​IMG]

    [​IMG]
     

    Attached Files:

    Last edited: Aug 11, 2009
  2. derez

    derez Expert Licensed User

  3. ExcludeReality

    ExcludeReality Active Member Licensed User

    Good thinking, See the update above.
    I am open for other suggestions too
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I think you left the old file ?
     
  5. ExcludeReality

    ExcludeReality Active Member Licensed User

    You're right, Erel.
    Sorry, I updated the new file
     
  6. derez

    derez Expert Licensed User

    I am still unhappy with the cards images - they are all of the same "family" and it is boring :(

    I wrote a rummy game in which I use two packs of cards. Here is one sub from there, demonstrating the control of the card images (see the link in my previous post):

    dblpack is an arraylist initialized to include the two packs:
    Code:
    dblpack.Clear
    dblpack.Add(
    0)
    For i = 1 To 106
      dblpack.Add(i)
    Next
    The position, which gets the cards face image is set by:

    Code:
    Sub pos(x)
    If x > 53 Then x = x -53
    Return (x-1)*3582
    End Sub
    where x is a number between 1 to 106.
    the following sub defines the top card in the bank, while it is still with the face down, so you have to show the back color according to the pack number 1 or 2.

    Code:
    Sub setbankD   ' defines the top card on the bank
    random = Rnd(1,dblpack.Count)
    bank = dblpack.Item(random)
    If bank > 53 Then deck = 5 Else deck = 6
    Cards.Position =  
    53 * 3582 + deck * 20798
    bankimage.image = Cards.RetrieveImage
    dblpack.RemoveAt(random)
    End Sub
    The value of the card is found by using mod() function.

    I hope it helps but of course you don't have to do it if you don't feel like it...
     
    Last edited: Aug 11, 2009
  7. derez

    derez Expert Licensed User

    :)To only change the appearance without complexing the sets of cards - here is a small mod which will display randomly the image of the selected (randomized) value:

    add binaryfile.dll and an object "cards"
    copy cards.dat from the link to your directory.

    Code:
    Sub App_Start
       BlackJackForm.Show
       FileOpen(C1,
    "Cards.dat",cRandom)
       Cards.New1(C1,
    True)
    End Sub
    Code:
    Sub HitCard
       
    If CardAnimation.Enabled = True Then Return
       PlayCards=PlayCards +
    1

       val = 
    Rnd(2,15)
       deck = Int(
    Rnd(1,4))
       cards.Position = (val+deck*
    13-1)* 3582 
       CardValue.AddOrUpdate (
    "Play" & PlayCards,val) '
       Control ("PlayCard" & PlayCards).Image =cards.RetrieveImage 
                 ...
    The same mod should be placed in the dealhitcard sub.

    Edit: There is a problem with the values of the cards, may be this game works with other rules. for example - the value of the queen is 10, not 12
    Why to randomize 2-15 ?
    Anyway - play with the position to get it right, good luck
     
    Last edited: Aug 12, 2009
  8. ExcludeReality

    ExcludeReality Active Member Licensed User

    I used:
    Jack=11
    Queen=12
    King=13
    Ace=14

    This game was only meant as a code example, I didn't know I would continue to develop it.
    I think I will leave it now, but anyone can feel free to make improvements of course.
    Thanks for your help Derez
     
    Last edited: Aug 12, 2009
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice