Ooops
October 28, 2020, 05:24:26 AM

Author Topic: [bb] cards.dll userlib by Snarkbait [ 1+ years ago ]  (Read 1354 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] cards.dll userlib by Snarkbait [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : cards.dll userlib
Author : Snarkbait
Posted : 1+ years ago

Description : A set of functions to use cards.dll which comes with all versions of Windows.

Example screenie:
[img]my.xfinity.com/_tfsanford/bjscreen1.html">


Code :
Code: BlitzBasic
  1. ;decls
  2. ; make sure 'user32.decls' has the following line:
  3. ; user32_GetDC%(hwnd%):"GetDC"
  4.  
  5. ; "cards.decls"
  6. ;.lib "cards.dll"
  7. ;
  8. ;cdtInit%( pdxCard*, pdyCard* ):"cdtInit"
  9. ;cdtTerm%( ):"cdtTerm"
  10. ;cdtDraw%( hdc%, cardx%, cardy%, cdraw%, modedraw%, rgbBgrnd% ):"cdtDraw"
  11.  
  12. ;"blitzcards.decls"
  13. ;.lib " "
  14. ;
  15. ;Init_CardGame%( )
  16. ;End_CardGame%( )
  17. ;MakeDeck%( )
  18. ;LoadNames%( )
  19. ;GetCardValue%( FaceCard%, Suit% )
  20. ;GetCardFace%( Value% )
  21. ;GetSuit%( Value% )
  22. ;GetCardString$( Value% )
  23. ;DrawCard% ( hdc% , cardx% , cardy% , crddraw% , modedraw% , rgbBgrnd% )
  24. ;ShuffleCards%( max_rand% )
  25. ;QuickSort%( L%, R% )
  26. ;GetHDC%( GUIobjHandle% )
  27. ;; for b3d use GetHDC%( )
  28.  
  29. ; include file "cards.bb"
  30. ;==================================Comments========================================================
  31. ; include file for card.dll
  32. ; by Snarkbait snarkbait66@gmail.com
  33. ; cards.decls AND blitzcards.decls must be in your userlib folder
  34. ; cards.dll should be in your system folder, in some OS versions it might be called cards32.dll just change the name in the userlib decls
  35.  
  36.  
  37.  
  38. ;==================================Consts==========================================================
  39.  
  40. ; for 'modedraw' parameter in DrawCard()
  41. Const FACE_UP = 0 ; draws the card specified in crddraw
  42. Const FACE_DOWN = 1 ; draws the card back specified in crddraw
  43. Const HI_LITE = 2 ; draws a specified card using inverted colors
  44. Const ACE_PILE = 3 ;  draws a dotted pile indicator in bgColor
  45. Const REMOVE = 4 ;  draws an "empty" card in bgColor - use to remove card from screen
  46. Const DOTTED_LAYER = 5 ; draws a transparent dotted layer on the card
  47. Const RED_X = 6 ; draws the green card with the red X
  48. Const CIRCLE = 7  ; draws the green card with the circle
  49.  
  50. ;====================
  51.  
  52. Const Clubs = 0
  53. Const Diamonds = 1
  54. Const Hearts = 2
  55. Const Spades = 3
  56.  
  57. Const Ace = 1
  58. Const Jack = 11
  59. Const Queen = 12
  60. Const King = 13
  61.  
  62. ; use these constants with 'GetCardValue' like:
  63. ; DrawCard( hdc, cardx, cardy, GetCardValue( Ace, Spades), FACE_UP)
  64.  
  65.  
  66.  
  67. ;==================================Arrays==========================================================
  68.  
  69. Dim CardDeck(51) ; use this as deck in your program
  70. Dim ShuffleStack(51) ; used only for shuffling
  71. Dim FaceName$(12)
  72. Dim SuitName$(3)
  73.  
  74.  
  75. ;==================================Globals==========================================================
  76.  
  77. Global cardYsize ; will be 96
  78. Global cardXSize ; will be 71
  79.  
  80.  
  81.  
  82.  
  83. ;==================================Functions========================================================
  84.  
  85. Function Init_CardGame()
  86.         bankx = CreateBank(4)
  87.         banky = CreateBank(4)
  88.         PokeInt bankx,0,1
  89.         PokeInt banky,0,1      
  90.         success = cdtInit(bankx,banky)         
  91.         If success
  92.                 cardXsize = PeekInt(bankx,0)
  93.                 cardYsize = PeekInt(banky,0)
  94.         Else
  95.                 RuntimeError "Cards32.dll Error"
  96.         EndIf
  97.         FreeBank bankx
  98.         FreeBank banky
  99.         MakeDeck()
  100.         LoadNames()
  101. End Function
  102.  
  103. Function End_CardGame()
  104.         success = cdtTerm()
  105.         Return success
  106. End Function
  107.  
  108. Function MakeDeck()
  109.         For a = 0 To 51
  110.                 CardDeck(a) = a
  111.         Next
  112. End Function
  113.  
  114. Function GetCardValue( FaceCard, Suit)
  115.         Return ((FaceCard - 1) Shl 2) + Suit
  116. End Function
  117.  
  118. Function GetCardFace( value )
  119.         Return (value Shr 2) + 1
  120. End Function
  121.  
  122. Function GetSuit( value )
  123.         Return value And 3
  124. End Function
  125.  
  126. Function GetCardString$( value )
  127.         face = GetCardFace( value )
  128.         suit = GetSuit( value)
  129.         Return FaceName$(face - 1) + " of " + SuitName$(Suit)
  130. End Function
  131.  
  132. Function LoadNames()
  133.         Restore Facenames
  134.         For a = 0 To 12
  135.                 Read FaceName$(a)
  136.         Next
  137.         Restore Suitnames
  138.         For a = 0 To 3
  139.                 Read SuitName$(a)
  140.         Next
  141. End Function    
  142.  
  143. Function DrawCard( hdc, cardx = 0, cardy = 0, crddraw = 0, modedraw = 0, rgbBgrnd = 0)
  144.         If hdc
  145.                 success = cdtDraw( hdc, cardx, cardy, crddraw, modedraw, rgbBgrnd)
  146.                 Return success
  147.         Else
  148.                 Return False
  149.         EndIf
  150. End Function
  151.  
  152. Function ShuffleCards(max_rand = $FFFFFFFF)
  153.         For a = 0 To 51
  154.                 ShuffleStack(a) = Rand(max_rand)
  155.         Next
  156.         a = QuickSort()
  157. End Function
  158.  
  159. Function QuickSort( low = 0,high = 51) ; by TFT modified by me
  160.   Local partition,q,h
  161.   partition=low
  162.   q=high
  163.   x= ShuffleStack((low +high)/2)
  164.   Repeat
  165.     While ShuffleStack(partition) < x
  166.       partition=partition+1
  167.     Wend
  168.     While x < ShuffleStack(q)
  169.       q=q-1
  170.     Wend
  171.     If partition > q Then Exit
  172.         ;SWAP------------------
  173.         h=ShuffleStack(q)
  174.         h2 = CardDeck(q)
  175.         ShuffleStack(q)=ShuffleStack(partition)
  176.         CardDeck(q) = CardDeck(partition)
  177.         ShuffleStack(partition)=h
  178.         cardDeck(partition) = h2
  179.         ;----------------------
  180.     partition=partition + 1
  181.     q=q-1
  182.     If q<0 Then Exit
  183.   Forever
  184.   If low<q Then a=QuickSort(low,q)
  185.   If partition < high Then a=QuickSort(partition,high)
  186.   Return True
  187. End Function
  188.  
  189. ; for Blitz plus only, comment out for b3d
  190. Function GetHDC%( GUIobjHandle)
  191.         If GUIobjHandle
  192.                 rethdc = user32_GetDC(QueryObject(GUIobjHandle,1))
  193.                         If rethdc
  194.                                 Return rethdc
  195.                         Else
  196.                                 Return False
  197.                         EndIf
  198.         Else
  199.                 Return False
  200.         EndIf
  201. End Function
  202.  
  203. ; for Blitz3d, comment out for blitz plus - wonky, needs work.
  204. ;Function GetHDC%()
  205. ;       rethdc = user32_GetDC(systemproperty$("AppHWND"))
  206. ;       If rethdc
  207. ;               Return rethdc
  208. ;       Else
  209. ;               Return False
  210. ;       EndIf
  211. ;End Function
  212.                        
  213. ;==================================Data Statements/Labels=============================================
  214.  
  215. .Facenames
  216. Data "Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"
  217.  
  218. .Suitnames
  219. Data "Clubs","Diamonds","Hearts","Spades"


Comments :


Picklesworth(Posted 1+ years ago)

 Very nice :DBut um... A bit hard to install... (And I haven't got it working yet)Could you perhaps have a zip file? I'll host it for a while, if you'd like.Seems to be missing the function QueryObject.


Snarkbait(Posted 1+ years ago)

 Mr. Pickle, see my comments on CW.com... make sure to comment out the first GetHDC funtion and uncomment the second one if using B3d.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal