Solved

Card Games

Posted on 2000-03-27
4
341 Views
Last Modified: 2011-09-20
I'd like to find some example VB code for card games.

If anybody can give me link...

WillP
willmar@syix.com
0
Comment
Question by:WillP
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
wpsjr1 earned 50 total points
ID: 2662598
Here is a class module I wrote to encapsulate the Cards32 API:

Option Explicit

' Cards32.dll Class module by Wpsjr1@syix.com

Public Enum Suit
  Clubs
  Diamonds
  Heart
  Spades
End Enum

Public Enum Surface
  Face
  Back
  Inverted
End Enum

Public Enum Face
  Ace = 0
  Two = 4
  Three = 8
  Four = 12
  Five = 16
  Six = 20
  Seven = 24
  Eight = 28
  Nine = 32
  Ten = 36
  Jack = 40
  Queen = 44
  King = 48
End Enum

Public Enum Back
  Crosshatch = 53
  Plaid = 54
  Weave = 55
  Robot = 56
  Roses = 57
  Black = 58
  Blue = 59
  FishCyan = 60
  FishBlue = 61
  Shell = 62
  Castle = 63
  beach = 64
  Cardhand = 65
  Unused = 66
  Ex = 67
  Oh = 68
End Enum

Private Declare Function cdtAnimate Lib "cards32.dll" (ByVal hdc As Long, ByVal lCardBack As Long, ByVal x As Long, ByVal y As Long, ByVal iState As Long) As Long
Private Declare Function cdtDraw Lib "cards32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lCard As Long, ByVal iDraw As Long, ByVal color As Long) As Long
Private Declare Function cdtDrawExt Lib "cards32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal ordCard As Long, ByVal iDraw As Long, ByVal color As Long) As Long
Private Declare Function cdtInit Lib "cards32.dll" (dx As Long, dy As Long) As Long
Private Declare Function cdtTerm Lib "cards32.dll" () As Long

Event Error(errString As String)

Dim m_lWidth&
Dim m_lHeight&

Private Sub Class_Initialize()
  ' initialize the cards32.dll
  If cdtInit(m_lWidth, m_lHeight) <> 1 Then RaiseEvent Error("Could not initialize Cards32.dll")
End Sub

Private Sub Class_Terminate()
  cdtTerm ' free resources
End Sub

Public Property Get Height() As Long
  Height = m_lHeight
End Property

Public Property Get Width() As Long
  Width = m_lWidth
End Property

' show an animation on the card
Public Function Animate(ByVal hdc As Long, ByVal eBack As Back, ByVal x As Long, ByVal y As Long, ByVal lState As Long) As Long
  Animate = cdtAnimate(hdc, eBack, x, y, lState)
End Function

' draws cards to the dx/dy returned in cdtInit
Public Function Draw(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal eSuit As Suit, ByVal eType As Surface, ByVal lColor As Long) As Long
  Draw = cdtDraw(hdc, x, y, eSuit, eType, lColor)
  If Draw = 0 Then RaiseEvent Error("Could not Draw card")
End Function

' draws cards to non-standard sizes
Public Function DrawEx(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal eSuit As Suit, ByVal eType As Surface, ByVal lColor As Long) As Long
  DrawEx = cdtDrawExt(hdc, x, y, dx, dy, eSuit, eType, lColor)
  If DrawEx = 0 Then RaiseEvent Error("Could not DrawEx card")
End Function

' end module


To draw the Ace of Clubs with an animation on your form try the following code:

Dim i%

c.Draw hdc, 0, 0, 0, Surface.Face, BackColor
For i = 3 To 0 Step -1
  c.Animate hdc, beach, 0, 0, i
  Sleep 100
Next i
c.Draw hdc, 0, 0, 0, Surface.Face, BackColor

Good Luck!  :)

Paul

0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2663153
Here are several examples of code to look at:
http://www.planet-source-code.com/vb/scripts/BrowseCategoryOrSearchResults.asp?lngWId=1

wpsjr, please leave your posts as comments
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2663158
bad link: go here and type in "Card games" to search
http://www.planet-source-code.com/vb/scripts/search.asp?lngWId=1
0
 

Author Comment

by:WillP
ID: 2752551
Not exactly what I had in mind, but interesting.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question