SkellySoul Posted March 3, 2011 Share Posted March 3, 2011 Hello I was wondering if someone could please help me fix a few things. I would like to change this: expandcollapse popupWhile 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Letter[65] _Use_Letter(65 , $Word) Case $Letter[66] _Use_Letter(66 , $Word) Case $Letter[67] _Use_Letter(67 , $Word) Case $Letter[68] _Use_Letter(68 , $Word) Case $Letter[69] _Use_Letter(69 , $Word) Case $Letter[70] _Use_Letter(70 , $Word) Case $Letter[71] _Use_Letter(71 , $Word) Case $Letter[72] _Use_Letter(72 , $Word) Case $Letter[73] _Use_Letter(73 , $Word) Case $Letter[74] _Use_Letter(74 , $Word) Case $Letter[75] _Use_Letter(75 , $Word) Case $Letter[76] _Use_Letter(76 , $Word) Case $Letter[77] _Use_Letter(77 , $Word) Case $Letter[78] _Use_Letter(78 , $Word) Case $Letter[79] _Use_Letter(79 , $Word) Case $Letter[80] _Use_Letter(80 , $Word) Case $Letter[81] _Use_Letter(81 , $Word) Case $Letter[82] _Use_Letter(82 , $Word) Case $Letter[83] _Use_Letter(83 , $Word) Case $Letter[84] _Use_Letter(84 , $Word) Case $Letter[85] _Use_Letter(85 , $Word) Case $Letter[86] _Use_Letter(86 , $Word) Case $Letter[87] _Use_Letter(87 , $Word) Case $Letter[88] _Use_Letter(88, $Word) Case $Letter[89] _Use_Letter(89 , $Word) Case $Letter[90] _Use_Letter(90 , $Word) EndSwitch WEnd To something like this: While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Letter[65] To $Letter[90] _Use_Letter($Letter[???] , $Word) ;Can't figure out which one is clicked. EndSwitch I would like to also change this: _Gen_Word("Hello") Func _Gen_Word($Gen) $Gen_Length = StringLen($Gen) $Blank[1] = "_" $Blank[2] = "_ _" $Blank[3] = "_ _ _" $Blank[4] = "_ _ _ _" $Blank[5] = "_ _ _ _ _" $Blank[6] = "_ _ _ _ _ _" $Blank[7] = "_ _ _ _ _ _ _" $Blank[8] = "_ _ _ _ _ _ _ _" $Blank[9] = "_ _ _ _ _ _ _ _ _" $Blank[10] = "_ _ _ _ _ _ _ _ _ _" $Blank[11] = "_ _ _ _ _ _ _ _ _ _ _" $Blank[12] = "_ _ _ _ _ _ _ _ _ _ _ _" GUICtrlSetData($Text , $Blank[$Gen_Length]) EndFunc To something like this: _Gen_Word("Hello") Func _Gen_Word($Gen) $Gen_Length = StringLen($Gen) Loop Start: $Blanks = $Blanks & "_" Loop Until: Loop = $Gen_Length GUICtrlSetData($Text , $Blank[$Gen_Length]) EndFunc I also have a big problem that I will post after. Link to comment Share on other sites More sharing options...
myk3 Posted March 3, 2011 Share Posted March 3, 2011 (edited) I can help with this one.. I think_Gen_Word("HELLO") Func _Gen_Word($Gen) $blanks ="" $text = "Boo" $1 = 1 $Gen_Length = StringLen($Gen) do $blanks = $blanks & " _ " $1 += 1 Until $1 -1 = $Gen_Length GUICtrlSetData($Text , $Blank,$Gen_Length) EndFuncI am by far no expert but i'm not sure there is a value assigned to the other one.. " Case $Letter[65] To $Letter[90]" just by reading how the "to" expression work.. Since it is measuring if the statement is true or not, not what the value is.. Basically the script is "Short-Circuiting" since the value is true when the user inputs "66" and then stops.. Again i may be wrong but i don't think the value is saved.. Edited March 3, 2011 by myk3 Link to comment Share on other sites More sharing options...
SkellySoul Posted March 3, 2011 Author Share Posted March 3, 2011 (edited) Thanks very much that worked and I think you are right about the "Case X To Y" and not being able to read what one was pressed, but really just wanted to shorten the code. Anyways I attached the resources and the script and if you run it you can see the problem when you try and guess letters. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $Word , $Blanks , $Letter[100] $Hang = 0 $Width = 800 $Height = 500 $Font = "Comic Sans MS" $Resource = @ScriptDir & "\Resources" $Word = "Hello" $Hangman = GUICreate("Hangman", $Width, $Height) GUISetBkColor(0xD0BE68, $Hangman) $Background = GUICtrlCreatePic($Resource & "\Background.bmp" , 0, 0, $Width, $Height) $Head = GUICtrlCreatePic("" , 115, 180, 100, 64) $Torso = GUICtrlCreatePic("" , 145, 244, 40, 61) $Left_Arm = GUICtrlCreatePic("" , 127, 250, 18, 41) $Right_Arm = GUICtrlCreatePic("" , 185, 250, 18, 41) $Pants = GUICtrlCreatePic("" , 147, 305, 36, 20) $Left_Leg = GUICtrlCreatePic("" , 139, 325, 25, 35) $Right_Leg = GUICtrlCreatePic("" , 166, 325, 25, 35) $Text = GUICtrlCreateLabel("" , 0 , 50 , $Width, 50, $SS_CENTER) GUICtrlSetFont($Text, 20, 800, 0, $Font) GUICtrlSetBkColor($Text, $GUI_BKCOLOR_TRANSPARENT) $Gold = GUICtrlCreateLabel("$1000" , 0 , 370 , 265, 30, $SS_CENTER) GUICtrlSetFont($Gold, 20, 800, 0, $Font) GUICtrlSetColor($Gold, 0x00FF00) GUICtrlSetBkColor($Gold, $GUI_BKCOLOR_TRANSPARENT) $Letter_X = 0 $Letter_Y = $Height -25 For $i = 65 To 90 Step +1 $Letter[$i] = GUICtrlCreateButton(Chr($i), $Letter_X, $Letter_Y, 30, 25) ;25 GUICtrlSetColor($Letter[$i], 0x000000) GUICtrlSetBkColor($Letter[$i], 0xD0BE68) $Letter_X += 30 Next $Hint = GUICtrlCreateButton("?" , $Width -20 , $Letter_Y, 20, 25) GUICtrlSetColor($Hint, 0x000000) GUICtrlSetBkColor($Hint, 0xD0BE68) GUICtrlSetState($Background , $GUI_DISABLE) GUISetState(@SW_HIDE) _Gen_Word($Word) GUISetState(@SW_SHOW) ;WinSetOnTop("" , "" , 1) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Letter[65] ;To $Letter[90] _Use_Letter(65 , $Word) Case $Letter[66] _Use_Letter(66 , $Word) Case $Letter[67] _Use_Letter(67 , $Word) Case $Letter[68] _Use_Letter(68 , $Word) Case $Letter[69] _Use_Letter(69 , $Word) Case $Letter[70] _Use_Letter(70 , $Word) Case $Letter[71] _Use_Letter(71 , $Word) Case $Letter[72] _Use_Letter(72 , $Word) Case $Letter[73] _Use_Letter(73 , $Word) Case $Letter[74] _Use_Letter(74 , $Word) Case $Letter[75] _Use_Letter(75 , $Word) Case $Letter[76] _Use_Letter(76 , $Word) Case $Letter[77] _Use_Letter(77 , $Word) Case $Letter[78] _Use_Letter(78 , $Word) Case $Letter[79] _Use_Letter(79 , $Word) Case $Letter[80] _Use_Letter(80 , $Word) Case $Letter[81] _Use_Letter(81 , $Word) Case $Letter[82] _Use_Letter(82 , $Word) Case $Letter[83] _Use_Letter(83 , $Word) Case $Letter[84] _Use_Letter(84 , $Word) Case $Letter[85] _Use_Letter(85 , $Word) Case $Letter[86] _Use_Letter(86 , $Word) Case $Letter[87] _Use_Letter(87 , $Word) Case $Letter[88] _Use_Letter(88, $Word) Case $Letter[89] _Use_Letter(89 , $Word) Case $Letter[90] _Use_Letter(90 , $Word) EndSwitch WEnd Func _Gen_Word($Gen) $i = 0 $Blanks = "" $Gen_Length = StringLen($Gen) do $Blanks = $Blanks & " _ " $i += 1 Until $i = $Gen_Length GUICtrlSetData($Text , $Blanks) EndFunc Func _Use_Letter($Use_Letter, $Use_Word) GUICtrlSetState($Letter[$Use_Letter] , $GUI_DISABLE) $Find_Letter = StringInStr($Use_Word, Chr($Use_Letter)) If $Find_Letter Then $Letter_Count = 0 Do $Letter_Count = $Letter_Count + 1 $Replace_Letter = StringInStr($Use_Word, Chr($Use_Letter) , Default , $Letter_Count) If $Replace_Letter <> 0 Then GUICtrlSetData($Text, StringReplace(GUICtrlRead($Text) , $Replace_Letter , Chr($Use_Letter))) Until $Letter_Count = StringLen($Use_Word) Else $Hang +=1 If $Hang = 1 Then GUICtrlSetImage($Head, $Resource & "\Head.bmp") ElseIf $Hang = 2 Then GUICtrlSetImage($Torso, $Resource & "\Torso.bmp") ElseIf $Hang = 3 Then GUICtrlSetImage($Left_Arm, $Resource & "\Left Arm.bmp") ElseIf $Hang = 4 Then GUICtrlSetImage($Right_Arm, $Resource & "\Right Arm.bmp") ElseIf $Hang = 5 Then GUICtrlSetImage($Pants, $Resource & "\Pants.bmp") ;New Skin Required. GUICtrlSetImage($Left_Leg, $Resource & "\Left Leg.bmp") ElseIf $Hang = 6 Then GUICtrlSetImage($Pants, $Resource & "\Pants.bmp") ;New Skin Required. GUICtrlSetImage($Right_Leg, $Resource & "\Right Leg.bmp") Else $Hang = 0 MsgBox(0 , "GAME OVER", "Sorry") ;Game Over + Reset EndIf GUISetState(@SW_SHOW, $Hangman) EndIf EndFunc For Example if you guess letters H and L it will do this... H_LL_ _ _ _ When it should be more like this... H _ L L _Resources.rar Edited March 3, 2011 by SkellySoul Link to comment Share on other sites More sharing options...
SkellySoul Posted March 4, 2011 Author Share Posted March 4, 2011 Help me please someone I could figure it out on my own if I was using a different label control for each letter but I want to have one label control mostly because I want it centered and centering it with a bunch of labels isn't really a good idea. Link to comment Share on other sites More sharing options...
JohnOne Posted March 5, 2011 Share Posted March 5, 2011 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $Word , $Blanks , $Letter[100] $Hang = 0 $Width = 800 $Height = 500 $Font = "Comic Sans MS" $Resource = @ScriptDir & "\Resources" $Word = "Hello" $Hangman = GUICreate("Hangman", $Width, $Height) GUISetBkColor(0xD0BE68, $Hangman) $Background = GUICtrlCreatePic($Resource & "\Background.bmp" , 0, 0, $Width, $Height) $Head = GUICtrlCreatePic("" , 115, 180, 100, 64) $Torso = GUICtrlCreatePic("" , 145, 244, 40, 61) $Left_Arm = GUICtrlCreatePic("" , 127, 250, 18, 41) $Right_Arm = GUICtrlCreatePic("" , 185, 250, 18, 41) $Pants = GUICtrlCreatePic("" , 147, 305, 36, 20) $Left_Leg = GUICtrlCreatePic("" , 139, 325, 25, 35) $Right_Leg = GUICtrlCreatePic("" , 166, 325, 25, 35) $Text = GUICtrlCreateLabel("" , 0 , 50 , $Width, 50, $SS_CENTER) GUICtrlSetFont($Text, 20, 800, 0, $Font) GUICtrlSetBkColor($Text, $GUI_BKCOLOR_TRANSPARENT) $Gold = GUICtrlCreateLabel("$1000" , 0 , 370 , 265, 30, $SS_CENTER) GUICtrlSetFont($Gold, 20, 800, 0, $Font) GUICtrlSetColor($Gold, 0x00FF00) GUICtrlSetBkColor($Gold, $GUI_BKCOLOR_TRANSPARENT) $Letter_X = 0 $Letter_Y = $Height -25 For $i = 65 To 90 Step +1 $Letter[$i] = GUICtrlCreateButton(Chr($i), $Letter_X, $Letter_Y, 30, 25) ;25 GUICtrlSetColor($Letter[$i], 0x000000) GUICtrlSetBkColor($Letter[$i], 0xD0BE68) $Letter_X += 30 Next $Hint = GUICtrlCreateButton("?" , $Width -20 , $Letter_Y, 20, 25) GUICtrlSetColor($Hint, 0x000000) GUICtrlSetBkColor($Hint, 0xD0BE68) GUICtrlSetState($Background , $GUI_DISABLE) GUISetState(@SW_HIDE) _Gen_Word($Word) GUISetState(@SW_SHOW) ;WinSetOnTop("" , "" , 1) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case Else For $i = 65 to 90 If $msg = $Letter[$i] Then $char = GUICtrlRead($msg) _Use_Letter($char,$Word,$i) EndIf Next EndSwitch WEnd Func _Gen_Word($Gen) $i = 0 $Blanks = "" $Gen_Length = StringLen($Gen) do $Blanks = $Blanks & " _ " $i += 1 Until $i = $Gen_Length GUICtrlSetData($Text , $Blanks) EndFunc Func _Use_Letter($Use_Letter, $Use_Word, $index) GUICtrlSetState($Letter[$index] , $GUI_DISABLE) $Find_Letter = StringInStr($Use_Word, $Use_Letter) If $Find_Letter Then $Letter_Count = 0 Do $Letter_Count = $Letter_Count + 1 $Replace_Letter = StringInStr($Use_Word, $Use_Letter , Default , $Letter_Count) If $Replace_Letter <> 0 Then GUICtrlSetData($Text, StringReplace(GUICtrlRead($Text) , $Replace_Letter , $Use_Letter)) Until $Letter_Count = StringLen($Use_Word) Else $Hang +=1 If $Hang = 1 Then GUICtrlSetImage($Head, $Resource & "\Head.bmp") ElseIf $Hang = 2 Then GUICtrlSetImage($Torso, $Resource & "\Torso.bmp") ElseIf $Hang = 3 Then GUICtrlSetImage($Left_Arm, $Resource & "\Left Arm.bmp") ElseIf $Hang = 4 Then GUICtrlSetImage($Right_Arm, $Resource & "\Right Arm.bmp") ElseIf $Hang = 5 Then GUICtrlSetImage($Pants, $Resource & "\Pants.bmp") ;New Skin Required. GUICtrlSetImage($Left_Leg, $Resource & "\Left Leg.bmp") ElseIf $Hang = 6 Then GUICtrlSetImage($Pants, $Resource & "\Pants.bmp") ;New Skin Required. GUICtrlSetImage($Right_Leg, $Resource & "\Right Leg.bmp") Else $Hang = 0 MsgBox(0 , "GAME OVER", "Sorry") ;Game Over + Reset EndIf GUISetState(@SW_SHOW, $Hangman) EndIf EndFunc Edited March 5, 2011 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 More sharing options...
Malkey Posted March 5, 2011 Share Posted March 5, 2011 This is one way of doing it. expandcollapse popupOpt("MustDeclareVars", 1) ;0=no, 1=require pre-declare ;Modified from http://www.autoitscript.com/forum/index.php?showtopic=107984&view=findpost&p=763191 ;#include <GUIConstantsEx.au3> Global Const $GUI_GR_LINE = 2 Global Const $GUI_GR_MOVE = 6 Global Const $GUI_GR_COLOR = 8 Global Const $GUI_GR_ELLIPSE = 12 Global Const $GUI_GR_REFRESH = 22 Global Const $GUI_GR_PENSIZE = 24 Global Const $GUI_BKCOLOR_TRANSPARENT = -2 Global Const $GUI_EVENT_CLOSE = -3 ;#include <StaticConstants.au3> Global Const $SS_CENTER = 0x1 ; Thanks to AlmarM for the tricky list. Local $text = "abbey,abruptly,affix,askew,axiom,azure,bagpipes,bandwagon,banjo,bayou,bikini," & _ "blitz,bookworm,boxcar,boxful,buckaroo,buffalo,buffoon,cobweb,croquet,daiquiri,disavow," & _ "duplex,dwarves,equip,exodus,fishhook,fixable,foxglove,galaxy,galvanize,gazebo,gizmo," & _ "glowworm,guffaw,haiku,haphazard,hyphen,icebox,injury,ivory,ivy,jaundice,jawbreaker," & _ "jaywalk,jazzy,jigsaw,jiujitsu,jockey,jovial,joyful,juicy,jumbo,kazoo,keyhole,khaki," & _ "kilobyte,kiosk,kiwifruit,knapsack,larynx,luxury,marquis,megahertz,microwave,mystify," & _ "nightclub,nowadays,numbskull,ovary,oxidize,oxygen,pajama,peekaboo,pixel,pizazz," & _ "pneumonia,polka,quartz,quiz,quorum,razzmatazz,rhubarb,rickshaw,schizophrenia,sphinx," & _ "spritz,squawk,subway,swivel,topaz,unknown,unworthy,unzip,uptown,vaporize,vixen,vodka," & _ "vortex,walkway,waltz,wavy,waxy,wheezy,whiskey,whomever,wimpy,wizard,woozy,xylophone," & _ "yachtsman,yippee,youthful,zephyr,zigzag,zilch,zodiac,zombie" Local $file, $Line1, $Line2, $iCount = -1, $iMiss = 0, $sMiss, $Letter[26] Local $Width = 800, $Height = 500, $Font = "Comic Sans MS", $Msg Local $Hangman = GUICreate("Hangman", $Width, $Height) GUISetBkColor(0xD0BE68, $Hangman) Local $iText = GUICtrlCreateLabel("", 0, 50, $Width, 50, $SS_CENTER) GUICtrlSetFont($iText, 20, 800, 0, $Font) GUICtrlSetBkColor($iText, $GUI_BKCOLOR_TRANSPARENT) Local $Gold = GUICtrlCreateLabel("$1000", 0, 370, 265, 30, $SS_CENTER) GUICtrlSetFont($Gold, 20, 800, 0, $Font) GUICtrlSetColor($Gold, 0x00FF00) GUICtrlSetBkColor($Gold, $GUI_BKCOLOR_TRANSPARENT) Local $Letter_X = 0 Local $Letter_Y = $Height - 25 For $i = 0 To 25 $Letter[$i] = GUICtrlCreateButton(Chr($i + 65), $Letter_X, $Letter_Y, 30, 25) ;25 GUICtrlSetFont(-1, 12, 700) GUICtrlSetColor($Letter[$i], 0x000000) GUICtrlSetBkColor($Letter[$i], 0xD0BE68) $Letter_X += 30 Next Local $Hint = GUICtrlCreateButton("?", $Width - 20, $Letter_Y, 20, 25) GUICtrlSetColor($Hint, 0x000000) GUICtrlSetBkColor($Hint, 0xD0BE68) $file = StringSplit($text, ",") $Line2 = $file[Random(1, $file[0], 1)] $Line1 = StringRegExpReplace(StringFormat("%" & StringLen($Line2) & "s", " "), ".", "-") ;ConsoleWrite($Line2 & @CRLF) ; show chosen word GUICtrlSetData($iText, $Line1) GUISetState(@SW_SHOW) While $Line2 <> $Line1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Letter[0] To $Letter[25] Local $InpB, $i, $iStart = 1, $occurrence = 1 $InpB = Chr(65 + $Msg - $Letter[0]) ; Character on the button pressed. GUICtrlSetColor($Msg, 0xFF0000) $iCount += 1 If StringInStr($Line2, $InpB, 2) = 0 And StringInStr($sMiss, $InpB) = 0 Then $iMiss += 1 DrawHMan($iMiss) If StringInStr($sMiss, $InpB) = 0 Then $sMiss &= StringUpper($InpB) & " " If $iMiss = 10 Then MsgBox(0, "tHE eND", "Hung" & @CRLF & 'The word was "' & $Line2 & '"') Exit EndIf Else GUICtrlSetColor($Msg, 0x0000FF) EndIf While StringInStr($Line2, $InpB, 0, $occurrence) <> 0 $iStart = StringInStr($Line2, $InpB, 0, $occurrence) $Line1 = StringLeft($Line1, $iStart - 1) & StringUpper($InpB) & StringRight($Line1, StringLen($Line2) - $iStart) $occurrence += 1 Sleep(10) WEnd GUICtrlSetData($iText, $Line1) EndSwitch WEnd MsgBox(0, "tHE eND", "Not hung - success" & @CRLF & 'The word was "' & $Line2 & '"' & _ @CRLF & @CRLF & "Number of tries: " & $iCount + 1 & @CRLF & @CRLF & _ "Number of Misses: " & $iMiss & @CRLF & $sMiss) Func DrawHMan($Op) Local $idGraphic If $Op >= 1 Then $idGraphic = GUICtrlCreateGraphic(325, 120, 150, 280) GUICtrlSetGraphic(-1, $GUI_GR_PENSIZE, 5) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 2, 255) ; Base GUICtrlSetGraphic(-1, $GUI_GR_LINE, 130, 255) EndIf If $Op >= 2 Then GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 10, 10) ; Upright GUICtrlSetGraphic(-1, $GUI_GR_LINE, 10, 255) EndIf If $Op >= 3 Then GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 10, 10) ; Horiz. beam GUICtrlSetGraphic(-1, $GUI_GR_LINE, 95, 10) EndIf If $Op >= 4 Then GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 85, 10) ; rope GUICtrlSetGraphic(-1, $GUI_GR_LINE, 85, 50) EndIf If $Op >= 5 Then GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 70, 255) ; Head GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 70, 50, 30, 30) EndIf If $Op >= 6 Then GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 85, 80) ; Body GUICtrlSetGraphic(-1, $GUI_GR_LINE, 85, 180) EndIf If $Op >= 7 Then GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 85, 180) ; Right Leg GUICtrlSetGraphic(-1, $GUI_GR_LINE, 120, 215) EndIf If $Op >= 8 Then GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 85, 180) ; Left leg GUICtrlSetGraphic(-1, $GUI_GR_LINE, 50, 215) EndIf If $Op >= 9 Then GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 85, 105) ; Right arm GUICtrlSetGraphic(-1, $GUI_GR_LINE, 120, 140) EndIf If $Op >= 10 Then GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 85, 105) ; Left arm GUICtrlSetGraphic(-1, $GUI_GR_LINE, 50, 140) EndIf GUICtrlSetGraphic(-1, $GUI_GR_REFRESH) EndFunc ;==>DrawHMan 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