Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

2005年に作ったゲーム「length」

Posted on 7月 23, 2022 by Takaaki Naganoya

はるかかなた昔、2005年に作ったゲームのソースが出てきました。日本語でコメントを書いてあったのですが、文字化けしていて作った本人にも読めません。作ったまま忘れていたので、掲載しておきます。

# ユーザー名を求める処理だけMac OS X→OS X→macOSと推移してそのまま動作しなかったので、書き換えをおこなっています

ゲーム名は「length」です。指定の文字数のアルファベットを入力すると、システム辞書を検索して、そのアルファベットで始まる英単語を検索します。

ゲームルールは「Count Up」と「Count Down」の2種類があり、入力文字ではじまる英単語がだんだん増えていくように解答するのが「Count Up」、だんだん少なくなるように答えていくのが「Count Down」モードです。


▲ゲームタイトル表示


▲入力アルファベット数の選択。長くなるとヒットする単語が少なくなるので難しい。2か3ぐらいが適当?


▲ゲームルール選択。ヒットする単語数が少なくなっていくように答える「countDown」と、増えていくように答える「countUp」。countUpのほうが簡単


▲ゲームスタート


▲ここで文字入力


▲1単語だけヒットした


▲続いて文字入力


▲5単語ヒットした


▲424単語ヒット!


▲389単語ヒット! 前の答えよりも減ってしまった! Count up失敗!


▲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
2005?N 9?? 11?? ???j?? 10:05:51 PM?Åc?o?[?W?????A?b?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

★Click Here to Open This Script 

More from my site

  • AS関連データの取り扱いを容易にする(はずの)privateDataTypeLibAS関連データの取り扱いを容易にする(はずの)privateDataTypeLib
  • Bundle IDで指定したアプリケーションのSDEFからコマンドを抽出テスト(指定コマンドのコマンド属性取り出し)Bundle IDで指定したアプリケーションのSDEFからコマンドを抽出テスト(指定コマンドのコマンド属性取り出し)
  • 新発売:AppleScript基礎テクニック集(23)サブルーチン、ハンドラ新発売:AppleScript基礎テクニック集(23)サブルーチン、ハンドラ
  • 新発売:AppleScript基礎テクニック集(22)スクリプトメニューの使い方新発売:AppleScript基礎テクニック集(22)スクリプトメニューの使い方
  • display text view Script Library v2.2をリリースdisplay text view Script Library v2.2をリリース
  • display text view Script Library v2.1をリリースdisplay text view Script Library v2.1をリリース
(Visited 55 times, 1 visits today)
Posted in GAME | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • macOS 13, Ventura(継続更新)
  • アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3
  • UI Browserがgithub上でソース公開され、オープンソースに
  • Xcode 14.2でAppleScript App Templateを復活させる
  • macOS 13 TTS Voice環境に変更
  • 2022年に書いた価値あるAppleScript
  • ChatGPTで文章のベクトル化(Embedding)
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた
  • 従来と異なるmacOS 13の性格?
  • 新発売:CotEditor Scripting Book with AppleScript
  • macOS 13対応アップデート:AppleScript実践的テクニック集(1)GUI Scripting
  • AS関連データの取り扱いを容易にする(はずの)privateDataTypeLib
  • macOS 13でNSNotFoundバグふたたび
  • macOS 12.5.1、11.6.8でFinderのselectionでスクリーンショット画像をopenできない問題
  • ChatGPTでchatに対する応答文を取得
  • 新発売:iWork Scripting Book with AppleScript
  • Finderの隠し命令openVirtualLocationが発見される
  • macOS 13.1アップデートでスクリプトエディタの挙動がようやくまともに
  • あのコン過去ログビューワー(暫定版)

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (277) 12.0savvy (185) 13.0savvy (55) CotEditor (60) Finder (47) iTunes (19) Keynote (98) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (41) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (117) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (56) Pages (37) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) WKUserScriptInjectionTimeAtDocumentEnd (18) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • Clipboard
  • Code Sign
  • Color
  • Custom Class
  • dialog
  • drive
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • PDF
  • Peripheral
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC