はるかかなた昔、2005年に作ったゲームのソースが出てきました。日本語でコメントを書いてあったのですが、文字化けしていて作った本人にも読めません。作ったまま忘れていたので、掲載しておきます。
# ユーザー名を求める処理だけMac OS X→OS X→macOSと推移してそのまま動作しなかったので、書き換えをおこなっています
ゲーム名は「length」です。指定の文字数のアルファベットを入力すると、システム辞書を検索して、そのアルファベットで始まる英単語を検索します。
ゲームルールは「Count Up」と「Count Down」の2種類があり、入力文字ではじまる英単語がだんだん増えていくように解答するのが「Count Up」、だんだん少なくなるように答えていくのが「Count Down」モードです。
▲入力アルファベット数の選択。長くなるとヒットする単語が少なくなるので難しい。2か3ぐらいが適当?
▲ゲームルール選択。ヒットする単語数が少なくなっていくように答える「countDown」と、増えていくように答える「countUp」。countUpのほうが簡単
▲389単語ヒット! 前の答えよりも減ってしまった! Count up失敗!
AppleScript名:length v0.5.scpt 【コメント】 ?uLeng???Q?[??v0.4?v 2005?N 9?? 11?? ???j?? 11:37:00 PM?Åc?o?[?W?????A?b?v ?uLeng???Q?[??v0.3?v |
use AppleScript version "2.4" use scripting additions use framework "Foundation" property prefFileName : "jp.piyomarusoft.length" property dataVer : 1.0 property emptyHscore : {{{0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}}, {{0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}, {0, "Piyomaru", "2005/9/5", {}}}} display dialog ("Length GAME" & return & return & "version 1.0 By Piyomaru Software") buttons {"OK"} default button 1 giving up after 3 with title "Welcome!" set lenList to {2, 3, 4, 5, 6, 7, 8} set aRes to (choose from list lenList with prompt "please select the length of battle keyword" default items 3) if aRes = false then return set bRes to aRes as number set histNum to {} set histKeywords to {} set scoreNum to 0 set ansHist to {} set ruleList to {"Count Down", "Count Up"} set ruleRes to (choose from list ruleList with prompt "Select Game Rule" default items "Count Up") if ruleRes = false then return set ruleRes to ruleRes as string if ruleRes = "Count Down" then –Count Down set prevNum to 9999999 else –Count Up set prevNum to 0 end if —ÉnÉCÉXÉRÉAÇÃämîFÇ®ÇÊÇ—ÉnÉCÉXÉRÉAèÓïÒÇÃê›íË set hsList to writeHighScore(0, bRes, "", "", {}, ruleRes) of me set highScore to item 1 of hsList set greatPerson to item 2 of hsList display dialog "GAME START" buttons {"OK"} default button 1 giving up after 2 —ÉÅÉCÉìÉãÅ[Év repeat —ÉLÅ[ÉèÅ[Éhì¸óÕÉãÅ[Évïîï™ repeat if length of ansHist is not equal to 0 then —í èÌèàóù set aText to "History: [" & retArrowText(histNum) of me & "]" & return & return else —èââÒÇÃÇ› set aText to "" end if set titleText to "LENGTH GAME (" & ruleRes & " MODE) " set mesText to ("SCORE:" & scoreNum as string) & return & return & aText & ("Input some keyword in English" & " ( Just " & bRes as string) & " characters.)" set a to text returned of (display dialog mesText default answer "" with title titleText) —ï∂éöéÌófiÇÉ`ÉFÉbÉN set kRes to checkAN(a) of me if kRes = false then display dialog "Wrong Character…." buttons {"OK"} default button 1 else —í∑Ç≥ÇÉ`ÉFÉbÉN if (length of a) is not equal to bRes then set tmpRes to (display dialog "Ooops!" & return & "The length of your keyword is not equal to " & aRes & "!" & return & "Try another keyword." buttons {"QUIT", "Again!"} default button 2 with title "Wrong Length") if tmpRes = "QUIT" then display dialog "—Goodbye—" buttons {"OK"} default button 1 giving up after 3 return end if else —âflãéÇÃâÒìöÇ∆èdï°ÇµÇƒÇ¢Ç»Ç¢Ç©É`ÉFÉbÉN if a is not in ansHist then exit repeat else set tmpRes to (display dialog "Ooops! " & a & " is already answerd! Try another word." buttons {"QUIT", "Again!"} default button 2 with title "Wrong Keyword") if tmpRes = "QUIT" then display dialog "—Goodbye—" buttons {"OK"} default button 1 giving up after 3 return end if end if end if end if end repeat –lookÉRÉ}ÉìÉhÇ≈ÉqÉbÉgÉLÅ[ÉèÅ[ÉhêîÇìæÇÈ set ansRes to getHitWords(a) of me —DZDZǩÇÁìñÇΩÇËîªíËÇ∆Ç©Ç¢ÇÎÇ¢ÇÎ if ruleRes = "Count Down" then –Count DownÇÃèÍçá if ansRes < prevNum and ansRes is not equal to 0 then set scoreNum to scoreNum + 1 set prevNum to ansRes else —ÉQÅ[ÉÄÉIÅ[ÉoÅ[ÇÃèàóù set tmpRes to (display dialog ("You lose!" & return & " SCORE:" & scoreNum as string) buttons {"OK"} default button 1) —ÉnÉCÉXÉRÉAèàóù if highScore < scoreNum then —ÉnÉCÉXÉRÉAÉâÅ[ÇÃñºëOÇÃéÊìæÇæÇØ set greatPerson to recHighScore(scoreNum, highScore) of me —é¿ç€Ç…ÉtÉ@ÉCÉãÇ…îΩâf set aDate to do shell script "date +%Y/%m/%d" set dummyList to writeHighScore(scoreNum, bRes, greatPerson, aDate, {ansHist, histNum}, ruleRes) of me end if —èIóπ return end if else –Count UpÇÃèÍçá if ansRes > prevNum then set scoreNum to scoreNum + 1 set prevNum to ansRes else —ÉQÅ[ÉÄÉIÅ[ÉoÅ[ÇÃèàóù set tmpRes to (display dialog ("You lose!" & return & " SCORE:" & scoreNum as string) buttons {"OK"} default button 1) —ÉnÉCÉXÉRÉAèàóù if highScore < scoreNum then —ÉnÉCÉXÉRÉAÉâÅ[ÇÃñºëOÇÃéÊìæÇæÇØ set greatPerson to recHighScore(scoreNum, highScore) of me —é¿ç€Ç…ÉtÉ@ÉCÉãÇ…îΩâf set aDate to do shell script "date +%Y/%m/%d" set dummyList to writeHighScore(scoreNum, bRes, greatPerson, aDate, {ansHist, histNum}, ruleRes) of me end if —èIóπ return end if end if set the end of ansHist to a set the end of histNum to ansRes end repeat —ï∂éöéÌófiÅiÉAÉãÉtÉ@ÉxÉbÉgÅjÇÃÉ`ÉFÉbÉN on checkAN(aKeyword) set anList to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} set aKeyword to aKeyword as Unicode text set aKeyword to aKeyword as string set kList to characters of aKeyword repeat with i in kList ignoring case if i is not in anList then return false end if end ignoring end repeat return true end checkAN on recHighScore(scoreNum, highScore) if scoreNum > highScore then set highScore to scoreNum set myShortName to word 1 of (do shell script "who am i") set myHomeDirectory to do shell script "echo ~" set theResponse to current application’s NSFullUserName() as string –set getFullNameScript to "nicl . -read /users/" & myShortName & " realname" –set theResponse to do shell script getFullNameScript set myFullName to (characters 11 through (length of theResponse) of theResponse) as string set pRes to text returned of (display dialog "Input Your Name:" default answer myFullName with title "You made high-score!!") if pRes = false or pRes = "" then set greatPerson to "Anonymous" else set greatPerson to pRes as string end if end if return greatPerson end recHighScore on retArrowText(aList) set aText to "" set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to " -> " set aText to aList as text set AppleScript’s text item delimiters to curDelim return aText end retArrowText on getHitWords(a) set c to "" set b to "" try set b to do shell script "look " & a & " | wc -l" set c to do shell script "look " & a if (b as number) > 30 then set cList to paragraphs of c if b as number > 300 then set limitNum to 300 else set limitNum to b as number end if set cItem to items 1 thru limitNum of cList set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to ", " set ccItem to cItem as string set AppleScript’s text item delimiters to curDelim set c to ccItem end if display dialog b & " Hits!" & return & c on error display dialog "0 hits" buttons {"OK"} default button 1 return 0 end try return b as number end getHitWords —ó^ǶÇΩÉfÅ[É^Ç™ÉnÉCÉXÉRÉAÇ…äYìñÇ∑ÇÈèÍçáÇ…ÇÕÅAǪÇÃé|ï\é¶ÇµÇ¬Ç¬ÉfÅ[É^Ç…ãLò^Ç∑ÇÈ —åãâ Ç∆ǵǃéwíËÉRÅ[ÉXÇÃÉnÉCÉXÉRÉAÉfÅ[É^Çï‘ǵǃÇ≠ÇÈÇÃÇ≈ÅA —Ç∆ÇËdžǶÇ∏ÅAÉnÉCÉXÉRÉAÇ…Ç»ÇÁÇ»Ç≥ǪǧǻÉfÅ[É^Çì¸ÇÍǃåƒÇ—èoÇπÇŒ —ÉnÉCÉXÉRÉAÇÃämîFÇ™çsǶÇÈ on writeHighScore(aScore, aLength, aPerson, aDate, aHist, aRule) set pPath to path to library folder from user domain set pPath to (pPath as string) & "Preferences:" set pPath to pPath as Unicode text set pFile to pPath & prefFileName tell application "Finder" if file "jp.piyomarusoft.length" of alias pPath exists then —Ç∑Ç≈Ç…ê›íËÉtÉ@ÉCÉãÇ™ë∂ç›Ç∑ÇÈèÍçá try set hScore to read alias pFile as list –anAliasÇ…ÇÕÉtÉ@ÉCÉãÉGÉCÉäÉAÉXÇ™ì¸Ç¡ÇƒÇ¢ÇÈ on error —âΩÇÁÇ©ÇÃÉtÉ@ÉCÉãä÷åWÇÃÉGÉâÅ[Ç™î≠ê∂ǵÇΩèÍçáÇ÷ÇÃëŒèà set hScore to emptyHscore end try else —Ç‹Çæê›íËÉtÉ@ÉCÉãÇ™ë∂ç›ÇµÇ»Ç¢èÍçá —ïœêîÇÃèâä˙⪠–item1 is count up, item2 is Count down set hScore to emptyHscore end if end tell –display dialog aRule if aRule is "Count Up" then set iSel1 to 1 else set iSel1 to 2 end if set realLength to (aLength – 1) if (item 1 of item realLength of item iSel1 of hScore) < aScore then –display dialog "You made High-Score" buttons {"OK"} default button 1 set item realLength of item iSel1 of hScore to {aScore, aPerson, aDate, aHist} set aRes to write_to_file(hScore, pFile, false) of me if aRes = false then display dialog "File I/O Error!" buttons {"OK"} default button 1 return else (* –ÉtÉ@ÉCÉãÉ^ÉCÉvÇèëÇ´ä∑ǶǃÅAÉeÉLÉXÉgÉGÉfÉBÉ^Ç≈äJÇ©ÇÍÇÈDZÇ∆ÇñhÇÆÇΩÇflÇÃÉeÉXÉg do shell script "sync" –set anAlias to pFile as alias tell application "Finder" –set kind of file pFile to "" –set file type of file pFile to "" –set file creator of file pFile to "" end tell *) end if end if set retList to item realLength of item iSel1 of hScore return retList end writeHighScore —ÉtÉ@ÉCÉãÇÃí«ãLÉãÅ[É`ÉìÅuwrite_to_fileÅv —í«ãLÉfÅ[É^ÅAí«ãLëŒè€ÉtÉ@ÉCÉãÅAbooleanÅitrueÇ≈í«ãLÅj on write_to_file(this_data, target_file, append_data) try set the target_file to the target_file as text set the open_target_file to open for access file target_file with write permission if append_data is false then set eof of the open_target_file to 0 write this_data to the open_target_file starting at eof close access the open_target_file return true on error error_message try close access file target_file end try return error_message end try end write_to_file |