Diablo Posted June 18, 2006 Share Posted June 18, 2006 (edited) Hi guys I got bored one day and made a blackjack game. Hope you all like it. Suggestions are welcome, and report them bugs if any. Blackjack.au3 Edit 1 : Switched to using card.dll & script now remembers your name. Edit 2 : Added Repaint function Edit 3 : Fixed minor bug. Edit 4 : Credits to Zedna for fixing the flicker problem and his suggestions. Fixed another bug with the aces calculation. Previous downloads : 33 Edited June 20, 2006 by Diablo [u]Blackjack[/u] ^.^MasterMind =D Link to comment Share on other sites More sharing options...
themax90 Posted June 18, 2006 Share Posted June 18, 2006 (edited) I did also. Here is the link: http://www.autoitscript.com/forum/index.ph...pe=post&id=3756Mine has 8132 downloads. Edited June 18, 2006 by AutoIt Smith Link to comment Share on other sites More sharing options...
Zedna Posted June 18, 2006 Share Posted June 18, 2006 (edited) Hi guys I got bored one day and made a blackjack game. Hope you all like it. Suggestions are welcome, and report them bugs if any. Nice 1) You can remember name of player in INI file 2) you can use existing Microsoft DLL cards.dll - it's in WINDOWS/SYSTEM directory I googled it and found some usefull links, for example: How to use cards.dll Programming for Fun and Profit - Using the Card.dll then you needn't create your own cards images... EDIT: Search in this forum for cards.dll (in quotes) there are AU3 examples of using it. Edited June 18, 2006 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Diablo Posted June 18, 2006 Author Share Posted June 18, 2006 Thanks for the suggestions guys =D Updated the script. 1 problem though, the cards dont seem to repaint themselves after they have been covered by another window, anyway to get them to show again? [u]Blackjack[/u] ^.^MasterMind =D Link to comment Share on other sites More sharing options...
Simucal Posted June 18, 2006 Share Posted June 18, 2006 Thanks for the suggestions guys =DUpdated the script.1 problem though, the cards dont seem to repaint themselves after they have been covered by another window, anyway to get them to show again?I suppose... have them redrawn in your main loop each time. AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
Zedna Posted June 18, 2006 Share Posted June 18, 2006 Thanks for the suggestions guys =D Updated the script. 1 problem though, the cards dont seem to repaint themselves after they have been covered by another window, anyway to get them to show again? Here is my some improvement: - instead of three GUICtrlCreateLabel & $WS_BORDER now 3x cdtDraw - implemented WM_PAINT - but only for 3 cards in left upper corner in WM_PAINT should be also painting of other cards, this can be done via memorydc like in script clock.au3 from this post expandcollapse popup; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.1.0 ; Author: DiabloTM ; ; Script Function: Just another blackjack game. ; ; ("\(o.O)/") ; ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <GUIConstants.au3> #NoTrayIcon Opt("ColorMode", 1) ; == GUI generated with Koda == $Form1 = GUICreate("Blackjack", 493, 512, 189, 179) ;~ GUICtrlCreateLabel("", 40, 24, 67, 105, BitOR($SS_CENTER, $SS_RIGHT, $SS_BLACKRECT, $SS_GRAYRECT, $SS_WHITERECT, $SS_BLACKFRAME, $WS_BORDER)) ;~ GUICtrlCreateLabel("", 32, 16, 67, 105, BitOR($SS_CENTER, $SS_RIGHT, $SS_BLACKRECT, $SS_GRAYRECT, $SS_WHITERECT, $SS_BLACKFRAME, $WS_BORDER)) ;~ GUICtrlCreateLabel("", 48, 32, 67, 105, BitOR($SS_BLACKRECT, $WS_BORDER)) $btnNew = GUICtrlCreateButton("New Game", 190, 180, 100, 30) $btnHit = GUICtrlCreateButton("Hit", 190, 230, 50, 30) $btnStay = GUICtrlCreateButton("Stay", 240, 230, 50, 30) $score = GUICtrlCreateLabel("", 85, 435, 100, 30, BitOR($SS_CENTER, $WS_BORDER, $SS_SUNKEN)) GUICtrlSetFont(-1, 18) GUICtrlSetColor(-1, 0x00C100) $comScore = GUICtrlCreateLabel("", 305, 435, 100, 30, BitOR($SS_CENTER, $WS_BORDER, $SS_SUNKEN)) GUICtrlSetFont(-1, 18) GUICtrlSetColor(-1, 0x00C100) $name = GUICtrlCreateLabel("", 160, 32, 110, 105) GUICtrlSetData($name, IniRead("Blackjack.ini", "Name", "Name", "Player")) GUICtrlSetFont(-1, 18, 400, 6, "Comic Sans MS") GUICtrlSetColor(-1, 0x4E13FD) GUICtrlCreateLabel("Computer", 330, 32, 110, 105) GUICtrlSetFont(-1, 18, 400, 6, "Comic Sans MS") GUICtrlSetColor(-1, 0xCC7A37) $gamesWon = GUICtrlCreateLabel("0", 190, 70, 110, 105) GUICtrlSetFont(-1, 18, 400, 2, "Comic Sans MS") GUICtrlSetColor(-1, 0x4E13FD) $comGamesWon = GUICtrlCreateLabel("0", 360, 70, 110, 105) GUICtrlSetFont(-1, 18, 400, 2, "Comic Sans MS") GUICtrlSetColor(-1, 0xCC7A37) $hDLL = DLLOpen("cards.dll") $hdc = DllCall("user32.dll","int","GetDC","hwnd",$Form1) $hdc = $hdc[0] DLLCall($hDLL,"int","cdtInit","int_ptr",0,"int_ptr",0) $NoOfCards = 0 $drawn = 0 $ace = 0 Dim $cards[52] $i = 0 $noGamesWon = 0 $comNoOfCards = 0 $comDrawn = 0 $comAce = 0 Dim $comCards[52] $comI = 0 $comNoGamesWon = 0 Global Const $WM_PAINT = 0x000F GUIRegisterMsg($WM_PAINT, 'MY_WM_PAINT') GUISetState(@SW_SHOW) Func MY_WM_PAINT($hwnd, $msg, $wparam, $lparam) ;~ If $hwnd = $Form1 Then Switch $msg Case $WM_PAINT _Paint() Return EndSwitch ;~ EndIf Return $GUI_RUNDEFMSG EndFunc Func _Paint() DLLCall($hDLL,"int","cdtDraw","int",$hdc,"int", 32,"int", 16,"int", 53,"int",1,"int", 0x0000ff) DLLCall($hDLL,"int","cdtDraw","int",$hdc,"int", 40,"int", 24,"int", 53,"int",1,"int", 0x00ff00) DLLCall($hDLL,"int","cdtDraw","int",$hdc,"int", 48,"int", 32,"int", 53,"int",1,"int", 0xff0000) EndFunc While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $btnHit GUICtrlSetState($btnNew, $GUI_DISABLE) $draw = Random(1, 13, 1) $drawCard = $draw * 4 - 1 - Random(0, 3, 1) DLLCall($hDLL,"int","cdtDraw","int",$hdc,"int", 50 + ($NoOfCards * 40),"int", 320,"int", $drawCard,"int",0,"int", 0xffffff) If $draw = 11 Or $draw = 12 Or $draw = 13 Then $draw = 10 If $draw = 1 Then $draw = 11 $ace = $ace + 1 EndIf $NoOfCards = $NoOfCards + 1 $drawn = $draw + $drawn If $drawn > 21 Then ;Check for aces. If $ace > 0 Then $drawn = $drawn - 10 $ace = $ace - 1 Else $winmove = WinGetPos("Blackjack") SplashTextOn("Game Over", @LF & "Game Over", 493, 120, $winmove[0] + 2, $winmove[1] + 45, 35, "Comic Sans MS", 22) GUICtrlSetState($btnNew, $GUI_ENABLE) GUICtrlSetState($btnHit, $GUI_DISABLE) GUICtrlSetState($btnStay, $GUI_DISABLE) $comNoGamesWon = $comNoGamesWon + 1 GUICtrlSetData($comGamesWon, $comNoGamesWon) EndIf EndIf GUICtrlSetData($score, $drawn) Case $msg = $btnStay Do $comDraw = Random(1, 13, 1) $comDrawCard = $comDraw * 4 - 1 - Random(0, 3, 1) DLLCall($hDLL,"int","cdtDraw","int",$hdc,"int", 270 + ($comNoOfCards * 40),"int", 320,"int", $comDrawCard,"int",0,"int", 0xffffff) If $comDraw = 11 Or $comDraw = 12 Or $comDraw = 13 Then $comDraw = 10 If $comDraw = 1 Then $comDraw = 11 $comAce = $comAce + 1 EndIf $comNoOfCards = $comNoOfCards + 1 $comDrawn = $comDraw + $comDrawn If $drawn > 21 Then ;Check for aces. If $comAce > 0 Then $comDrawn = $comDrawn - 10 $comAce = $comAce - 1 EndIf EndIf GUICtrlSetData($comScore, $comDrawn) until (($comDrawn > 16) Or ($comDrawn > $drawn)) If $drawn > $comDrawn Then $winmove = WinGetPos("Blackjack") SplashTextOn("You Win", @LF & "You Win", 493, 120, $winmove[0] + 2, $winmove[1] + 45, 35, "Comic Sans MS", 22) GUICtrlSetState($btnNew, $GUI_ENABLE) GUICtrlSetState($btnHit, $GUI_DISABLE) GUICtrlSetState($btnStay, $GUI_DISABLE) $noGamesWon = $noGamesWon + 1 GUICtrlSetData($gamesWon, $noGamesWon) ElseIf $drawn = $comDrawn Then $winmove = WinGetPos("Blackjack") SplashTextOn("Its a Tie", @LF & "Its a Tie", 493, 120, $winmove[0] + 2, $winmove[1] + 45, 35, "Comic Sans MS", 22) GUICtrlSetState($btnNew, $GUI_ENABLE) GUICtrlSetState($btnHit, $GUI_DISABLE) GUICtrlSetState($btnStay, $GUI_DISABLE) ElseIf $comDrawn < 22 Then $winmove = WinGetPos("Blackjack") SplashTextOn("You Lose", @LF & "You Lose", 493, 120, $winmove[0] + 2, $winmove[1] + 45, 35, "Comic Sans MS", 22) GUICtrlSetState($btnNew, $GUI_ENABLE) GUICtrlSetState($btnHit, $GUI_DISABLE) GUICtrlSetState($btnStay, $GUI_DISABLE) $comNoGamesWon = $comNoGamesWon + 1 GUICtrlSetData($comGamesWon, $comNoGamesWon) Else ;com goes bust o.O $winmove = WinGetPos("Blackjack") SplashTextOn("You Win", @LF & "You Win", 493, 120, $winmove[0] + 2, $winmove[1] + 45, 35, "Comic Sans MS", 22) GUICtrlSetState($btnNew, $GUI_ENABLE) GUICtrlSetState($btnHit, $GUI_DISABLE) GUICtrlSetState($btnStay, $GUI_DISABLE) $noGamesWon = $noGamesWon + 1 GUICtrlSetData($gamesWon, $noGamesWon) EndIf Case $msg = $btnNew $NoOfCards = 0 $drawn = 0 $ace = 0 $comI = 0 $comNoOfCards = 0 $comDrawn = 0 $comAce = 0 GUICtrlSetData($score, "") GUICtrlSetData($comScore, "") GUICtrlSetState($btnHit, $GUI_ENABLE) GUICtrlSetState($btnStay, $GUI_ENABLE) SplashOff() $WinGetPos = WinGetPos("Blackjack") WinMove("Blackjack", "", -493, -512) WinMove("Blackjack", "", $WinGetPos[0], $WinGetPos[1]) Case $msg = $name $winmove = WinGetPos("Blackjack") $PlayerName = InputBox("Name", "Enter your name", "", " M8", -1, 80, $winmove[0] + 120, $winmove[1] + 210) if $PlayerName = "" Then Else GUICtrlSetData($name, $PlayerName) IniWrite ( "Blackjack.ini", "Name", "Name", $PlayerName) EndIf EndSelect WEnd Func OnAutoItExit ( ) DLLCall($hDLL,"none","cdtTerm") DLLClose($hDLL) DLLCall("user32.dll","int","ReleaseDC","hwnd",$Form1,"int",$hdc) EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted June 18, 2006 Share Posted June 18, 2006 One important note: On WIN9x you must use cards.dll from WIN2000/XP (it's 32bit) because this one from WIN9x is 16bit. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
RazerM Posted June 18, 2006 Share Posted June 18, 2006 This game is good. My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
Diablo Posted June 19, 2006 Author Share Posted June 19, 2006 @Zedna Thx for the tip. Updated. [u]Blackjack[/u] ^.^MasterMind =D Link to comment Share on other sites More sharing options...
Valuater Posted June 19, 2006 Share Posted June 19, 2006 Nice 8) Link to comment Share on other sites More sharing options...
Zedna Posted June 19, 2006 Share Posted June 19, 2006 (edited) Hi DiabloI have some good news for you 1) I found great web about using cards.dll: http://www.publicjoe.f9.co.uk/csharp/card00.html - for example how to rotate cards, ...2) Here is cards.dll from Windows 2000 packed by UPX: Cards.zipIt's because images for back of cards are diferrent in WIN2000/WINXPHere is your script with my corrections:3) changed code for backs of cards to 54 - for 3 cards in left top corner (for yse with DLL from WIN2000):4) in _RePaint() implemented painting to memory DC and then BitBlt whole image to Window DC- it's very good "antiflicker" method of painting5) In button "New Game" replaced that your ugly WinMove() code by DLLCall & InvalidateRectBlackjack_zedna.zipEDIT: First suggestion: instead of SplashText use some Label (Hide/Show) with bold and color and transparent background ...Second suggestion: use 0x008000 for background color. In card games it looks better (and change color of labels with points to some other color - not green)Your script is really good and I like to improve it Edited June 19, 2006 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Diablo Posted June 20, 2006 Author Share Posted June 20, 2006 rotate cards? hmm.. Anyway the script is updated, check out first post. And thx Zedna, i took up your suggestions. [u]Blackjack[/u] ^.^MasterMind =D Link to comment Share on other sites More sharing options...
Zedna Posted June 20, 2006 Share Posted June 20, 2006 (edited) rotate cards? hmm.. Anyway the script is updated, check out first post. And thx Zedna, i took up your suggestions. Now it's really game that I like to play One cosmetic thing: When there are many of cards with small points in one game, then it could go too right like in this screenshot. The same is for place for computer's cards. Solution is to place cards with smaller difference or increase form width or have cards for player and computer up/down instead of left/rigth (two columns of cards or two rows of cards one below other) Edited June 20, 2006 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
greenmachine Posted June 20, 2006 Share Posted June 20, 2006 Just so you guys know, the dealer in BlackJack always stops at 17 or higher - they do not try to get higher than the player. Thus, when the player has 18 and the dealer has 17, the dealer stops. It does not try to hit again (potentially getting a 2, 3, or 4 to win). The code fix is really simple, but I just thought you should know. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now