L'auteur
Mike Gagnon Canada Membre Simple # 0000000025 enregistré le 14/10/2004
Gagnon Mike Pointe Cla H9R 3K8 de la société Carver Technologies Inc. Fiche personnelle
Note des membres
pas de note
|
Contributions > 05 - API et appels systèmes
Créer un jeu de cartes.
# 0000000271
ajouté le 27/01/2006 23:26:01 et modifié le 29/03/2006
consulté 11864 fois
Niveau
initié
Version(s) Foxpro : VFP 9.0 VFP 8.0 VFP 7.0 VFP 6.0 VFP 5.0 VFP 3.0
|
Description |
Ceci est basé sur un article de Calvin Hsia
en 2004 modifié quelques peu. Le DLL cards.dll qui fait parti de
Windows peut aussi etre utilisé avec VFP. |
Code source : |
Public ox
#Define NORTHx 150
#Define NORTHy 0
#Define EASTx 300
#Define EASTy 140
#Define SOUTHx 150
#Define SOUTHy 280
#Define WESTx 0
#Define WESTy 140
Declare Integer cdtInit In cards.Dll Integer @, Integer @
Declare Integer cdtTerm In cards.Dll
Declare Integer cdtDraw In cards.Dll Integer, Integer, Integer, Integer, Integer, Integer
Declare Integer cdtDrawExt In cards.Dll Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer
Declare Integer GetDC In WIN32API Integer
Declare Integer ReleaseDC In WIN32API Integer, Integer
Declare Integer ValidateRect In WIN32API Integer, String
ox=Newobject("myform")
ox.Show()
ox.dealem
Define Class myform As Form
Left=250
Height=400
Width=520
AllowOutput=.F.
xpix = 0
ypix = 0
caption = "Jouez aux cartes"
Dimension crd[52]
Dimension xlt[52]
Procedure Init
Local i
Rand(10)
For i = 1 To 52
This.crd[i] = i
Endfor
For i = 1 To 4
This.xlt[13 *i ] = i - 1 && the aces
Endfor
For j = 2 To 13 && 2 thru K
For i = 0 To 3
This.xlt[j-2 + 13 *i+1] = 4*(j-1) + i
Endfor
Endfor
xpix=0
ypix=0
cdtInit(@xpix, @ypix)
Thisform.xpix = xpix
Thisform.ypix = ypix
Endproc
Procedure shuffle
Local i, tmp
For i = 1 To 52
nrnd = Int(Rand() * 52 )+1
tmp = This.crd[i]
This.crd[i] = This.crd[nrnd]
This.crd[nrnd] = tmp
Endfor
Endproc
Procedure sortem(nHand, xpos, ypos)
Local i,j, nSt, nEnd, tmp, npts, ndenom
npts=0
nSt = nHand * 13+1
nEnd = nSt + 12
For i = nSt To nEnd
For j = nSt To i-1
If This.crd[i] > This.crd[j]
tmp = This.crd[i]
This.crd[i] = This.crd[j]
This.crd[j] = tmp
Endif
Endfor
Endfor
hdc = GetDC(This.HWnd)
For i = nSt To nEnd
ndenom = Mod(This.crd[i]-1, 13)
If ndenom > 8
npts = npts + ndenom - 8
ENDIF
cdtDraw(hdc, xpos+(i-nSt)*12,ypos,This.xlt[this.crd[i]],0,0)
Endfor
ReleaseDC(This.HWnd, hdc)
srect = This.ntox(0) + This.ntox(0) + This.ntox(Thisform.Width) + This.ntox(Thisform.Height)
ValidateRect(This.HWnd, srect)
Return npts
Endproc
Procedure ntox(nPix)
Return Chr(Mod(nPix,256)) + Chr(Int(nPix/256)) +Chr(0)+Chr(0)
Endproc
Procedure dealem
Local nptsn,nptse, nptss, nptsw
Thisform.shuffle
nptsn = This.sortem(0,NORTHx,NORTHy)
nptse = This.sortem(2,EASTx, EASTy)
nptss = This.sortem(1,SOUTHx,SOUTHy)
nptsw = This.sortem(3,WESTx,WESTy)
nsp = 0
For i = 1 To 26
If This.crd[i] > 39
nsp = nsp + 1
Endif
Endfor
nspe = 0
For i = 27 To 39
If This.crd[i] > 39
nspe = nspe + 1
Endif
Endfor
If nspe < (13 - nsp)/2
nspe = (13 - nsp) - nspe
Endif
Endproc
Procedure Destroy
cdtTerm()
Endproc
Procedure xlate(nCrd As Integer)
Local nsuit, nNum
nsuit = Int(nCrd/13)
nNum = Mod(nCrd,13)
If nNum = 12
nCrd = nsuit
Else
nCrd = 4*(nNum + 1) + nsuit
Endif
Return nCrd
Endproc
Enddefine
|
Commentaires |
Aucun commentaire enregistré ...
|