This is an old favourite and oft repeated on the web. If you haven't already done so, click and play along. Normally, the cards are always the same ... I thought it would be fun to make a better version which uses different cards every time. Before proceeding, make sure you know how the trick works!
Once again, I'm going to try to take you through my thought processes as I created this program.
Firstly, I realised that I needed to identify the black & red court cards and pair them together. One pair, for example, would be the Jack of Spades and the Jack of Clubs. Then I could randomly select one card from each pair to give me the starting six and I would need the the other from each pair for the final six. (Yes I know it's five but all we have to do is drop one!) Anyway ... see if you can list these six pairs yourself.
One way to store information in a BB program is with the Data statement.
I'll explain how to use it in a moment.
Here's the start of my program:
Graphics 800,600 Setbuffer Backbuffer() SeedRnd MilliSecs() Data 13,52 ; black Kings Data 26,39 ; red Kings Data 12,51 ; black Queens Data 25,38 ; red Queens Data 11,50 ; black Jacks Data 24,37 ; red Jacks Dim cards1(6) Dim cards2(6)
To get at the data we use the Read so, for example, Read c1
will store the 13 in c1.
See if you can randomly set up those two arrays yourself before reading on.
For i=1 To 6
Read c1
Read c2
If Rand(2)=1 Then
cards1(i)=c1
cards2(i)=c2
Else
cards1(i)=c2
cards2(i)=c1
End If
Next
Neat eh? Well the rest of the program requires nothing new so I'll leave you to it. You can use my graphics or better still ... make your own.