// Text of project C:\Documents and Settings\Administrator\My Documents\My Downloads\Newton\Programming\Newton Projects\Text Twist\texttwist.NTK written on: 05/14/04 17:13:48 // Beginning of file text.lyt main := {word5: nil, twistLetters: func() begin if canBeTwisted then begin for i:=1 to 10 do begin letter1:=0; letter2:=0; while letter1 = letter2 do begin letter1:=Random(0,5); letter2:=Random(0,5); end; tempLetter:=gameWord[letter2]; gameWord[letter2]:=gameWord[letter1]; gameWord[letter1]:=tempLetter; end; //Set all twister letters to letters of the word for i:= 0 to 5 do begin SetValue(textLetters[i],'text,gameWord[i]); textLetters[i].letter:=gameWord[i]; end; end; end;, playingGame: nil, viewFormat: 83951953, answer6: nil, dictionary5: nil, startGame: func() begin Print("Setting canBeTwisted to non-nil"); canBeTwisted:=1; Print("Blanking all gameWords"); foreach emptyBox in [gameWord1,gameWord2,gameWord3,gameWord4,gameWord5,gameWord6,gameWord7,gameWord8,gameWord9,gameWord10, gameWord11,gameWord12,gameWord13,gameWord14,gameWord15,gameWord16,gameWord17,gameWord18,gameWord19,gameWord20,gameWord21] do begin SetValue(emptyBox,'text,nil); end; Print("Selecting Random Word"); :selectRandomWord(); Print("set continuePlaying to nil"); continuePlaying:=nil; word3:=0; word4:=0; word5:=0; word6:=0; theWord:=nil; letterCount:=0; :twistLetters(); foundWords:=[]; timeCountdown.value:=120; timeCountdown:Close(); timeCountdown:Open(); gameTextBox:SetupIdle(1000); SetValue(twist,'text,"Jumble"); lastWord:=nil; lastLetters:=[]; SetLength(lastLetters,6); playingGame:=1; SetValue(wordLetter1,'text,nil); SetValue(wordLetter2,'text,nil); SetValue(wordLetter3,'text,nil); SetValue(wordLetter4,'text,nil); SetValue(wordLetter5,'text,nil); SetValue(wordLetter6,'text,nil); end;, answer3: nil, setupDictionary: func(value3,value4,value5,value6) begin dictionary3:=value3; dictionary4:=value4; dictionary5:=value5; dictionary6:=value6; end;, theWord: nil, viewBounds: {left: -1, top: 4, bottom: 303, right: 229}, wordLetters: nil, findLetter: func() begin if SetContains(lastWordLetters,twistLetter1.letter) then begin SetValue(twistLetter1,'text,nil); twistLetter1.clicked:=1; end; if SetContains(lastWordLetters,twistLetter2.letter) then begin SetValue(twistLetter2,'text,nil); twistLetter2.clicked:=1; end; if SetContains(lastWordLetters,twistLetter3.letter) then begin SetValue(twistLetter3,'text,nil); twistLetter3.clicked:=1; end; if SetContains(lastWordLetters,twistLetter4.letter) then begin SetValue(twistLetter4,'text,nil); twistLetter4.clicked:=1; end; if SetContains(lastWordLetters,twistLetter5.letter) then begin SetValue(twistLetter5,'text,nil); twistLetter5.clicked:=1; end; if SetContains(lastWordLetters,twistLetter6.letter) then begin SetValue(twistLetter6,'text,nil); twistLetter6.clicked:=1; end; end, _proto: @157, lastLetters: nil, word4: nil, foundWords: nil, resetWord: func() begin foreach wordLetterReset in textLetters do begin SetValue(wordLetterReset,'text,wordLetterReset.letter); wordLetterReset.clicked:=nil; end; foreach wordLetterReset in wordLetters do SetValue(wordLetterReset,'text,nil); letterCount:=0; theWord:=""; SetValue(twist,'text,"Jumble"); lastLetters:=[]; SetLength(lastLetters,6); canBeTwisted:=1; end;, answer5: nil, title: "Jumble", gameWord: nil, dictionary4: nil, continuePlaying: nil, lastWord: nil, letterCount: nil, word6: nil, selectRandomWord: func() begin local levelSelect:=Random(1,3); Print(levelSelect); if levelSelect=1 then begin gameWord:=["d","r","y","i","n","g"]; :setupDictionary(["rig","rid","gin","dry","din","dig"],["ring","rind","grin","grid","ding"], ["grind","dying","dingy"],["drying"]); :setupBlankWords([gameWord1,gameWord2,gameWord3,gameWord4,gameWord5,gameWord6], [gameWord7,gameWord8,gameWord9,gameWord10,gameWord11],[gameWord12,gameWord13,gameWord14],[gameWord15]); end; if levelSelect=2 then begin gameWord:=["s","i","n","n","e","d"]; :setupDictionary(["din","inn","ins","sin","den"],["dens","dies","dine","ends","inns","nine","send","side","sine"], ["dines","nines","snide"],["sinned"]); :setupBlankWords([gameWord1,gameWord2,gameWord3,gameWord4,gameWord5],[gameWord6,gameWord7,gameWord8,gameWord9,gameWord10,gameWord11, gameWord12,gameWord13,gameWord14],[gameWord15,gameWord16,gameWord17],[gameWord18]); end; if levelSelect=3 then begin gameWord:=["b","u","t","t","o","n"]; :setupDictionary(["bun","but","not","nub","nut","out","ton","tot","tub"],["bout","bunt","butt","tout","unto"], [],["button"]); :setupBlankWords([gameWord1,gameWord2,gameWord3,gameWord4,gameWord5,gameWord6,gameWord7,gameWord8,gameWord9], [gameWord10,gameWord11,gameWord12,gameWord13,gameWord14],[],[gameWord15]); if levelSelect=4 then begin gameWord:=["h","u","n","g","r","y"]; :setupDictionary(["gnu","gun","guy","hug","rug","run","urn"],["hung","rung"], [],["hungry"]); :setupBlankWords([gameWord1,gameWord2,gameWord3,gameWord4,gameWord5,gameWord6,gameWord7], [gameWord8,gameWord9],[],[gameWord10]); end; if levelSelect=5 then begin gameWord:=["s","u","c","c","o","r"]; :setupDictionary(["cur","our"],["ours","curs"],["occur","scour"],["crocus","occurs","succor"]); :setupBlankWords([gameWord1,gameWord2],[gameWord3,gameWord4],[gameWord5,gameWord6],[gameWord7,gameWord8,gameWord9]); end; end; end;, clickedLetter: func() begin if not clicked and playingGame then begin Print("Button isn't clicked and playingGame"); SetValue(wordLetters[letterCount],'text,letter); Print("Set wordLetters[letterCount] to letter"); SetValue(self,'text,nil); Print("Setting current button text to nil"); clicked:=1; Print("Setting clicked to: " & clicked); theWord:=theWord & letter; Print("Added new letter: " & letter & ", to theWord: " & theWord); SetValue(twist,'text,nil); Print("Removing twist option from buttons"); Print(lastLetters); lastLetters[letterCount]:=letter; Print(lastLetters); Print("added one to letterCount:" && letterCount); letterCount:=letterCount + 1; canBeTwisted:=nil; end; end;, lastWordLetters: nil, ViewSetupFormScript: // be sure to call inherited:?ViewSetupFormScript() func() begin playingGame:=nil; wordLetters:=[wordLetter1,wordLetter2,wordLetter3,wordLetter4,wordLetter5,wordLetter6]; textLetters:=[twistLetter1,twistLetter2,twistLetter3,twistLetter4,twistLetter5,twistLetter6]; inherited:?ViewSetupFormScript(); end, word3: nil, dictionary6: nil, score: nil, debug: "main", canBeTwisted: nil, answer4: nil, setupBlankWords: func(values3,values4,values5,values6) begin answer3:=values3; answer4:=values4; answer5:=values5; answer6:=values6; Print("About to set dashes"); foreach blankBox in answer3 do SetValue(blankBox,'text,"- - -"); foreach blankBox in answer4 do SetValue(blankBox,'text,"- - - -"); foreach blankBox in answer5 do SetValue(blankBox,'text,"- - - - -"); foreach blankBox in answer6 do SetValue(blankBox,'text,"- - - - - -"); end, textLetters: nil, dictionary3: nil }; startButton := /* child of main */ {text: "Start Game", viewBounds: {left: 73, top: 269, bottom: 281, right: 153}, buttonClickScript: func() begin score:=0; :startGame(); end, debug: "startButton", _proto: @226 }; // View startButton is declared to main gameWord1 := /* child of main */ {text: nil, viewBounds: {left: 8, top: 146, right: 78, bottom: 163}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord1", _proto: @218 }; // View gameWord1 is declared to main enter := /* child of main */ { buttonClickScript: func() begin if theWord then begin local loopCounter:=0; if StrLen(theWord) = 3 then begin foreach realWord in dictionary3 do begin if StrEqual(realWord,theWord) then begin SetValue(answer3[word3],'text,theWord); ArrayRemoveCount(dictionary3,loopCounter,1); word3:=word3 + 1; lastWord:=theWord; lastWordLetters:=Clone(lastLetters); score:=score + 90; SetValue(gameTextBox,'text,"Score:" && NumberStr(score)); end; loopCounter:=loopCounter + 1; end; end; if StrLen(theWord) = 4 then begin foreach realWord in dictionary4 do begin if StrEqual(realWord,theWord) then begin SetValue(answer4[word4],'text,theWord); ArrayRemoveCount(dictionary4,loopCounter,1); word4:=word4 + 1; lastWord:=theWord; lastWordLetters:=Clone(lastLetters); score:=score + 160; SetValue(gameTextBox,'text,"Score:" && NumberStr(score)); end; loopCounter:=loopCounter + 1; end; end; if StrLen(theWord) = 5 then begin foreach realWord in dictionary5 do begin if StrEqual(realWord,theWord) then begin SetValue(answer5[word5],'text,theWord); ArrayRemoveCount(dictionary5,loopCounter,1); word5:=word5 + 1; lastWord:=theWord; lastWordLetters:=Clone(lastLetters); score:=score + 250; SetValue(gameTextBox,'text,"Score:" && NumberStr(score)); end; loopCounter:=loopCounter + 1; end; end; if StrLen(theWord) = 6 then begin foreach realWord in dictionary6 do begin if StrEqual(realWord,theWord) then begin continuePlaying:=1; SetValue(answer6[word6],'text,theWord); ArrayRemoveCount(dictionary6,loopCounter,1); word6:=word6 + 1; lastWord:=theWord; lastWordLetters:=Clone(lastLetters); score:=score + 360; SetValue(gameTextBox,'text,"Score:" && NumberStr(score)); end; loopCounter:=loopCounter + 1; end; end; if lastWord then SetValue(twist,'text,"Last Word"); :resetWord(); end; end;, text: "Enter", viewBounds: {left: 162, top: 94, right: 218, bottom: 110}, viewFormat: 593, debug: "enter", _proto: @226 }; // View enter is declared to main clear := /* child of main */ { buttonClickScript: func() begin :resetWord(); end, text: "Clear", viewBounds: {left: 8, top: 125, right: 64, bottom: 141}, viewFormat: 593, debug: "clear", _proto: @226 }; // View clear is declared to main last := /* child of main */ { buttonClickScript: func() begin if lastWord then begin letterCount:=StrLen(lastWord); SetValue(wordLetter1,'text,lastWordLetters[0]); SetValue(wordLetter2,'text,lastWordLetters[1]); SetValue(wordLetter3,'text,lastWordLetters[2]); if letterCount > 3 then SetValue(wordLetter4,'text,lastWordLetters[3]); else SetValue(wordLetter4,'text,nil); if letterCount > 4 then SetValue(wordLetter5,'text,lastWordLetters[4]); else SetValue(wordLetter5,'text,nil); if letterCount > 5 then SetValue(wordLetter6,'text,lastWordLetters[5]); else SetValue(wordLetter6,'text,nil); :findLetter(); end; end, text: "Last Word", viewBounds: {left: 162, top: 125, right: 218, bottom: 141}, viewFormat: 593 , debug: "last", _proto: @226 }; // View last is declared to main twist := /* child of main */ { buttonClickScript: func() begin :twistLetters(); end;, text: "Jumble", viewBounds: {left: 8, top: 94, right: 64, bottom: 110}, viewFormat: 593, debug: "twist", _proto: @226 }; // View twist is declared to main wordLetter6 := /* child of main */ {text: nil, viewBounds: {left: 188, top: 23, right: 218, bottom: 53}, viewFormat: 592, viewFont: editFont18, viewJustify: 8388614, debug: "wordLetter6", _proto: @218 }; // View wordLetter6 is declared to main wordLetter5 := /* child of main */ {text: nil, viewBounds: {left: 152, top: 23, right: 182, bottom: 53}, viewFormat: 592, viewFont: editFont18, viewJustify: 8388614, debug: "wordLetter5", _proto: @218 }; // View wordLetter5 is declared to main wordLetter4 := /* child of main */ {text: nil, viewBounds: {left: 116, top: 23, right: 146, bottom: 53}, viewFormat: 592, viewFont: editFont18, viewJustify: 8388614, debug: "wordLetter4", _proto: @218 }; // View wordLetter4 is declared to main wordLetter3 := /* child of main */ {text: nil, viewBounds: {left: 80, top: 23, right: 110, bottom: 53}, viewFormat: 592, viewFont: editFont18, viewJustify: 8388614, debug: "wordLetter3", _proto: @218 }; // View wordLetter3 is declared to main wordLetter2 := /* child of main */ {text: nil, viewBounds: {left: 44, top: 23, right: 74, bottom: 53}, viewFormat: 592, viewFont: editFont18, viewJustify: 8388614, debug: "wordLetter2", _proto: @218 }; // View wordLetter2 is declared to main wordLetter1 := /* child of main */ {text: nil, viewBounds: {left: 8, top: 23, right: 38, bottom: 53}, viewFormat: 592, viewFont: editFont18, viewJustify: 8388614, debug: "wordLetter1", _proto: @218 }; // View wordLetter1 is declared to main twistLetter6 := /* child of main */ {viewBounds: {left: 188, top: 59, right: 218, bottom: 88}, buttonClickScript: func() begin :clickedLetter(); end;, viewFormat: 593, text: nil, viewFont: editFont18, letter: nil, viewJustify: 8388614, clicked: nil, debug: "twistLetter6", _proto: @226 }; // View twistLetter6 is declared to main twistLetter5 := /* child of main */ {viewBounds: {left: 152, top: 59, right: 182, bottom: 88}, buttonClickScript: func() begin :clickedLetter(); end;, viewFormat: 593, text: nil, viewFont: editFont18, letter: nil, clicked: nil, viewJustify: 8388614, debug: "twistLetter5", _proto: @226 }; // View twistLetter5 is declared to main twistLetter4 := /* child of main */ {viewBounds: {left: 116, top: 59, right: 146, bottom: 88}, buttonClickScript: func() begin :clickedLetter(); end;, viewFormat: 593, text: nil, viewFont: editFont18, letter: nil, clicked: nil, viewJustify: 8388614, debug: "twistLetter4", _proto: @226 }; // View twistLetter4 is declared to main twistLetter3 := /* child of main */ {viewBounds: {left: 80, top: 59, right: 110, bottom: 88}, buttonClickScript: func() begin :clickedLetter(); end;, viewFormat: 593, viewFont: editFont18, text: nil, letter: nil, clicked: nil, viewJustify: 8388614, debug: "twistLetter3", _proto: @226 }; // View twistLetter3 is declared to main twistLetter2 := /* child of main */ {viewBounds: {left: 44, top: 59, right: 74, bottom: 88}, buttonClickScript: func() begin :clickedLetter(); end;, viewFormat: 593, text: nil, viewFont: editFont18, letter: nil, clicked: nil, viewJustify: 8388614, debug: "twistLetter2", _proto: @226 }; // View twistLetter2 is declared to main twistLetter1 := /* child of main */ {viewBounds: {left: 8, top: 59, right: 38, bottom: 88}, buttonClickScript: func() begin :clickedLetter(); end;, viewFormat: 593, text: nil, viewFont: editFont18, letter: nil, clicked: nil, viewJustify: 8388614, debug: "twistLetter1", _proto: @226 }; // View twistLetter1 is declared to main gameWord2 := /* child of main */ {text: nil, viewBounds: {left: 8, top: 163, right: 78, bottom: 180}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord2", _proto: @218 }; // View gameWord2 is declared to main gameWord3 := /* child of main */ {text: nil, viewBounds: {left: 8, top: 180, right: 78, bottom: 197}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord3", _proto: @218 }; // View gameWord3 is declared to main gameWord4 := /* child of main */ {text: nil, viewBounds: {left: 8, top: 197, right: 78, bottom: 214}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord4", _proto: @218 }; // View gameWord4 is declared to main gameWord5 := /* child of main */ {text: nil, viewBounds: {left: 8, top: 214, right: 78, bottom: 231}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord5", _proto: @218 }; // View gameWord5 is declared to main gameWord6 := /* child of main */ {text: nil, viewBounds: {left: 8, top: 231, right: 78, bottom: 248}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord6", _proto: @218 }; // View gameWord6 is declared to main gameWord7 := /* child of main */ {text: nil, viewBounds: {left: 8, top: 248, bottom: 265, right: 78}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord7", _proto: @218 }; // View gameWord7 is declared to main gameWord8 := /* child of main */ {text: nil, viewBounds: {left: 78, top: 146, right: 148, bottom: 163}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord8", _proto: @218 }; // View gameWord8 is declared to main gameWord9 := /* child of main */ {text: nil, viewBounds: {left: 78, top: 163, right: 148, bottom: 180}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord9", _proto: @218 }; // View gameWord9 is declared to main gameWord10 := /* child of main */ {text: nil, viewBounds: {left: 78, top: 180, right: 148, bottom: 197}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord10", _proto: @218 }; // View gameWord10 is declared to main gameWord11 := /* child of main */ {text: nil, viewBounds: {left: 78, top: 197, right: 148, bottom: 214}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord11", _proto: @218 }; // View gameWord11 is declared to main gameWord12 := /* child of main */ {text: nil, viewBounds: {left: 78, top: 214, right: 148, bottom: 231}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord12", _proto: @218 }; // View gameWord12 is declared to main gameWord13 := /* child of main */ {text: nil, viewBounds: {left: 78, top: 231, right: 148, bottom: 248}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord13", _proto: @218 }; // View gameWord13 is declared to main gameWord14 := /* child of main */ {text: nil, viewBounds: {left: 78, top: 248, bottom: 265, right: 148}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord14", _proto: @218 }; // View gameWord14 is declared to main gameWord15 := /* child of main */ {text: nil, viewBounds: {left: 148, top: 146, right: 218, bottom: 163}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord15", _proto: @218 }; // View gameWord15 is declared to main gameWord16 := /* child of main */ {text: nil, viewBounds: {left: 148, top: 163, right: 218, bottom: 180}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord16", _proto: @218 }; // View gameWord16 is declared to main gameWord17 := /* child of main */ {text: nil, viewBounds: {left: 148, top: 180, right: 218, bottom: 197}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord17", _proto: @218 }; // View gameWord17 is declared to main gameWord18 := /* child of main */ {text: nil, viewBounds: {left: 148, top: 197, right: 218, bottom: 214}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord18", _proto: @218 }; // View gameWord18 is declared to main gameWord19 := /* child of main */ {text: nil, viewBounds: {left: 148, top: 214, right: 218, bottom: 231}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord19", _proto: @218 }; // View gameWord19 is declared to main gameWord20 := /* child of main */ {text: nil, viewBounds: {left: 148, top: 231, right: 218, bottom: 248}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord20", _proto: @218 }; // View gameWord20 is declared to main gameWord21 := /* child of main */ {text: nil, viewBounds: {left: 148, top: 248, bottom: 265, right: 218}, viewFont: editFont12, viewJustify: 8388614, debug: "gameWord21", _proto: @218 }; // View gameWord21 is declared to main timeCountdown := /* child of main */ {value: 0, maxValue: 999, minValue: 0, viewBounds: {left: 82, top: 117, right: 144, bottom: 143}, viewFlags: 3, debug: "timeCountdown", _proto: @72 }; // View timeCountdown is declared to main gameTextBox := /* child of main */ {text: "score:0", viewBounds: {left: 68, top: 92, right: 158, bottom: 112}, viewFont: simpleFont9, viewJustify: 6, ViewIdleScript: func() begin if timeCountdown.value > 0 then begin timeCountdown.value:=timeCountdown.value - 1; timeCountdown:Close(); timeCountdown:Open(); return 1000; // Return the number of milliseconds to delay or nil to end idling. end; else begin SetValue(gameTextBox,'text,"Out of Time"); playingGame:=nil; winBox:Open(); return 0; end; end, debug: "gameTextBox", _proto: @218 }; // View gameTextBox is declared to main winBox := /* child of main */ {viewBounds: {left: -3, top: 65, bottom: 130, right: 151}, ViewSetupFormScript: // be sure to call inherited:?ViewSetupFormScript() func() begin if continuePlaying then SetValue(winner,'text,"Get ready for the next round.\nYour score is " & score & "."); else SetValue(winner,'text,"Your score is " & score & "."); inherited:?ViewSetupFormScript(); end, ViewHideScript: func() begin Print("About to empty all boxes"); foreach blankBox in answer3 do SetValue(blankBox,'text,nil); foreach blankBox in answer4 do SetValue(blankBox,'text,nil); foreach blankBox in answer5 do SetValue(blankBox,'text,nil); foreach blankBox in answer6 do SetValue(blankBox,'text,nil); Print("Finished ViewHideScript"); if continuePlaying then :startGame(); end, viewJustify: 16, debug: "winBox", _proto: @180 }; // View winBox is declared to main winner := /* child of winBox */ {text: nil, viewBounds: {left: 0, top: 5, bottom: -5, right: 0}, viewJustify: 240, debug: "winner", _proto: @218 }; // View winner is declared to main constant |layout_text.lyt| := main; // End of file text.lyt