Simple BlackJack game

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
3811819172_93e25d6e75_o.jpg


3811819802_36f235c493_o.jpg
 

Attachments

  • BlackJack.zip
    75.8 KB · Views: 303
Last edited:

ExcludeReality

Active Member
Licensed User
Good thinking, See the update above.
I am open for other suggestions too
 

derez

Expert
Licensed User
Longtime 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:
B4X:
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:

B4X:
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.

B4X:
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:

derez

Expert
Licensed User
Longtime 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.

B4X:
Sub App_Start
   BlackJackForm.Show
   FileOpen(C1,"Cards.dat",cRandom)
   Cards.New1(C1,True)
End Sub

B4X:
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:

ExcludeReality

Active Member
Licensed User
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 ?

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:
Top