Face Cards and Images...

Miscellaneous Forums/General Discussion/Face Cards and Images...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Yop Windows has a Cards DLL I remember using it in VB5 and VB6... the link Jack provided shows you how to use it. I remember something else where I played with making my own deck though... let me crack my DB:

; CARD DECK
; including shuffle
; (i didn't write the shuffle routines but I tweaked them a touch)
; the type and deck functions are mine... with help from the guys at Blitzbasic.com
; who may not be in my will but I send them good thoughts!
;
Graphics3D 800,600,16,2

SetBuffer BackBuffer()

SeedRnd MilliSecs()
reseed = Rand(1,1000) ;this compensates for known Random bug (just ask 'Morduun' 8)
reseed = Rand(1,1000) 

camera=CreateCamera() ; ya gotta see the cards!
PositionEntity camera,0,0,0
light=CreateLight()
RotateEntity light,45,0,0

Dim cards%(52) ; dim array for deck of cards so they can be shuffled
; *****************************************  CREATE DECK
Type card
	Field x  ; location
	Field y  ; location
	Field width ; next two are for size of card
	Field height
	Field number ; card number from sequence
	Field name$ ; name of card to compare with card number
	Field id ; to be used in conjunction with previous two varibles
End Type

Global i ; used in shuffle

carddeck=LoadAnimImage("cards.png",71,96,0,51) ; load big image of cards... has some nvidia probs I think???

shuffle() ; go to the mix them up function

For i = 0 To 52 ; set up the types of the shuffled deck
	deck.card = New card
	deck\x = tempx
	deck\y = tempy
	deck\width = 71
	deck\height = 96
	deck\number = cards%(i) ; i is used here to get number of card in PNG image to load
	deck\name$ = getSuit(i) ; i is used here to tell the type what suit the card is
	deck\id = i+1 ;				i is used here to adjust deck ID for cards
Next
; ***********************  THIS SECTION PRINTS OUT THE ENTIRE SHUFFLED DECK for accounting purposes
; ***********************  AND because I wanted to prove to myself that the shuffle worked
For i% = 0 To 13
	y% = y% + 15

	Text  10, y, getSuit$(cards(i))
	Text 210, y, getSuit$(cards(i+13))
	Text 410, y, getSuit$(cards(i+26))
	Text 610, y, getSuit$(cards(i+39))
	Text 320, 570, "( Press ENTER key to exit )",1,1
Next

Input

Flip

UpdateWorld()
RenderWorld()
; some words used to CHECK if the cards shown are correct
Text 0,0,"CARD: "+getsuit$(cards(0))+" + "+getsuit$(cards(1))+" + "+getsuit$(cards(2))+" + "+getsuit$(cards(3))
Text 0,15,"RAW #: "+cards(0)+" "+cards(1)+" "+cards(2)+" "+cards(3)

deck.card = First card
For y = 0 To 3
	If deck\number = 0 Then deck\number = 1 ; you can't read -1 (negative 1)
	DrawImage carddeck,15*y+30,y*50+29,deck\number-1
	Text 0,290+(y*20),""+getSuit(deck\number)
	deck = After deck
	
Next

While Not KeyHit(1)
; this is my adapted button code... does not work
For what.card = Each card
	If MouseX()>what\x And MouseX()<what\x+what\width And MouseY()>what\y And MouseY()<what\y+what\height Then
	pushed = 0
	If MouseHit(1) Then
	pushed = what\id
	EndIf
	EndIf
Next


Text 0,550,"PUSHED: "+ pushed ; my attempt to get the mouse to select a card.
Flip
pushed = 0

Wend

End

Function shuffle%()
	;Load the cards() array with 52 unique numbers
	;(they just happen to be sequential for now)
	For i% = 0 To 52
		cards(i) = i
	Next

	;Simulate shuffling deck 7 times	
	For i = 1 To 7*52
		;Use indices swap1 and swap2 to scramble deck
		swap1% = Rand(0,52)
		swap2% = Rand(0,52)
		
		;Ensure indices don't point to same element
		While swap1 = swap2
			swap2 = Rand(0,52)
		Wend
		
		;OK, two different elements, perform swap
		temp% = cards(swap1)
		cards(swap1) = cards(swap2)
		cards(swap2) = temp
	Next
End Function

Function getSuit$( integer%)
	;1-13 is a spade,  14-26 is a heart,  27-39 is a club,  40-52 is diamond
	If integer < 14 Then suit$ = "Spades"
	If integer > 13 And integer < 27 Then suit$ = "Hearts"
	If integer > 26 And integer < 40 Then suit$ = "Clubs"
	If integer > 39 Then suit$ = "Diamonds"
	;now we know the suit, make 'integer' a number between 0 and 12
	integer = integer Mod 13
	
	Select integer
		Case  1: value$ = "Ace"
		Case 11: value$ = "Jack"
		Case 12: value$ = "Queen"
		Case  0: value$ = "King"
		Default: value$ = Str(integer)
	End Select
	
	Return value$ + " of " + suit$
End Function

If you want the card image I used I can email it to your blitz listed email if you want!