quick_sliver007 Posted April 18, 2005 Share Posted April 18, 2005 Here is the code: expandcollapse popup#include <GuiConstants.au3> #include <Array.au3> $Gui = GUICreate("Hangman", 299, 387, (@DesktopWidth - 299) / 2, (@DesktopHeight - 387) / 2) $Pic = GUICtrlCreatePic("1.bmp", 10, 20, 280, 260) GUICtrlCreateLabel("Used Letters:", 10, 320, 65, 20) $Label_Used_Letters = GUICtrlCreateLabel("", 72, 320, 150, 20) $Input = GUICtrlCreateInput("", 10, 350, 130, 20) GUICtrlSetLimit($Input, 1) $Button_Enter = GUICtrlCreateButton("Enter", 160, 350, 130, 20) _setletters() GUISetState(@SW_SHOW, $Gui) Func _enter() ControlClick("Hangman", "Enter", 7) EndFunc ;==>_enter HotKeySet("{ENTER}", "_enter") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _setletters() Global $random = Random(1, 25) ;Global $string = FileReadLine("wordlist.txt", 3); using the 3rd word(seattle) for testing Global $string = "seattle" Global $stringsplit = StringSplit($string, "") Global $labels[20] Global $c For $c = 1 To $stringsplit[0] $labels[$c] = GUICtrlCreateLabel("_", $c * 10, 290, 10, 20) Next Return $stringsplit[0] EndFunc ;==>_setletters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $lettersUsed = "" While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_Enter If GUICtrlRead($Input) <> "" Then Local $Read_Input = GUICtrlRead($Input) If Not _isLetterUsed() Then Global $Count = 0 Do $Count = $Count + 1 Global $StringInStr = StringInStr($string, $Read_Input, 0, $Count) ;Help;Here;Here;Here;Here;Here;;;;;;;;;;;;;;;;;;;;;;;Help Here If Not GUICtrlSetData($labels[$StringInStr], $Read_Input) Then ;If Not $StringInStr Then MsgBox(0, "failed", "Failed") Else MsgBox(0, "passed", "passed") EndIf ;Help;Here;Here;Here;Here;Here;;;;;;;;;;;;;;;;;;;;;;;Help Here GUICtrlSetData($labels[$StringInStr], $Read_Input) Until $Count = $stringsplit[0] EndIf EndIf GUICtrlSetData($Input, "") GUICtrlSetState($Input, $Gui_focus) EndSelect WEnd Exit Func _isLetterUsed() If StringInStr($lettersUsed, $Read_Input) Then MsgBox(0, "", "letter used") Return 1 Else $lettersUsed = $lettersUsed & $Read_Input GUICtrlSetData($Label_Used_Letters, $lettersUsed) EndIf EndFunc ;==>_isLetterUsed I marked the area I need Help with. I want a way to know if the user typed a letter that is not in the word. The problem is that I am getting 7 msgboxs, One for every letter in the word. I want one msgbox that says "passed" if the letter is in the word and I want one msgbox if the letter is not in the word that says "failed". Can someone show me how to trap when the user types in a bad letter. If so you have my thanks. . Link to comment Share on other sites More sharing options...
GaryFrost Posted April 18, 2005 Share Posted April 18, 2005 $passed = 0 Do $Count = $Count + 1 Global $StringInStr = StringInStr($string, $Read_Input, 0, $Count) If GUICtrlSetData($labels[$StringInStr], $Read_Input) Then $passed = 1 EndIf GUICtrlSetData($labels[$StringInStr], $Read_Input) Until $Count = $stringsplit[0] if($passed) Then MsgBox(0, "passed", "passed") Else MsgBox(0, "failed", "Failed") EndIf SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
steveR Posted April 18, 2005 Share Posted April 18, 2005 expandcollapse popup#include <GuiConstants.au3> #include <Array.au3> $Gui = GUICreate("Hangman", 299, 387, (@DesktopWidth - 299) / 2, (@DesktopHeight - 387) / 2) $Pic = GUICtrlCreatePic("1.bmp", 10, 20, 280, 260) GUICtrlCreateLabel("Used Letters:", 10, 320, 65, 20) $Label_Used_Letters = GUICtrlCreateLabel("", 72, 320, 150, 20) $Input = GUICtrlCreateInput("", 10, 350, 130, 20) GUICtrlSetLimit($Input, 1) $Button_Enter = GUICtrlCreateButton("Enter", 160, 350, 130, 20) _setletters() GUISetState(@SW_SHOW, $Gui) Func _enter() ControlClick("Hangman", "Enter", 7) EndFunc ;==>_enter HotKeySet("{ENTER}", "_enter") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _setletters() Global $random = Random(1, 25) ;Global $string = FileReadLine("wordlist.txt", 3); using the 3rd word(seattle) for testing Global $string = "seattle" Global $stringsplit = StringSplit($string, "") Global $labels[20] Global $c For $c = 1 To $stringsplit[0] $labels[$c] = GUICtrlCreateLabel("_", $c * 10, 290, 10, 20) Next Return $stringsplit[0] EndFunc ;==>_setletters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $lettersUsed = "" While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_Enter If GUICtrlRead($Input) <> "" Then Local $Read_Input = GUICtrlRead($Input) If _isLetterValid($Read_Input) Then MsgBox(0, "", "passed") Else MsgBox(0, "", "failed") EndIf If Not _isLetterUsed() Then ;~ MsgBox(0, "passed", "passed") Global $Count = 0 Do $Count = $Count + 1 Global $StringInStr = StringInStr($string, $Read_Input, 0, $Count) ;Help;Here;Here;Here;Here;Here;;;;;;;;;;;;;;;;;;;;;;;Help Here ;~ If Not GUICtrlSetData($labels[$StringInStr], $Read_Input) Then ;~ ;If Not $StringInStr Then ;~ MsgBox(0, "failed", "Failed") ;~ Else ;~ MsgBox(0, "passed", "passed") ;~ EndIf ;~ ;Help;Here;Here;Here;Here;Here;;;;;;;;;;;;;;;;;;;;;;;Help Here GUICtrlSetData($labels[$StringInStr], $Read_Input) Until $Count = $stringsplit[0] EndIf EndIf GUICtrlSetData($Input, "") GUICtrlSetState($Input, $Gui_focus) EndSelect WEnd Exit Func _isLetterUsed() If StringInStr($lettersUsed, $Read_Input) Then MsgBox(0, "", "letter used") Return 1 Else $lettersUsed = $lettersUsed & $Read_Input GUICtrlSetData($Label_Used_Letters, $lettersUsed) EndIf EndFunc ;==>_isLetterUsed Func _isLetterValid($letter) If StringInStr($string, $letter) Then Return 1 Else Return 0 EndIf EndFunc ;==>_isLetterValid AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. Link to comment Share on other sites More sharing options...
quick_sliver007 Posted April 18, 2005 Author Share Posted April 18, 2005 To steveR Thank you again, thats 3 times you helps me on this script. You have been very helpful. I been working on that since the last time you help me and you figure it out in a few mins, what I been working on for hours. Thanks man. . 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