Topher Posted April 7, 2012 Posted April 7, 2012 (edited) The Word Game is a mastermind like game in which the player tries to determine a hidden word. The word is entered by another person or chosen randomly by the game. The player then guesses using a valid word and is told how many letters in their word is in the game's word. The player has twenty chances to guess the word. Try to improve upon your average number of guesses per round.A valid word is an uncapitalized five letter word with no repeating letters. For example: READY, CHOMP and UNZIP are valid words. SALLY, RESET and FGHYU are not.The DictionaryTa DaInstructionsCodeexpandcollapse popup#NoTrayIcon #region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=backup\TWG.ico #AutoIt3Wrapper_UseX64=n #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** ; #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: Garth Bigelow Script Function: The Word Game A Mastermind like game using five letter words #ce ---------------------------------------------------------------------------- FileInstall("Dictionary.dat", "Dictionary.dat") FileInstall("TaDa.wav", "TaDa.wav") #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiMenu.au3> #include <Misc.au3> #include <WindowsConstants.au3> Global $Name = "The Word Game" Global $NameVersion = $Name & " ver 1.6.07" ; Always placed here so I can quickly change the version number. Global Const $GameFile = "game.txt" Global Const $DictionaryFile = "Dictionary.dat" Global Const $StatFile = "Stat.txt" Global $GameID Global $TheWord Global $WordArray[21] Global $Number Global $ShowLetters = False ;Menu Variables Global $hWord, $hStats, $hHelp, $hMain Global Enum $idSetWord = 1000, $idRandomWord, $idGiveUp, $idResetAlphabet, $idSaveExit, $idViewStats, $idViewStatHistory, $idResetStats, $idAbout, $idHelp Global $MenuActionFlag = 0 ;Alphabet Variables Dim $Alphabet[27] Dim $AlphaState[27] Dim $LetterButtonArray[21][6] ; Mouse Variables Global $SingleClick = False, $DoubleClick = False Global Const $DoubleClickTime = _GetDoubleClickTime() ; Only allow one instance of the program If _Singleton($NameVersion, 1) = 0 Then WinActivate($NameVersion) MsgBox(262160, "Notice", $Name & " is already running.") Exit EndIf ; for double clicking on letters and menu commands GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; create .ini file if needed If FileExists("Config.ini") = 0 Then ; 0 - Select via Menu ; 1 - Enter Word Always ; 2 - Random Word Always iniWrite("Config.ini", "Word", "Always", 0) iniWrite("Config.ini", "Color", "OutColor", 0x666666) iniWrite("Config.ini", "Color", "OutBKColor", 0xA5D2F2) Endif $iniWordFlag = IniRead("Config.ini", "Word", "Always", 0) $LetterOutColor = IniRead("Config.ini", "Color", "OutColor", 0x666666) $LetterOutBKColor = IniRead("Config.ini", "Color", "OutBKColor", 0xA5D2F2) ; loop for games played GUISetHelp("The Word Game.pdf") While True Game() If MsgBox(262180, $Name, "Fancy another game?") = 7 Then ExitLoop WEnd Func Game() $Prep = True $Number = 1 ; Create Game Window $GameID = GUICreate($NameVersion, 800, 565, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU)) GUISetBkColor(0xA5D2F2, $GameID) If $GameID = 0 Then ErrorBox(@ScriptLineNumber, "Platform GUI can not be created") GUISetState() GUISetFont(14, 600, -1, "Courier New") SystemMenu($GameID) GUICtrlSetState($idResetAlphabet, $GUI_DISABLE) GetSecretWord() ; Display Alphabet Buttons Const $Square = 790 / 26 LoadAlphaStates() For $Letter = 1 To 26 $Alphabet[$Letter] = GUICtrlCreateButton(Chr(64 + $Letter), $Letter * $Square - $Square + 5, 10, $Square, $Square, BitOR($BS_NOTIFY, $BS_OWNERDRAW)) SetAlphaColor($Letter, $Alphabet[$Letter]) Next ; Create Letters Array For $a = 1 To 20 For $b = 1 To 5 $LetterButtonArray[$a][$b] = GUICtrlCreateButton("", ($b - .5) * 20, 25 + ($a * 24), 20, 20, BitOR($BS_NOTIFY, $BS_OWNERDRAW)) GUICtrlSetState($LetterButtonArray[$a][$b], $GUI_HIDE) Next Next $Number = DisplayWords() If $Number > 1 Then _GUICtrlMenu_EnableMenuItem($hWord, 6, 0) ;Main Loop _GUICtrlMenu_EnableMenuItem($hWord, 0, 2) _GUICtrlMenu_EnableMenuItem($hWord, 1, 2) _GUICtrlMenu_EnableMenuItem($hWord, 3, 0) _GUICtrlMenu_EnableMenuItem($hWord, 5, 0) While True ; End game if the 20 guesses are exhausted If $Number = 21 Then MsgBox(262192, "You Lose", "Your 20 guesses are over." & @CRLF & "My word was " & $TheWord) UpdateStats(-1) DisplayStats() ExitLoop EndIf $msg = GUIGetMsg() DetectClicks() If $ShowLetters = True Then $ShowLetters = False For $Letter = 1 To 26 SetAlphaColor($Letter, $Alphabet[$Letter]) Next For $Row = 1 To $Number - 1 DisplayWord($Row) Next SaveWordFile() GUICtrlSetState($WordArray[$Number], $GUI_FOCUS) EndIf ; allow entry of the guess word If $Prep = True Then $WordArray[$Number] = GUICtrlCreateInput("", 20, 25 + ($Number * 24), 80, 27) $Guess = $WordArray[$Number] GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetColor(-1, 0x000000) $GuessButton = GUICtrlCreateButton("Guess", 110, 25 + ($Number * 24), 80, 27) $Prep = False GUICtrlSetState($WordArray[$Number], $GUI_FOCUS) EndIf ; compare guess word to secret word If $msg = $GuessButton Then _GUICtrlMenu_EnableMenuItem($hWord, 6, 0) GUICtrlSetData($Guess, StringUpper(GUICtrlRead($Guess))) ;other stuff If TestWord(GUICtrlRead($Guess)) = True Then $Prep = True GUICtrlSetState($GuessButton, $GUI_HIDE) GUICtrlSetState($Guess, $GUI_DISABLE) DisplayWord($Number) If GUICtrlRead($Guess) = $TheWord Then Tada() MsgBox(262192, "Congratulations", "That is my word" & @CRLF & "You guessed it in " & $Number & " Guesses") UpdateStats($Number) DisplayStats() ExitLoop EndIf SaveWordFile() $Number += 1 Else MsgBox(262160, "Mistake", GUICtrlRead($Guess) & " is not a valid word." & @CRLF & "Press OK to try another word") GUICtrlSetData($Guess, "") GUICtrlSetState($WordArray[$Number], $GUI_FOCUS) EndIf EndIf MenuCommands() ; ends the game prematurely and displays the secret word ; unless the game is at the beginning, then just exit game If $MenuActionFlag = $idGiveUp Then $MenuActionFlag = 0 If $TheWord <> "" Then If MsgBox(262180, "Confirmation", "Are you sure you want to give up?") = 7 Then ContinueLoop MsgBox(262160, "You Lose.", "My word was " & $TheWord) If $Number > 1 Then UpdateStats(-1) DisplayStats() EndIf EndIf ExitLoop EndIf ; reset the alphabet to alpha state 0 ; used if you discover your work is wrong If $MenuActionFlag = $idResetAlphabet Then $MenuActionFlag = 0 If MsgBox(262180, "Confirmation", "Are you sure you want to reset the alphabet") = 7 Then ContinueLoop For $a = 1 To 26 $AlphaState[$a] = 0 ;$Alphabet[$a] = GUICtrlCreateButton(Chr(64 + $a), $a*$Square-$Square+5, 45, $Square, $Square) SetAlphaColor($a, $Alphabet[$a]) Next For $Row = 1 To $Number - 1 DisplayWord($Row) Next SaveWordFile() GUICtrlSetState($WordArray[$Number], $GUI_FOCUS) EndIf If $msg = $GUI_EVENT_CLOSE Or $MenuActionFlag = $idSaveExit Then _GUICtrlMenu_SetMenu($GameID, 0) GUIDelete($GameID) Exit EndIf If $MenuActionFlag = $idHelp Then $MenuActionFlag = 0 ShellExecute("The Word Game.pdf") Endif WEnd FileDelete($GameFile) _GUICtrlMenu_SetMenu($GameID, 0) GUIDelete($GameID) EndFunc ;==>Game ; ; Determines whether system has detected a single or double click but not both ; Func DetectClicks() If $SingleClick Then $DoubleClickPause = TimerInit() Do Sleep(10) If $DoubleClick Then ActOnClick($DoubleClick, 2) $SingleClick = False ExitLoop EndIf Until TimerDiff($DoubleClickPause) > 100;$DoubleClickTime $DoubleClick = False If $SingleClick Then If Not $DoubleClick Then ActOnClick($SingleClick, 1) EndIf $SingleClick = False EndIf EndFunc ; ; Increase In or Out or Unknown state of alphabet letters ; by one of two states depending on single or double clicks ; Func ActOnClick($nID, $Clicks) For $a = 1 To 26 If $nID = $Alphabet[$a] Then $AlphaState[$a] += $Clicks If $AlphaState[$a] > 2 Then $AlphaState[$a] -= 3 $ShowLetters = True Return $GUI_RUNDEFMSG EndIf Next For $a = 1 To 20 For $b = 1 To 5 If $nID = $LetterButtonArray[$a][$b] Then $Letter = Asc(GUICtrlRead($LetterButtonArray[$a][$b])) - 64 $AlphaState[$Letter] += $Clicks If $AlphaState[$Letter] > 2 Then $AlphaState[$Letter] -= 3 $ShowLetters = True Return $GUI_RUNDEFMSG EndIf Next Next EndFunc ; Determine Maximum Speed of clicks to still be a double click ; Func _GetDoubleClickTime() Local $aResult = DllCall("user32.dll", "uint", "GetDoubleClickTime") If @error Then Return SetError(1,0,100) Return $aResult[0] EndFunc ; ; detects clicks on letter buttons ; directs menu commands ; Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) ; Local $hCtrl = $lParam ; alphebet single and double click detection Switch ($nNotifyCode) Case $BN_DBLCLK $DoubleClick = $nID Case $BN_CLICKED $SingleClick = $nID EndSwitch ; menu commands Switch _WinAPI_LoWord($wParam) Case $idSetWord $MenuActionFlag = $idSetWord Case $idRandomWord $MenuActionFlag = $idRandomWord Case $idResetAlphabet $MenuActionFlag = $idResetAlphabet Case $idSaveExit $MenuActionFlag = $idSaveExit Case $idGiveUp $MenuActionFlag = $idGiveUp Case $idViewStats $MenuActionFlag = $idViewStats Case $idViewStatHistory $MenuActionFlag = $idViewStatHistory Case $idResetStats $MenuActionFlag = $idResetStats Case $idAbout $MenuActionFlag = $idAbout Case $idHelp $MenuActionFlag = $idHelp EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND ; ; Respond to Menu Commands ; Func MenuCommands() Switch ($MenuActionFlag) Case $idViewStats DisplayStats() Case $idViewStatHistory DisplayStatHistory() Case $idResetStats If MsgBox(262180, "Confirmation", "Delete your previous statistics?") = 6 Then FileDelete($StatFile) MsgBox(262144, "Comment", "Previousd Statistics Deleted") EndIf Case $idAbout About() Case Else Return EndSwitch $MenuActionFlag = 0 EndFunc ;==>MenuCommands ; ; Setup Main Menu Structure ; Func SystemMenu($hGUI) ; Create File menu $hWord = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hWord, 0, "Enter &Word", $idSetWord) _GUICtrlMenu_InsertMenuItem($hWord, 1, "Set &Random Word", $idRandomWord) _GUICtrlMenu_InsertMenuItem($hWord, 2, "", 0) _GUICtrlMenu_InsertMenuItem($hWord, 3, "Reset &Alphabet", $idResetAlphabet) _GUICtrlMenu_InsertMenuItem($hWord, 4, "", 0) _GUICtrlMenu_InsertMenuItem($hWord, 5, "Save and E&xit", $idSaveExit) _GUICtrlMenu_InsertMenuItem($hWord, 6, "&Give Up", $idGiveUp) _GUICtrlMenu_EnableMenuItem($hWord, 3, 2) _GUICtrlMenu_EnableMenuItem($hWord, 5, 2) _GUICtrlMenu_EnableMenuItem($hWord, 6, 2) _GUICtrlMenu_SetMenuStyle($hWord, $MNS_NOCHECK) ; Create Edit menu $hStats = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hStats, 0, "&View Statistics", $idViewStats) _GUICtrlMenu_InsertMenuItem($hStats, 1, "View Stat &History", $idViewStatHistory) _GUICtrlMenu_InsertMenuItem($hStats, 2, "", 0) _GUICtrlMenu_InsertMenuItem($hStats, 3, "Reset Statistics", $idResetStats) _GUICtrlMenu_SetMenuStyle($hStats, $MNS_NOCHECK) ; Create Help menu $hHelp = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hHelp, 0, "&Help", $idHelp) _GUICtrlMenu_InsertMenuItem($hHelp, 1, "&About", $idAbout) _GUICtrlMenu_SetMenuStyle($hHelp, $MNS_NOCHECK) ; Create Main menu $hMain = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hMain, 0, "&Word", 0, $hWord) _GUICtrlMenu_InsertMenuItem($hMain, 1, "&Stat", 0, $hStats) _GUICtrlMenu_InsertMenuItem($hMain, 2, "&Help", 0, $hHelp) ; Set window menu _GUICtrlMenu_SetMenu($hGUI, $hMain) EndFunc ;==>SystemMenu ; ; Credits ; Func About() Local $Display $Display = $NameVersion & @CRLF & @CRLF $Display &= " - Written by Garth Bigelow" & @CRLF $Display &= " - with much patient help from the AutoIt help forums" & @CRLF & @CRLF $Display &= " - Copyright (c) 2012" & @CRLF $Display &= " - Program may be freely disseminated as long as no charge is levied." & @CRLF MsgBox(262144, "About", $Display) EndFunc ;==>About ; SaveWordFile creates the game file which is used to continue a game if the game is closed while still in play ; $GameFile contains ; The Secret Word ; The Letter States (0,1 or 2) for Each Letter of the Alphabet ; followed by each word guessed ; each entry on its own line ; Func SaveWordFile() $file = FileOpen($GameFile, 2) ; write fresh mode ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, @ScriptLineNumber, "Unable to open file.") Exit EndIf FileWriteLine($file, $TheWord) For $Num = 1 To 26 FileWriteLine($file, $AlphaState[$Num]) Next For $Num = 1 To $Number If GUICtrlRead($WordArray[$Num]) >= "A" Then FileWriteLine($file, GUICtrlRead($WordArray[$Num])) EndIf Next FileClose($file) EndFunc ;==>SaveWordFile ; ; Tests whether $TestWord is in the dictionary ; returns true if it is, false if it isn't Func TestWord($TestWord) $file = FileOpen($DictionaryFile, 0) ; read only mode ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, @ScriptLineNumber, "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While True $word = FileReadLine($file) If @error = -1 Then ExitLoop $word = StringLeft($word, 5) If $word <> $TestWord Then ContinueLoop ; tidy up FileClose($file) ; valid word Return True WEnd ; Tidy up FileClose($file) ; Not a valid word Return False EndFunc ;==>TestWord ; ; Returns the number of letters in the guess that are also in the secret word ; Func GetCount($Char) $Array1 = StringSplit($TheWord, "") $Array2 = StringSplit(GUICtrlRead($WordArray[$Char]), "") $Count = 0 For $a = 1 To 5 For $b = 1 To 5 If $Array1[$a] = $Array2[$b] Then $Count += 1 Next Next Return $Count EndFunc ;==>GetCount ; ; Returns one random word from the dictionary ; Func RandomWord() $wordcount = 0 $file = FileOpen($DictionaryFile, 0) ; read only mode ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, @ScriptLineNumber, "Unable to open file.") Exit EndIf ; count number of words While True FileReadLine($file) If @error = -1 Then ExitLoop $wordcount += 1 WEnd ; record structure is a five letter word followed by a flag ; if flag = 0 the word is common (and therefore eligible for being a secret word) ; = 1 the word is rare ; keep picking random words until a common word is found While True $ranword = FileReadLine($file, (Random(1, $wordcount - 1, 1))) If StringRight($ranword, 1) = 0 Then $ReturnWord = StringLeft($ranword, 5) ExitLoop EndIf WEnd FileClose($file) ; return the valid word Return $ReturnWord EndFunc ;==>RandomWord ; ; Sets the secret word, either by manual entry or by random word from the dictionary ; Func GetSecretWord() $InitWord = "" $file = "" If FileExists($GameFile) Then $file = FileOpen($GameFile, 0) ; write read only ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, @ScriptLineNumber, "Unable to open file.") Exit EndIf $TheWord = FileReadLine($file) FileClose($file) Return EndIf If Not FileExists($GameFile) Then While True $msg = GUIGetMsg() If $MenuActionFlag = $idSetWord Or $iniWordFlag = 1 Then $MenuActionFlag = 0 $tempX = @DesktopWidth / 2 - 100 $tempY = @DesktopHeight / 2 - 70 $TheWord = InputBox("Select Word", "Enter The Game Word:", "", " M", -1, 140, $tempX, $tempY, 0, $GameID) If @error = 0 Then $TheWord = StringUpper($TheWord) If TestWord($TheWord) = True Then ExitLoop MsgBox(262160, "Word Problem", $TheWord & " is not a valid game word." & @CRLF & "Press OK to try another word") EndIf EndIf If $MenuActionFlag = $idRandomWord Or $iniWordFlag = 2 Then $MenuActionFlag = 0 $TheWord = RandomWord() ExitLoop EndIf MenuCommands() If $msg = $GUI_EVENT_CLOSE Then Exit WEnd EndIf EndFunc ;==>GetSecretWord ; ; Each letter of the alphabet has an associated state ; 0 - state is unknown ; 1 - letter is out ; 2 - letter is in ; This routine sets the states if a game is resumed ; Func LoadAlphaStates() If FileExists($GameFile) Then $file = FileOpen($GameFile, 0) ; write read only ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, @ScriptLineNumber, "Unable to open file.") Exit EndIf For $Num = 1 To 26 $AlphaState[$Num] = FileReadLine($file, $Num + 1) Next FileClose($file) Else For $Num = 1 To 26 $AlphaState[$Num] = 0 Next EndIf EndFunc ;==>LoadAlphaStates ; ; The states of the letters of the alphabet are displayed by a color ; This routine sets that color ; Func SetAlphaColor($Char, $Object) ; debugging remove later If $Char < 1 Or $Char > 26 Then Return Switch $AlphaState[$Char] Case 0 ; Grey on Darker Gray GUICtrlSetBkColor($Object, 0xFFFFFF) GUICtrlSetColor($Object, 0x030203) Case 1 ; Disabled Mimic Colors GUICtrlSetBkColor($Object, $LetterOutBKColor) GUICtrlSetColor($Object, $LetterOutColor) ; GUICtrlSetBkColor($Object, 0xECF27E) ; GUICtrlSetColor($Object, 0x636162) Case 2 ; White on Red GUICtrlSetBkColor($Object, 0xFC0F03) GUICtrlSetColor($Object, 0xFFFFFF); 0xF4FC03) EndSwitch EndFunc ;==>SetAlphaColor ; ; Display the word as a button for each letter and then ; the number of letters between word and secret word ; Letters are displayed in their Alpha State colors ; Func DisplayWord($Number) ; Remove Input Word Field GUICtrlSetState($WordArray[$Number], $GUI_HIDE) ; Separate Word in Letters $temp = GUICtrlRead($WordArray[$Number]) $Character = StringSplit($temp, "") ; Display Word For $Num = 1 To 5 GUICtrlSetData($LetterButtonArray[$Number][$Num], $Character[$Num]) SetAlphaColor(Asc($Character[$Num]) - 64, $LetterButtonArray[$Number][$Num]) GUICtrlSetState($LetterButtonArray[$Number][$Num], $GUI_SHOW) Next GUICtrlCreateLabel(" = " & GetCount($Number), 120, 23 + ($Number * 24), 90) GUICtrlSetFont(-1, 17, 800) ; GUICtrlSetBkColor(-1, 0xE8E1E4) GUICtrlSetColor(-1, 0x030203) EndFunc ;==>DisplayWord ; ; upon resuming the game the previous guesses are displayed ; Func DisplayWords() If Not FileExists($GameFile) Then Return 1 $file = FileOpen($GameFile, 0) ; read only ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, @ScriptLineNumber, "Unable to open file.") Exit EndIf $Count = 1 While True $word = FileReadLine($file, $Count + 27) If @error = -1 Then ExitLoop $WordArray[$Count] = GUICtrlCreateInput($word, 20, 25 + ($Count * 24), 80) DisplayWord($Count) $Count += 1 WEnd FileClose($file) Return $Count EndFunc ;==>DisplayWords Func UpdateStats($guesses) $file = FileOpen($StatFile, 1) ; write append ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, @ScriptLineNumber, "Unable to open file.") Exit EndIf FileWrite($file, $TheWord) FileWrite($file, " ") FileWriteLine($file, $guesses) FileClose($file) EndFunc ;==>UpdateStats Func DisplayStats() Local $StatID, $file, $Wins, $Total, $Lost, $score, $msg $file = FileOpen($StatFile, 0) ; read only ; Check if file opened for reading OK If $file = -1 Then Return EndIf $Wins = 0 $Total = 0 $Lost = 0 While True $score = FileReadLine($file) If @error = -1 Then ExitLoop $score = StringRight($score, 2) If $score > 0 Then $Total += $score $Wins += 1 Else If $score = -1 Then $Lost += 1 EndIf EndIf WEnd $StatID = GUICreate("Statistics", 190, 110, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU, $WS_EX_TOPMOST), -1, $GameID) GUISetFont(12, 800) GUICtrlCreateLabel("Games Won: " & $Wins, 10, 20) If $Wins = 0 Then GUICtrlCreateLabel("Average Score: N/A", 10, 45) Else GUICtrlCreateLabel("Average Score: " & Round($Total / ($Wins + $Lost), 2), 10, 45) EndIf GUICtrlCreateLabel("Games Lost: " & $Lost, 10, 70) GUISetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE GUIDelete($StatID) EndFunc ;==>DisplayStats Func DisplayStatHistory() Local $StatID, $StatEdit, $temp, $file, $line, $word, $score $StatID = GUICreate("Statistics History", 230, 540, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU, $WS_EX_TOPMOST), -1, $GameID) GUISetFont(14, 600, -1, "Courier New") $temp = " Word Tries" & @CRLF & " ===== =====" $StatEdit = GUICtrlCreateEdit($temp, 10, 10, 210, 560) GUISetState() $file = FileOpen($StatFile, 0) ; read only ; Check if file opened for reading OK If $file = -1 Then GUIDelete($StatID) Return EndIf ; Determine Number of Words ; So that List can be lastest word first $Count = 0 While True $line = FileReadLine($file) If @error = -1 Then ExitLoop $Count += 1 WEnd ; Exit if there are no words If $Count = 0 Then GUIDelete($StatID) Return EndIf ; Cycle thru the statistics file While True $line = FileReadLine($file, $Count) $Count -= 1 If $Count = 0 then ExitLoop ; ignore old style stat file entries If StringLen($line) < 5 Then ContinueLoop ; decode file line $word = StringLeft($line, 5) $score = StringRight($line, 2) ; display word $temp = GUICtrlRead($StatEdit) $temp &= @CRLF & " " & $word & " " ; display number of tries If $score = -1 Then $temp &= "Lost" Else ; If $score < 10 Then $temp &= " " $temp &= " " & $score EndIf GUICtrlSetData($StatEdit, $temp) WEnd Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE GUIDelete($StatID) EndFunc ;==>DisplayStatHistory ; ; Winning Hu-ra ; Func Tada() SoundPlay("TaDa.wav") EndFunc ;==>Tada ; ; Displays Error and Line of Error ; Func ErrorBox($line, $content) MsgBox(0, "Internal Error", $content & @CR & @CR & "Line: " & $line) Exit EndFunc ;==>ErrorBox Edited May 18, 2012 by Topher [left][hr] $mood = "whimsy" $mode = "confused" $randomChaos = True Do Something() Until $Tired[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left]
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