% '******************************************************* '* HANGMAN '* * '******************************************************* %> <%' Begin functions declarations '********** ' GetNewWord() ' Generates a random number from 1 to 83 which it uses to ' select a line from a textfile with 83 lines of words in it. ' It then retrieves the word, converts in to uppercase, and ' returns it as its return value. '********** Function GetNewWord() Dim objFSO, objFile Dim I Dim iRandom Dim strTemp ' Get a random number between 1 and 83 inclusive Randomize() iRandom = Int(83 * Rnd + 1) 'iRandom = 42 ' A word with a space = 3, with a - = 42 ' Open file and get the line equal to the number generated Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(Server.MapPath("hangman.txt")) ' Loop till line before the one we want For I = 1 to iRandom - 1 objFile.SkipLine Next strTemp = UCase(objFile.ReadLine) objFile.Close Set objFile = Nothing Set objFSO = Nothing GetNewWord = strTemp End Function ' GetNewWord() '********** ' CalculateGuess(strWord) ' Takes the secret word as input. It checks to see if the ' word contains any spaces or dashes to include them in the ' guess since you can't guess space or dash. Returns a ' properly adjusted guess based upon the secret word. '********** Function CalculateGuess(strWord) Dim strGuess Dim I strGuess = "" If InStr(1, strWord, Chr(32), 1) Or InStr(1, strWord, Chr(45), 1) Then For I = 1 to Len(strWord) Select Case Asc(Mid(strWord, I, 1)) Case 32 strGuess = strGuess & " " Case 45 strGuess = strGuess & "-" Case Else strGuess = strGuess & "_" End Select Next Else strGuess = String(Len(strWord), "_") End If CalculateGuess = strGuess End Function ' CalculateGuess() '********** ' CalculateGuess(strWord, strGuess, strLetter) ' Takes the secret word, the current state of the guess, and ' the guessed letter as input. It updates the guess to ' include all occurances of the guessed letter. It returns ' the guess containing the new letter. Only needs to be ' called when the letter is in the secret word. '********** Function UpdateGuess(strWord, strGuess, strLetter) Dim strTemp strTemp = "" For I = 1 to Len(strWord) If Mid(strWord, I, 1) = strLetter Then strTemp = strTemp & strLetter Else strTemp = strTemp & Mid(strGuess, I, 1) End If Next UpdateGuess = strTemp End Function ' UpdateGuess() ' End functions declarations %>
![]() |
||
|
|
|
|
![]() |
||