Deck of Cards:
+ Code Snippet// set display properties
SetWindowSize( 1280,720, 0 )
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
SetPrintColor(0,0,0)
SetClearColor(255,255,255)
Suits$ = "♣♦♥♠"
Type Card
Value, Suit$, Face$
EndType
GLOBAL Deck as Card []
for x = 1 to 4
ThisSuit$ = MID(Suits$,x,1)
for y = 1 to 13
ThisCard as Card
ThisCard.Value = y
Face$ = STR(y)+ThisSuit$
If y = 1 then Face$ = "A" + ThisSuit$
If y = 11 then Face$ = "J" + ThisSuit$
If y = 12 then Face$ = "Q" + ThisSuit$
If y = 13 then Face$ = "K" + ThisSuit$
ThisCard.Face$ = Face$
ThisCard.Suit$ = ThisSuit$
Deck.Insert(ThisCard)
next y
next x
GLOBAL TheseCards as Integer []
for x = 1 to 13
for y = 1 to 4
ThisTXT = CreateText("") : SetTextAlignment(ThisTXT,1)
SetTextPosition(ThisTXT, x*70,y*48)
SetTextSize(ThisTXT,48) : TheseCards.Insert(ThisTXT)
next y
Next x
Shuffle()
do
if GetRawKeyPressed(27) then End
if GetPointerPressed() then Shuffle()
Print("Tap to Shuffle")
Sync()
loop
Function Shuffle()
TempArray as Card []
for x = 0 to Deck.Length
TempArray.insert(Deck[x])
next x
for x = Deck.Length to 0 step -1
Deck.Remove()
next x
all = TempArray.Length
for x = 0 to all
ThisIndex = Random(0,TempArray.Length)
Deck.Insert(TempArray[ThisIndex])
TempArray.Remove(ThisIndex)
next x
For x = 0 to TheseCards.Length
If Deck[x].Suit$ = "♣" or Deck[x].Suit$ = "♠"
SetTextColor(TheseCards[x],0,0,0,255)
Else
SetTextColor(TheseCards[x],255,0,0,255)
Endif
SetTextString(TheseCards[x],Deck[x].Face$)
Next x
EndFunction