Jump to content

Dice and Cards replacer


dragan
 Share

Recommended Posts

Several nights ago, few friends of mine and me, wanted to play a board game, but we had no dices and had no cards, so I made one app in few sec. that simulates throwing dices and drawing cards. Today I decided to make more complete app for same purpose, and I came up with this script.

I also didn't mention that app will store drawn cards into memory array, so it won't draw same card again (if you have only 1 deck, and if you have 2 decks it won't draw 2 of the same card) until all cards are selected, then the array resets and you have all the cards again. And if you have cards selected (to save for next drawing), and you reach the end of the deck, selected cards will be stored into memory automatically after deck is being reset.

Posted Image

Reason for edit: added image to the post

edit No.2 - v1.0.0.1: added low quality animations to it

edit No.3 - v1.0.0.2: changed _GenerateRandomNumbers() functions, help from LaCastiglione, and changed "Poker" into "Sevens" tnx to nitekram

edit No.4 - v1.0.0.3: added ability to select cards/dice you want to save for next throwing/drawing, all graphics are made using GDI+, also will calculate mid-color for cards (black vs red) and set label in that color. After decks number gets changed, all decks are being mixed automatically (to reset cards on the table).

#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#Include <GuiComboBox.au3>
#include <GDIPlus.au3>

Opt("GUICloseOnESC", 0)

HotKeySet('{F9}', '_ThrowDices')
HotKeySet('{F10}', '_DrawCards')

Global $Title = 'Dice&Card Games Assistant'
Global $version = '1.0.0.3'

Global $width = 500, $height = 425

$Title &= ' - v' & $version

Global $IniFile = @ScriptDir & '\config.ini'

Global $DicesOn = False, $CardsOn = False
Global $MouseState = 1, $LastHoveredDice = 0, $lasthoveredCard = 0
Global $CardsOverLap = False

If NOT FileExists($IniFile) Then
    IniWrite($IniFile, 'Dices', 'Number', 7)
    IniWrite($IniFile, 'Cards', 'Number', 5)
    IniWrite($IniFile, 'Cards', 'Deck', 1)
    IniWrite($IniFile, 'Cards', 'DeckNumber', 1)
    IniWrite($IniFile, 'Options', 'Sound', 3)
    IniWrite($IniFile, 'Options', 'Animate', 3)
EndIf

Dim $CardsArray[1][5]
_Form_Cards_Array($CardsArray, IniRead($IniFile, 'Cards', 'Deck', 1))

Dim $LastCards[1][8]
Dim $LastDices[1][5]

$Form1 = GUICreate($Title, $width, $height)
GUISetBkColor(0xEEEEEE)
GUICtrlCreateGroup('Dices', 5, 5, $width-10, 140)
GUICtrlCreateLabel('Number of dices:', 20, 25, 85, 17)
$DiceNumber = GUICtrlCreateInput(IniRead($IniFile, 'Dices', 'Number', '7'), 105, 25-3, 45, 20, BitOR($ES_CENTER, $ES_NUMBER))
GUICtrlCreateUpdown(-1)
$ThrowDices = GUICtrlCreateButton('Throw dices    [ hotkey = F9 ]', 160, 25-6, $width-35-180-50, 25)
$DicesThrownLabel = GUICtrlCreateLabel('Thrown dice(s): /', 10, 123, $width-20, 17, $ES_CENTER)
GUICtrlSetFont(-1, 10, 400, -1, 'Segoe UI')
$clear_dice_button = GUICtrlCreateButton('Clear selection', 180+($width-35-180-70)+10, 25-6, 80, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$CardSetHeight = 145
GUICtrlCreateGroup('Cards', 5, $CardSetHeight+5, $width-10, 230)
GUICtrlCreateLabel('Number of cards to draw:', 20, 25+$CardSetHeight, 85+40, 17)
$CardsNumber = GUICtrlCreateInput(IniRead($IniFile, 'Cards', 'Number', '5'), 105+40, 25-3+$CardSetHeight, 45, 20, BitOR($ES_CENTER, $ES_NUMBER))
GUICtrlCreateUpdown(-1)
GUICtrlCreateLabel('Deck type:', 145+45+20, 25+$CardSetHeight, 60, 17)
$DeckType = GUICtrlCreateCombo('', 210+55, 25-3+$CardSetHeight, 100, -1, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, 'Bridge - 2 to A|Sevens - 7 to A')
_GUICtrlComboBox_SetCurSel($DeckType, IniRead($IniFile, 'Cards', 'Deck', '1'))
GUICtrlCreateLabel('Decks No:', 385, 25+$CardSetHeight, 60, 17)
$DecksNumber = GUICtrlCreateInput(IniRead($IniFile, 'Cards', 'DeckNumber', '1'), 440, 25-3+$CardSetHeight, 45, 20, BitOR($ES_CENTER, $ES_NUMBER))
GUICtrlCreateUpdown(-1)
$DrawCards = GUICtrlCreateButton('Draw cards   [ hotkey = F10 ]', 20+90, 50+$CardSetHeight, $width-40-175)
$CardsDrawnLabel = GUICtrlCreateLabel('Drawn card(s): /', 10, 213+$CardSetHeight, $width-20, 17, $ES_CENTER)
GUICtrlSetFont(-1, 10, 400, -1, 'SegoeUI')
$Clear_Cards_Button = GUICtrlCreateButton('Clear selection', 20, 50+$CardSetHeight, 80, 25)
$Mix_Cards_Button = GUICtrlCreateButton('Mix cards', 405, 50+$CardSetHeight, 80, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$PlaySounds = GUICtrlCreateCheckbox('Play sounds', 5, $height-35)
GUICtrlSetState(-1, IniRead($IniFile, 'Options', 'Sound', '3'))
$AnimateElements = GUICtrlCreateCheckbox('Animate elements', 120, $height-35)
GUICtrlSetState(-1, IniRead($IniFile, 'Options', 'Animate', '3'))
$CloseBUtton = GUICtrlCreateButton('Close', $width-110, $height-35, 100, 25)
GUISetState(@SW_SHOW)

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
$hbitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($hbitmap)
$HotPen2 = _GDIPlus_PenCreate (0x5500CC00, 6)
$HotPen3 = _GDIPlus_PenCreate (0xCC0000CC, 1)
$HotBrush = _GDIPlus_BrushCreateSolid (0x200000CC)
$BrushRed = _GDIPlus_BrushCreateSolid(0xFFCC0000)
$BrushBlack = _GDIPlus_BrushCreateSolid(0xFF000000)
$BrushWhite = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$BackgroundBrush = _GDIPlus_BrushCreateSolid(0xFFEEEEEE)
$hFormat = _GDIPlus_StringFormatCreate ()
_GDIPlus_StringFormatSetAlign($hFormat, 1)
$hFamily = _GDIPlus_FontFamilyCreate ('Times New Roman')
$hFont = _GDIPlus_FontCreate ($hFamily, 36, 1)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 2)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg(0xF,"MY_PAINT")

OnAutoItExitRegister( "QuitApplication" )

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_RESTORE
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
        Case $DeckType
            _Form_Cards_Array($CardsArray, _GUICtrlComboBox_GetCurSel($DeckType))
            _MixCards()
    EndSwitch

    If WinActive($Form1) then
        Local $a = GUIGetCursorInfo($Form1)
        $hoveringDice = False
        For $i = 1 to UBound($LastDices)-1
            If ($a[0] > $LastDices[$i][1]) AND ($a[1] > $LastDices[$i][2]) AND ($a[0] < $LastDices[$i][3]) AND ($a[1] < $LastDices[$i][4]) Then
                If $a[2] = 1 Then
                    If $MouseState <> 3 Then
                        $MouseState = 3
                        $LastHoveredDice = 0
                        If $LastDices[$i][5] = False then
                            If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Windows Navigation Start.wav")
                            $LastDices[$i][5] = True
                        Else
                            If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Speech Misrecognition.wav")
                            $LastDices[$i][5] = False
                        EndIf
                    EndIf
                else
                    If $MouseState <> 1 Then
                        $MouseState = 1
                    EndIf
                EndIf
                If $hoveringDice = False then $hoveringDice = True
                If $LastHoveredDice <> $i Then
                    $LastHoveredDice = $i
                    _GDIPlus_GraphicsFillRect($backbuffer, 6, 48, $width-13, 60+8, $BackgroundBrush)
                    For $z = 1 to UBound($LastDices)-1
                        If $LastDices[$z][5] = True then
                            _DrawDices($LastDices[$z][0], $LastDices[$z][1], $LastDices[$z][2], 60, 60, True)
                            _DrawEdgeRoundDice($LastDices[$z][1], $LastDices[$z][2], 60, 60, $HotPen3, True, $HotBrush)
                        Else
                            _DrawDices($LastDices[$z][0], $LastDices[$z][1], $LastDices[$z][2], 60, 60, False)
                        EndIf
                        If $z = $i then
                            _DrawEdgeRoundDice($LastDices[$z][1], $LastDices[$z][2], 60, 60, $HotPen2)
                        EndIf
                    Next
                    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
                EndIf
            EndIf
        Next
        If $hoveringDice = False Then
            If $LastHoveredDice <> 0 Then
                $LastHoveredDice = 0
                _DrawOrDeleteEdgesDice($HotPen3, True, $HotBrush)
                _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
            EndIf
        EndIf

        Local $hoveringCard = False
        For $i = 1 to UBound($LastCards)-1
            If ($a[0] > $LastCards[$i][3]) AND ($a[1] > $LastCards[$i][4]) AND ($a[0] < $LastCards[$i][5]) AND ($a[1] < $LastCards[$i][6]) Then
                Local $card_dim = 80
                If $a[2] = 1 Then
                    If $MouseState <> 3 Then
                        $MouseState = 3
                        $lasthoveredCard = 0
                        If $LastCards[$i][7] = False then
                            If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Windows Navigation Start.wav")
                            $LastCards[$i][7] = True
                        Else
                            If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Speech Misrecognition.wav")
                            $LastCards[$i][7] = False
                        EndIf
                    EndIf
                Else
                    If $MouseState <> 1 Then
                        $MouseState = 1
                    EndIf
                EndIf
                If $hoveringCard = False then $hoveringCard = True
                If $lasthoveredCard <> $i Then
                    $lasthoveredCard = $i
                    _GDIPlus_GraphicsFillRect($backbuffer, 6, $CardSetHeight+78, $width-13, $card_dim+$card_dim/2+8, $BackgroundBrush)
                    If $CardsOverLap = True then _GDIPlus_StringFormatSetAlign($hFormat, 0)
                    For $z = 1 to UBound($Lastcards)-1
                        If $CardsOverLap = True Then
                            If $z = UBound($Lastcards)-1 Then
                                _GDIPlus_StringFormatSetAlign($hFormat, 1)
                            EndIf
                        EndIf
                        _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $BrushWhite)
                        $layOut = _GDIPlus_RectFCreate ($LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2)
                        If $LastCards[$z][2] < 3 then
                            _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$z][0] & @CRLF & $LastCards[$z][1], $hFont, $layOut, $hFormat, $BrushBlack)
                        Else
                            _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$z][0] & @CRLF & $LastCards[$z][1], $hFont, $layOut, $hFormat, $BrushRed)
                        EndIf
                        _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2)
                        If $LastCards[$z][7] = True then
                            _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $HotBrush)
                            _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $HotPen3)
                        EndIf
                        If $z = $i then _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $HotPen2)
                    Next
                    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
                EndIf
            EndIf
        Next
        If $hoveringCard = False Then
            If $lasthoveredCard <> 0 Then
                $lasthoveredCard = 0
                _DrawOrDeleteEdgesCards($HotPen3, True, $HotBrush)
                _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
            EndIf
        EndIf
    EndIf
    Sleep(1)
WEnd

Func _DrawOrDeleteEdgesCards($pen = 0, $fill = False, $brush = 0)
    Local $card_dim = 80
    _GDIPlus_GraphicsFillRect($backbuffer, 6, $CardSetHeight+78, $width-13, $card_dim+$card_dim/2+8, $BackgroundBrush)
    If $CardsOverLap = True then _GDIPlus_StringFormatSetAlign($hFormat, 0)
    For $z = 1 to UBound($Lastcards)-1
        If $CardsOverLap = True Then
            If $z = UBound($Lastcards)-1 Then
                _GDIPlus_StringFormatSetAlign($hFormat, 1)
            EndIf
        EndIf
        _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $BrushWhite)
        $layOut = _GDIPlus_RectFCreate ($LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2)
        If $LastCards[$z][2] < 3 then
            _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$z][0] & @CRLF & $LastCards[$z][1], $hFont, $layOut, $hFormat, $BrushBlack)
        Else
            _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$z][0] & @CRLF & $LastCards[$z][1], $hFont, $layOut, $hFormat, $BrushRed)
        EndIf
        _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2)
        If $LastCards[$z][7] = True then
            If $fill = True then _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $brush)
            _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $pen)
        EndIf
    Next
EndFunc

Func _DrawOrDeleteEdgesDice($pen = 0, $Fill = False, $brush = 0)
    _GDIPlus_GraphicsFillRect($backbuffer, 6, 48, $width-13, 60+8, $BackgroundBrush)
    For $i = 1 to UBound($LastDices)-1
        If $LastDices[$i][5] = True then
            _DrawDices($LastDices[$i][0], $LastDices[$i][1], $LastDices[$i][2], 60, 60, True)
            _DrawEdgeRoundDice($LastDices[$i][1], $LastDices[$i][2], 60, 60, $pen, $fill, $brush)
        Else
            _DrawDices($LastDices[$i][0], $LastDices[$i][1], $LastDices[$i][2], 60, 60, False)
        EndIf
    Next
EndFunc

Func _DrawEdgeRoundDice($iX, $iY, $iWidth, $iHeight, $pen, $fill = False, $brush = 0)
    Local $aPoints[5][2]
    Local $reduction = 6
    $aPoints[0][0] = 4
    $aPoints[1][0] = $iX+$reduction
    $aPoints[1][1] = $iY+$reduction
    $aPoints[2][0] = $iX+$iWidth-$reduction
    $aPoints[2][1] = $iY+$reduction
    $aPoints[3][0] = $iX+$iWidth-$reduction
    $aPoints[3][1] = $iY+$iHeight-$reduction
    $aPoints[4][0] = $iX+$reduction
    $aPoints[4][1] = $iY+$iHeight-$reduction
    If $fill = True then _GDIPlus_GraphicsFillClosedCurve($backbuffer, $aPoints, $brush)
    _GDIPlus_GraphicsDrawClosedCurve($backbuffer, $aPoints, $pen)
EndFunc

Func _ThrowDices()
    If $DicesOn = True then Return 0
    $DicesOn = True
    If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Windows Pop-up Blocked.wav")
    Local $number_of_dices = GUICtrlRead($DiceNumber)
    If $number_of_dices < 1 Then
        MsgBox(0, 'Error', 'Your dice number is invalid')
        $DicesOn = False
        Return 0
    EndIf
    Local $Total = ''
    Local $space_between = 8
    Local $dice_dim = 60
    Local $total_width = $number_of_dices*$dice_dim+($number_of_dices-1)*$space_between
    If $total_width > $width-20 Then
        Do
            $space_between -= 1
            $total_width = $number_of_dices*$dice_dim+($number_of_dices-1)*$space_between
        Until $total_width < $width-20
    EndIf
    Local $layOut, $random_number
    _GDIPlus_GraphicsFillRect($backbuffer, 6, 48, $width-13, $dice_dim+8, $BackgroundBrush)
    If UBound($LastDices)-1 <> $number_of_dices then
        ReDim $LastDices[$number_of_dices+1][6]
        For $i = 1 to $number_of_dices
            $LastDices[$i][5] = False
        Next
    Else
        For $i = 1 to $number_of_dices
            If $LastDices[$i][5] = True then _DrawDices($LastDices[$i][0], $LastDices[$i][1], $LastDices[$i][2], $dice_dim, $dice_dim, $LastDices[$i][5])
            If $LastDices[$i][5] = True then _DrawEdgeRoundDice($LastDices[$i][1], $LastDices[$i][2], $dice_dim, $dice_dim, $HotPen3, True, $HotBrush)
        Next
    EndIf
    If GUICtrlRead($AnimateElements) = $GUI_CHECKED Then _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
    For $i = 1 to $number_of_dices
        If $LastDices[$i][5] = True then
            $random_number = $LastDices[$i][0]
        Else
            $random_number = Random(1, 6, 1)
            $LastDices[$i][0] = $random_number
        EndIf
        $Total &= $random_number & ', '
        If $LastDices[$i][5] = False then _DrawDices($random_number, $width/2-$total_width/2+($i-1)*($dice_dim+$space_between), 52, $dice_dim, $dice_dim, $LastDices[$i][5])
        $LastDices[$i][1] = $width/2-$total_width/2+($i-1)*($dice_dim+$space_between)
        $LastDices[$i][2] = 52
        $LastDices[$i][3] = $width/2-$total_width/2+($i-1)*($dice_dim+$space_between)+$dice_dim
        $LastDices[$i][4] = 52+$dice_dim
        If $LastDices[$i-1][3] > $LastDices[$i][1] then $LastDices[$i-1][3] = $LastDices[$i][1]
        If (GUICtrlRead($AnimateElements) = $GUI_CHECKED) AND ($LastDices[$i][5] = False) Then
            Local $step = -7
            Local $Correction = 1
            For $z = 52+$dice_dim+$step+$step to 52 Step $step
                _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hbitmap, $width/2-$total_width/2+($i-1)*($dice_dim+$space_between)-$Correction, 52-$Correction, $dice_dim+2*$Correction, _
                                                    $dice_dim+2*$Correction, $width/2-$total_width/2+($i-1)*($dice_dim+$space_between)-$Correction, $z-$Correction, $dice_dim+2*$Correction, (52+$dice_dim)-$z+2*$Correction)
                Sleep(1)
            Next
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
        EndIf
    Next
    _DrawOrDeleteEdgesDice($HotPen3, True, $HotBrush)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
    $Total = StringTrimRight($Total, 2)
    GUICtrlSetData($DicesThrownLabel, 'Thrown dice(s): ' & $Total)
    $DicesOn = False
EndFunc

Func _DrawDices($DiceNumb, $iX, $iY, $iWidth, $iHeight = $iWidth, $NoBlackCurve = False)
    Local $SpotSize = 10
    Local $aPoints[5][2]
    Local $reduction = 6
    $aPoints[0][0] = 4
    $aPoints[1][0] = $iX+$reduction
    $aPoints[1][1] = $iY+$reduction
    $aPoints[2][0] = $iX+$iWidth-$reduction
    $aPoints[2][1] = $iY+$reduction
    $aPoints[3][0] = $iX+$iWidth-$reduction
    $aPoints[3][1] = $iY+$iHeight-$reduction
    $aPoints[4][0] = $iX+$reduction
    $aPoints[4][1] = $iY+$iHeight-$reduction
    _GDIPlus_GraphicsFillClosedCurve($backbuffer, $aPoints, $BrushWhite)
    If $NoBlackCurve = False then _GDIPlus_GraphicsDrawClosedCurve($backbuffer, $aPoints)
    Switch $DiceNumb
        Case 1
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$iWidth/2-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
        Case 2
            Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/3)^2)/2))
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
        Case 3
            Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/4)^2)/2))
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$iWidth/2-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
        Case 4
            Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/4)^2)/2))
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
        Case 5
            Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/4)^2)/2))
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$iWidth/2-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
        Case 6
            Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/4)^2)/2))
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$iWidth-$a_side-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
            _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack)
    EndSwitch
EndFunc

Func _DrawCards()
    If $CardsOn = True then Return 0
    $CardsOn = True
    If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Windows Pop-up Blocked.wav")
    Local $number_of_cards = GUICtrlRead($CardsNumber)
    If $number_of_cards < 1 Then
        MsgBox(0, 'Error', 'Your number of cards is invalid')
        $CardsOn = False
        Return 0
    EndIf
    If GUICtrlRead($DecksNumber) < 1 Then
        MsgBox(0, 'Error', 'Invalid number of card decks')
        $CardsOn = False
        Return 0
    EndIf
    Local $Total = ''
    Local $space_between = 8
    Local $card_dim = 80
    Local $total_width = $number_of_cards*$card_dim+($number_of_cards-1)*$space_between
    If $total_width > $width-20 Then
        Do
            $space_between -= 1
            $total_width = $number_of_cards*$card_dim+($number_of_cards-1)*$space_between
        Until $total_width < $width-20
        _GDIPlus_StringFormatSetAlign($hFormat, 0)
        $CardsOverLap = True
    Else
        $CardsOverLap = False
    EndIf
    Local $layOut
    Dim $DrawnCard[3]
    Local $TotalBlacks = 0
    _GDIPlus_GraphicsFillRect($backbuffer, 6, $CardSetHeight+78, $width-13, $card_dim+$card_dim/2+8, $BackgroundBrush)
    If UBound($LastCards)-1 <> $number_of_cards then
        ReDim $LastCards[$number_of_cards+1][8]
        For $i = 1 to $number_of_cards
            $LastCards[$i][7] = False
        Next
    Else
        For $i = 1 to $number_of_cards
            If $LastCards[$i][7] = True then
                If $CardsOverLap = True Then
                    If $i = $number_of_cards Then
                        _GDIPlus_StringFormatSetAlign($hFormat, 1)
                    EndIf
                EndIf
                _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2, $BrushWhite)
                $layOut = _GDIPlus_RectFCreate ($LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2)
                If $LastCards[$i][2] < 3 then
                    _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$i][0] & @CRLF & $LastCards[$i][1], $hFont, $layOut, $hFormat, $BrushBlack)
                    $TotalBlacks += 1
                Else
                    _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$i][0] & @CRLF & $LastCards[$i][1], $hFont, $layOut, $hFormat, $BrushRed)
                EndIf
                _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2)
                _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2, $HotBrush)
                _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2, $HotPen3)
            EndIf
        Next
    EndIf
    If $CardsOverLap = True then _GDIPlus_StringFormatSetAlign($hFormat, 0)
    For $i = 1 to $number_of_cards
        If $i = $number_of_cards then _GDIPlus_StringFormatSetAlign($hFormat, 1)

        If $LastCards[$i][7] = True then
            ReDim $DrawnCard[3]
            $DrawnCard[0] = $LastCards[$i][0]
            $DrawnCard[1] = $LastCards[$i][1]
            $DrawnCard[2] = $Lastcards[$i][2]
        Else
            $DrawnCard = _GetCard()
            $LastCards[$i][0] = $DrawnCard[0]
            $LastCards[$i][1] = $DrawnCard[1]
            $LastCards[$i][2] = $DrawnCard[2]
        EndIf

        $LastCards[$i][3] = $width/2-$total_width/2+($i-1)*($card_dim+$space_between)
        $LastCards[$i][4] = $CardSetHeight+82
        $LastCards[$i][5] = $width/2-$total_width/2+($i-1)*($card_dim+$space_between)+$card_dim
        $LastCards[$i][6] = $CardSetHeight+82+$card_dim+$card_dim/2
        If $LastCards[$i-1][5] > $LastCards[$i][3] then $LastCards[$i-1][5] = $LastCards[$i][3]

        $Total &= $DrawnCard[0] & $DrawnCard[1] & ', '
        If (GUICtrlRead($AnimateElements) = $GUI_CHECKED) AND ($LastCards[$i][7] = False) then
            Local $step = -20
            For $z = $CardSetHeight+82+$card_dim+$card_dim/2+$step to $CardSetHeight+82 step $step
                _GDIPlus_GraphicsFillRect ($backbuffer, $width/2-$total_width/2+($i-1)*($card_dim+$space_between), $z, $card_dim, ($CardSetHeight+82+$card_dim+$card_dim/2)-$z, $BrushWhite)
                $layOut = _GDIPlus_RectFCreate ($width/2-$total_width/2+($i-1)*($card_dim+$space_between), $z, $card_dim, ($CardSetHeight+82+$card_dim+$card_dim/2)-$z)
                If $DrawnCard[2] < 3 then
                    _GDIPlus_GraphicsDrawStringEx ($backbuffer, $DrawnCard[0] & @CRLF & $DrawnCard[1], $hFont, $layOut, $hFormat, $BrushBlack)
                Else
                    _GDIPlus_GraphicsDrawStringEx ($backbuffer, $DrawnCard[0] & @CRLF & $DrawnCard[1], $hFont, $layOut, $hFormat, $BrushRed)
                EndIf
                _GDIPlus_GraphicsDrawRect ($backbuffer, $width/2-$total_width/2+($i-1)*($card_dim+$space_between), $z, $card_dim, ($CardSetHeight+82+$card_dim+$card_dim/2)-$z)
                _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
                Sleep(1)
            Next
        EndIf
        If $LastCards[$i][7] = False then
            _GDIPlus_GraphicsFillRect ($backbuffer, $width/2-$total_width/2+($i-1)*($card_dim+$space_between), $CardSetHeight+82, $card_dim, $card_dim+$card_dim/2, $BrushWhite)
            $layOut = _GDIPlus_RectFCreate ($width/2-$total_width/2+($i-1)*($card_dim+$space_between), $CardSetHeight+82, $card_dim, $card_dim+$card_dim/2)
            If $DrawnCard[2] < 3 then
                _GDIPlus_GraphicsDrawStringEx ($backbuffer, $DrawnCard[0] & @CRLF & $DrawnCard[1], $hFont, $layOut, $hFormat, $BrushBlack)
                $TotalBlacks += 1
            Else
                _GDIPlus_GraphicsDrawStringEx ($backbuffer, $DrawnCard[0] & @CRLF & $DrawnCard[1], $hFont, $layOut, $hFormat, $BrushRed)
            EndIf
            _GDIPlus_GraphicsDrawRect ($backbuffer, $width/2-$total_width/2+($i-1)*($card_dim+$space_between), $CardSetHeight+82, $card_dim, $card_dim+$card_dim/2)
        EndIf
    Next
    _DrawOrDeleteEdgesCards($hotpen3, True, $HotBrush)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
    $Total = StringTrimRight($Total, 2)
    GUICtrlSetData($CardsDrawnLabel, 'Drawn card(s): ' & $Total)
    GUICtrlSetColor($CardsDrawnLabel, '0x' & Hex(Round(204-(204/$number_of_cards)*$TotalBlacks), 2) & '0000')
    $CardsOn = False
EndFunc

Func _GetCard()
    Local $CardChars[5] = ['', ChrW(9824), ChrW(9827), ChrW(9829), ChrW(9830)]
    Local $i_deckCount = GUICtrlRead($DecksNumber)
    Local $ret_Val[3]
    Local $resultet_Number, $resultet_sign
    Local $4Signs
    Local $Satisfied = False
    Do
        _AllCardsPickedCheck()
        $resultet_Number = _GenerateRandomNumbers(UBound($CardsArray)-1, UBound($CardsArray)-1, 1)
        If NOT @error then
            For $i = 0 to UBound($resultet_Number)-1
                $4Signs = _GenerateRandomNumbers(4, 4, 1)
                If NOT @error then
                    For $j = 0 to 3
                        If $CardsArray[$resultet_Number[$i]][$4Signs[$j]] < $i_deckCount Then
                            $ret_Val[0] = $CardsArray[$resultet_Number[$i]][0]
                            $ret_Val[1] = $CardChars[$4Signs[$j]]
                            $ret_Val[2] = $4Signs[$j]
                            $CardsArray[$resultet_Number[$i]][$4Signs[$j]] += 1
                            $Satisfied = True
                            ExitLoop
                        EndIf
                    Next
                EndIf
                If $Satisfied = True then ExitLoop
            Next
            _AllCardsPickedCheck()
        EndIf
    Until $Satisfied = True
    Return $ret_Val
EndFunc

Func _GenerateRandomNumbers($iGenerateNums, $iMaxEachNum, $iMinEachNum = 0)
    If $iGenerateNums > ($iMaxEachNum - $iMinEachNum) + 1 Then Return SetError(1, 0, 0)

    Local $aRandom[$iGenerateNums]

    For $i = 0 To $iGenerateNums - 1
        While True
            $aRandom[$i] = Random($iMinEachNum, $iMaxEachNum, 1)

            For $j = 0 To $iGenerateNums - 1
                If $j <> $i Then
                    If $aRandom[$j] = $aRandom[$i] Then ContinueLoop 2
                EndIf
            Next

            ExitLoop
        WEnd
    Next

    Return $aRandom
EndFunc   ;==>_GenerateRandomNumbers

Func _AllCardsPickedCheck()
    Local $Check4DrawnCards = False
    Local $Filled = True
    Local $i_deckCount = GUICtrlRead($DecksNumber)
    Local $TotalCardsDrawn
    If $Check4DrawnCards = True Then $TotalCardsDrawn = 'Card:' & @TAB & _
                                    ChrW(9824) & @TAB & ChrW(9827) & @TAB & _
                                    ChrW(9829) & @TAB & ChrW(9830) & @CRLF & _
                                    '----------------------------------' & @CRLF
    For $i = 1 to UBound($CardsArray)-1
        $TotalCardsDrawn &= $CardsArray[$i][0]
        For $j = 1 to 4
            If $CardsArray[$i][$j] < $i_deckCount then
                $Filled = False
                If $Check4DrawnCards = False then ExitLoop
            EndIf
            If $Check4DrawnCards = True Then $TotalCardsDrawn &= @TAB & $CardsArray[$i][$j]
        Next
        If $Check4DrawnCards = True Then $TotalCardsDrawn &= @CRLF
    Next
    If $Check4DrawnCards = True Then ClipPut($TotalCardsDrawn)
    If $Filled = True then _ResetCards()
EndFunc

Func _ResetCards()
    For $i = 0 to UBound($CardsArray)-1
        $CardsArray[$i][1] = 0
        $CardsArray[$i][2] = 0
        $CardsArray[$i][3] = 0
        $CardsArray[$i][4] = 0
        For $z = 1 to UBound($Lastcards)-1
            If $Lastcards[$z][7] = True Then
                If $CardsArray[$i][0] = $Lastcards[$z][0] Then
                    $CardsArray[$i][$Lastcards[$z][2]] += 1
                EndIf
            EndIf
        Next
    Next
EndFunc

Func _Form_Cards_Array(ByRef $CardAr, $type)
    If $type = 0 Then
        Local $AllCards[14] = ['', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
        ReDim $CardAr[14][5]
    ElseIf $type = 1 Then
        Local $AllCards[9] = ['', 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
        ReDim $CardAr[9][5]
    EndIf
    For $i = 0 to UBound($AllCards)-1
        $CardAr[$i][0] = $AllCards[$i]
        $CardAr[$i][1] = 0
        $CardAr[$i][2] = 0
        $CardAr[$i][3] = 0
        $CardAr[$i][4] = 0
    Next
EndFunc

Func QuitApplication()
    _Save_All_Data()
    _WinAPI_DeleteObject($hbitmap)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BrushDispose($BrushBlack)
    _GDIPlus_BrushDispose($HotBrush)
    _GDIPlus_BrushDispose($BrushRed)
    _GDIPlus_BrushDispose($BrushWhite)
    _GDIPlus_BrushDispose($BackgroundBrush)
    _GDIPlus_PenDispose ($HotPen2)
    _GDIPlus_PenDispose ($HotPen3)
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc

Func _MixCards()
    ReDim $LastCards[UBound($Lastcards)][8]
    For $i = 1 to UBound($Lastcards)-1
        For $z = 0 to 6
            $Lastcards[$i][$z] = -1
        Next
        $Lastcards[$i][7] = False
    Next
    _ResetCards()
    Local $card_dim = 80
    _GDIPlus_GraphicsFillRect($backbuffer, 6, $CardSetHeight+78, $width-13, $card_dim+$card_dim/2+8, $BackgroundBrush)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
EndFunc

Func _Save_All_Data()
    IniWrite($IniFile, 'Dices', 'Number', GUICtrlRead($DiceNumber))
    IniWrite($IniFile, 'Cards', 'Number', GUICtrlRead($CardsNumber))
    IniWrite($IniFile, 'Cards', 'Deck', _GUICtrlComboBox_GetCurSel($DeckType))
    IniWrite($IniFile, 'Cards', 'DeckNumber', GUICtrlRead($DecksNumber))
    IniWrite($IniFile, 'Options', 'Sound', GUICtrlRead($PlaySounds))
    IniWrite($IniFile, 'Options', 'Animate', GUICtrlRead($AnimateElements))
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $ThrowDices
            _ThrowDices()
        Case $DrawCards
            _DrawCards()
        Case $CloseBUtton
            Exit
        Case $clear_dice_button
            If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Speech Misrecognition.wav")
            For $i = 1 to UBound($LastDices)-1
                $LastDices[$i][5] = False
            Next
            _DrawOrDeleteEdgesDice($HotPen3, True, $HotBrush)
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
        Case $Clear_Cards_Button
            If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Speech Misrecognition.wav")
            For $i = 1 to UBound($Lastcards)-1
                $Lastcards[$i][7] = False
            Next
            _DrawOrDeleteEdgesCards($HotPen3, True, $HotBrush)
            _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
        Case $Mix_Cards_Button
            _MixCards()
    EndSwitch
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndDecks
    If Not IsHWnd($DecksNumber) Then $hWndDecks = GUICtrlGetHandle($DecksNumber)
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $hWndDecks, $DecksNumber
            Switch $iCode
                Case 1024
                    _MixCards()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func MY_PAINT($hWnd, $Msg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height)
    Return $GUI_RUNDEFMSG
EndFunc
Edited by dragan
Link to comment
Share on other sites

Very Nice! I like your generation of Images/Graphix.

Any chance of adding animations for added lolz?

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

Not sure about Bridge, but poker for sure uses all 52 cards - you drop down shows bridge 2-A and poker 7-A (might want to change that?)

2¢

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I modified one of the functions because when I clicked 'Draw Cards' I kept receiving this error: "ContinueLoop" statement with no matching "While", "Do" or "For" statement.:

Func _GenerateRandomNumbers($iGenerateNums, $iMaxEachNum, $iMinEachNum = 0)
    If $iGenerateNums > ($iMaxEachNum - $iMinEachNum) + 1 Then Return SetError(1, 0, 0)

    Local $aRandom[$iGenerateNums]

    For $i = 0 To $iGenerateNums - 1
        While True
            $aRandom[$i] = Random($iMinEachNum, $iMaxEachNum, 1)

            For $j = 0 To $iGenerateNums - 1
                If $j <> $i Then
                    If $aRandom[$j] = $aRandom[$i] Then ContinueLoop 2
                EndIf
            Next

            ExitLoop
        WEnd
    Next

    Return $aRandom
EndFunc   ;==>_GenerateRandomNumbers
Link to comment
Share on other sites

very interesting.

One of the first things that I wanted to do with autoit was make a poker game of my own, in fact I think its how I found myself on this forum to begin with.

As I recall I got as far as selecting random numbers 1 to 14, before realizing how hard it would be to assign them suits, remember those that had been drawn, and deal to multiple players.

Suffice to say, I got distracted, and fell out of love with the idea.

Certainly will have a look at script.

Thanks for sharing.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

@nitekram: Tnx, I dunno why I used 7-A (but again I'm not poker player), changed now to "sevens" - hungarian game (though you should play with hungarian cards but this one can do as well), thank you.

@LaCastiglione: Tnx for assistant, function is changed now.

@JohnOne: Yeah, with multidimensional array it's not so hard to store drawn cards into memory:

Func _Form_Cards_Array(ByRef $CardAr, $type)
    If $type = 0 Then ; 0 = 2 - A
        Local $AllCards[14] = ['', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
        ReDim $CardAr[14][5]
    ElseIf $type = 1 Then ; 1 = 7 - A
        Local $AllCards[9] = ['', 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
        ReDim $CardAr[9][5]
    EndIf
    For $i = 0 to UBound($AllCards)-1
        $CardAr[$i][0] = $AllCards[$i] ;card's number - 2, 3, 4... K, A
        $CardAr[$i][1] = 0 ;number of drawn Spades card
        $CardAr[$i][2] = 0 ;number of drawn Clubs card
        $CardAr[$i][3] = 0 ;number of drawn Hearts card
        $CardAr[$i][4] = 0 ;number of drawn Diamonds card
        ; each time a card is drawn, this number gets higher by 1 (+=1), and if the number reaches
        ; the number of decks then this card will no longer be drawn until all cards are equal to
        ; the number of decks, then each of this gets = 0 again.
    Next
EndFunc

I guess now (after I reached 5 posts) I can change and edit my older posts.

Edited by dragan
Link to comment
Share on other sites

Excellent! The new animations make all the difference. Easter egg time?

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to comment
Share on other sites

Very nice looking, but I think the cards needs a little work. I seem to draw the same card twice frequently (ie, two 10 of ♥ or two 6 of ♦). Once again, looks great.

Spoiler

Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder
Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array
Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc
Cool Stuff: AutoItObject UDF â—Š Extract Icon From Proc â—Š GuiCtrlFontRotate â—Š Hex Edit Funcs â—Š Run binary â—Š Service_UDF

 

Link to comment
Share on other sites

that's just coincidence, I think you draw some card, and then reach the end of the deck, cards get mixed, and you draw same card.

replace this function with the one in the script:

Func _AllCardsPickedCheck()
    Local $Check4DrawnCards = True
    Local $Filled = True
    Local $i_deckCount = GUICtrlRead($DecksNumber)
    Local $TotalCardsDrawn
    If $Check4DrawnCards = True Then $TotalCardsDrawn = 'Card:' & @TAB & _
                                    ChrW(9824) & @TAB & ChrW(9827) & @TAB & _
                                    ChrW(9829) & @TAB & ChrW(9830) & @CRLF & _
                                    '----------------------------------' & @CRLF
    For $i = 1 to UBound($CardsArray)-1
        $TotalCardsDrawn &= $CardsArray[$i][0]
        For $j = 1 to 4
            If $CardsArray[$i][$j] < $i_deckCount then
                $Filled = False
                If $Check4DrawnCards = False then ExitLoop
            EndIf
            If $Check4DrawnCards = True Then $TotalCardsDrawn &= @TAB & $CardsArray[$i][$j]
        Next
        If $Check4DrawnCards = True Then $TotalCardsDrawn &= @CRLF
    Next
    If $Check4DrawnCards = True Then ClipPut($TotalCardsDrawn)
    If $Filled = True then _ResetCards()
EndFunc

and use notepad or whatever to paste the data after each card drawing to see that the card isn't repeating.

Edited by dragan
Link to comment
Share on other sites

that's just coincidence, I think you draw some card, and then reach the end of the deck, cards get mixed, and you draw same card.

replace this function with the one in the script:

Func _AllCardsPickedCheck()
    Local $Check4DrawnCards = True
    Local $Filled = True
    Local $i_deckCount = GUICtrlRead($DecksNumber)
    Local $TotalCardsDrawn
    If $Check4DrawnCards = True Then $TotalCardsDrawn = 'Card:' & @TAB & _
                                    ChrW(9824) & @TAB & ChrW(9827) & @TAB & _
                                    ChrW(9829) & @TAB & ChrW(9830) & @CRLF & _
                                    '----------------------------------' & @CRLF
    For $i = 1 to UBound($CardsArray)-1
        $TotalCardsDrawn &= $CardsArray[$i][0]
        For $j = 1 to 4
            If $CardsArray[$i][$j] < $i_deckCount then
                $Filled = False
                If $Check4DrawnCards = False then ExitLoop
            EndIf
            If $Check4DrawnCards = True Then $TotalCardsDrawn &= @TAB & $CardsArray[$i][$j]
        Next
        If $Check4DrawnCards = True Then $TotalCardsDrawn &= @CRLF
    Next
    If $Check4DrawnCards = True Then ClipPut($TotalCardsDrawn)
    If $Filled = True then _ResetCards()
EndFunc

and use notepad or whatever to paste the data after each card drawing to see that the card isn't repeating.

Looks better...could've just said replace

Local $Check4DrawnCards = False

with

Local $Check4DrawnCards = True
Spoiler

Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder
Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array
Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc
Cool Stuff: AutoItObject UDF â—Š Extract Icon From Proc â—Š GuiCtrlFontRotate â—Š Hex Edit Funcs â—Š Run binary â—Š Service_UDF

 

Link to comment
Share on other sites

Check4DrawnCards var. wasn't there, I've added it to the 1st post after I posted the function for you to test drawn cards in my previous post ;)

Sorry to have caused misunderstanding :) And I'm glad you like the looks of it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...