- Offizieller Beitrag
Hi,
für all jene, die gern Kartenspiele programmieren: Windows hält ja bereits Karten und Deckblätter bereit.
Hier mal ein kleines Bsp., wie man das nutzen kann:
Spoiler anzeigen
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
Opt ("MustDeclareVars", 1)
_Main ( )
_Main (True)
Func _Main ($mixed=False)
Local $a_hBMP[52][3], $a_hBitmap[52], $hGraphic, $hGUI, $hInstance
Local $ressource = "cards.dll"
; Load ressource dll as datafile
$hInstance = _WinAPI_LoadLibraryEx ($ressource, $LOAD_LIBRARY_AS_DATAFILE)
; Load bitmap's from library
; Farben sind in der Dll falsch angeordnet, ebenso die Asse
; im Array [i][0]=dll-Indx, [i][1]=echte Reihenfolge, [i][2]=BMP-Handle
Local $j = 15
For $i = 0 To 38
If $i = 12 Or $i = 25 Or $i =38 Then
$a_hBMP[$i][0] = $j -13
$a_hBMP[$i][1] = $i +1
$a_hBMP[$i][2] = _WinAPI_LoadBitmap ($hInstance, $a_hBMP[$i][0])
Else
$a_hBMP[$i][0] = $j
$a_hBMP[$i][1] = $i +1
$a_hBMP[$i][2] = _WinAPI_LoadBitmap ($hInstance, $a_hBMP[$i][0])
EndIf
$j += 1
Next
$j = 2
For $i = 39 To 50
$a_hBMP[$i][0] = $j
$a_hBMP[$i][1] = $i +1
$a_hBMP[$i][2] = _WinAPI_LoadBitmap ($hInstance, $a_hBMP[$i][0])
$j += 1
Next
$a_hBMP[51][0] = 1
$a_hBMP[51][1] = 52
$a_hBMP[51][2] = _WinAPI_LoadBitmap ($hInstance, $a_hBMP[51][0])
If $mixed Then
; Get random order
Local $aImagesIndex[52], $RandomIndex
For $i = 0 To 51
Do
$RandomIndex = Random(0, 51, 1)
_ArraySearch($aImagesIndex, String($RandomIndex))
If @error Then $aImagesIndex[$i] = String($RandomIndex)
Until $aImagesIndex[$i]
Next
; Set BMP-Handle to random order
Local $aTmp[52][3]
For $i = 0 To UBound($aTmp) -1
$aTmp[$i][0] = $a_hBMP[$aImagesIndex[$i]][0]
$aTmp[$i][1] = $a_hBMP[$aImagesIndex[$i]][1]
$aTmp[$i][2] = $a_hBMP[$aImagesIndex[$i]][2]
Next
; Group by partial sort
_ArraySort($aTmp, 0, 0, 12, 1)
_ArraySort($aTmp, 0, 13, 25, 1)
_ArraySort($aTmp, 0, 26, 38, 1)
_ArraySort($aTmp, 0, 39, 51, 1)
$a_hBMP = $aTmp
$aTmp = 0
EndIf
; Create GUI
Local $title='Karten reinfarbig'
If $mixed Then $title = 'Karten gemischt sortiert'
$hGUI = GUICreate ($title, 710, 350)
GUISetBkColor(0x008000)
GUISetState ()
; Initialize GDI+ library
_GDIPlus_Startup ()
; Create bitmap object's from bitmap handle's
For $i = 0 To UBound($a_hBitmap) -1
$a_hBitmap[$i] = _GDIPlus_BitmapCreateFromHBITMAP ($a_hBMP[$i][2])
Next
; Create a Graphics object from a window handle
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
; Draw all bitmap object's
Local $x = 20, $y = 20, $count
For $i = 0 To UBound($a_hBitmap) -1
$count = $i +1
_GDIPlus_GraphicsDrawImage ($hGraphic, $a_hBitmap[$i], $x, $y)
If $i > 1 And Mod($count, 13) = 0 Then
$x += 100
Else
$x += 20
EndIf
If $i = 25 Then
$x = 20
$y += 140
EndIf
Next
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; Clean up resources
For $i = 0 To UBound($a_hBitmap) -1
_GDIPlus_ImageDispose ($a_hBitmap[$i])
_WinAPI_DeleteObject ($a_hBMP[$i][2])
Next
_WinAPI_FreeLibrary ($hInstance)
; Shut down GDI+ library
_GDIPlus_ShutDown ()
GUIDelete()
EndFunc ;==>_Main
Edit: Habe (nur im geposteten Skript, nicht im Anhang) mal erweitert, dass die gemischten Karten in den Blöcken sortiert sind. Sieht besser aus
Edit2: Neue Version: die Karten befinden sich nun farblich und wertemäßig in der (in DE) üblicherweise verwendeten Reihenfolge. Also Karo-Rot-Pik-Kreuz und 2 bis As. Die gemischten Karten sind jetzt innerhalb des jeweiligen Stapels sortiert.
DL bisher: 17