※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!

wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)

 notice: Flash editor updated! Join the development! Thanks to MiniBuilder


forked from : nitoyon's Enumerate Prime Numbers (227letters) (Sieve of Eratosthenes) [diff(221)]

FORKED

落ち着け・・・素数を数えて落ち着くんだ・・・ 泣いて馬謖を斬る [diff(195)]

  1. // forked from undo's 落ち着け・・・素数を数えて落ち着くんだ・・・
  2. // forked from nitoyon's Enumerate Prime Numbers (227letters) (Sieve of Eratosthenes)
  3. // inspired by http://twitter.com/javascripter/statuses/8367943818
  4. package {
  5.     import flash.display.*;
  6.     import flash.text.*;
  7.     import flash.events.*;
  8.     
  9.     public class BashokuGame extends Sprite {
  10.         private var defaultText:String = "\n"+"また馬謖が失敗しました。馬謖を斬ってください。";
  11.         private var shogun:Array;
  12.         private var killedNum:int;
  13.         private var i:int;
  14.         private var ryuzenNum:int = 0;
  15.         
  16.     private var tf:TextField;
  17.     private var sbtn:Button;
  18.     private var yes:Button;
  19.     private var no:Button;
  20.             
  21.     public function BashokuGame() {
  22.         shogun = ["劉禅","馬謖","馬謖","馬謖","馬謖","馬謖","馬忠""馬超","馬岱","馬良","馬騰","馬休","馬鉄","赤兎馬"];
  23.         tf = new TextField();
  24.         tf.autoSize = TextFieldAutoSize.CENTER;
  25.         var tform:TextFormat = new TextFormat();
  26.         tform.align = TextFormatAlign.CENTER;
  27.         tf.defaultTextFormat = tform;
  28.         tf.text = defaultText;
  29.         addChild(tf);
  30.         tf.x = stage.stageWidth/2 - tf.textWidth/2;
  31.         tf.y = 100;
  32.           
  33.         sbtn = new Button("game start"150);
  34.         //sbtn.width = 150;
  35.         sbtn.x = stage.stageWidth/2 - sbtn.width/2;
  36.         sbtn.y = 200;
  37.         sbtn.addEventListener(MouseEvent.CLICK, onClick);
  38.         addChild(sbtn);
  39.                         
  40.         yes = new Button("泣いて斬る"100);
  41.         yes.x = stage.stageWidth/2 - yes.width - 10;
  42.         yes.y = 200;
  43.         yes.addEventListener(MouseEvent.CLICK, onYes);
  44.         addChild(yes);
  45.             
  46.         no = new Button("斬らない"100);
  47.         no.x = stage.stageWidth/2 + 10;
  48.         no.y = 200;
  49.         no.addEventListener(MouseEvent.CLICK, onNo);
  50.         addChild(no);
  51.         
  52.         yes.visible = false;
  53.         no.visible = false;
  54.         }
  55.     private function onClick(evt:MouseEvent):void{
  56.         startGame();
  57.     }
  58.         
  59.     private function startGame():void{
  60.         sbtn.visible = false;
  61.         yes.visible = true;
  62.         no.visible = true;
  63.         killedNum = 0;
  64.             
  65.         i = Math.floor(Math.random() * shogun.length);
  66.             
  67.         tf.text = "\n"+shogun[i];
  68.     }
  69.           
  70.         private function onYes(evt:Event):void{
  71.         check(true);
  72.     }
  73.             
  74.     private function onNo(evt:Event):void{
  75.         check(false);
  76.     }
  77.             
  78.     private function check(b:Boolean):void {
  79.         if (b) {
  80.         if (shogun[i] == "馬謖"||shogun[i] == "劉禅") {
  81.                 killedNum++;
  82.             i = Math.floor(Math.random() * shogun.length);
  83.             tf.text = "\n"+shogun[i];
  84.         }
  85.         else {
  86.             endGame();
  87.         } 
  88.         }else {
  89.             if (shogun[i] != "馬謖" && shogun[i] != "劉禅") {
  90.                 i = Math.floor(Math.random() * shogun.length);
  91.                 tf.text = "\n"+shogun[i];
  92.             }
  93.             else {
  94.                 endGame();
  95.             }
  96.             }
  97.         }
  98.             
  99.     private function endGame():void {
  100.         sbtn.visible = true;
  101.         yes.visible = false;
  102.         no.visible = false;
  103.         tf.text = "\n"+"GAME OVER"+"\n"+String(killedNum)+"人の馬謖を斬りました";
  104.     }
  105.             
  106.     }
  107. }
  108. import flash.display.*;
  109. import flash.text.*;
  110. class Button extends SimpleButton
  111. {
  112.     public function Button(label:String, width:int = 0):void
  113.     {
  114.         var up:Sprite = _buildImage(label, 0x0, width);
  115.         var over:Sprite = _buildImage(label, 0x333333, width);
  116.         var down:Sprite = _buildImage(label, 0x333333, width);
  117.         down.y = 1;
  118.         super(up, over, down, up);
  119.     }
  120.     private static function _buildImage(label:String, color:int, width:int = 0):Sprite
  121.     {
  122.         var text:TextField = new TextField();
  123.         text.defaultTextFormat = new TextFormat('Verdana'10, 0xffffff, truenullnullnullnull, TextFormatAlign.CENTER);
  124.         text.autoSize = TextFieldAutoSize.LEFT;
  125.         text.selectable = false;
  126.         text.text = label;
  127.         text.x = (width - text.width) >> 1;
  128.         text.y = 5;
  129.         var base:Shape = new Shape();
  130.         var g:Graphics = base.graphics;
  131.         g.beginFill(color);
  132.         g.drawRect(00, width, text.height + 10);
  133.         g.endFill();
  134.         var sp:Sprite = new Sprite();
  135.         sp.addChild(base); 
  136.         sp.addChild(text);
  137.         return sp;
  138.     }
  139. }
noswf

落ち着け・・・素数を数えて落ち着くんだ・・・ forked from: 落ち着け・・・素数を数えて落ち着くんだ・・・ [diff(1)]

  1. // forked from undo's 落ち着け・・・素数を数えて落ち着くんだ・・・
  2. // forked from nitoyon's Enumerate Prime Numbers (227letters) (Sieve of Eratosthenes)
  3. // inspired by http://twitter.com/javascripter/statuses/8367943818
  4. package{
  5.     import flash.text.*;
  6.     import flash.display.*;
  7.     import flash.events.*;
  8.     import flash.net.*;
  9.     import flash.utils.escapeMultiByte;
  10.         
  11.     public class C extends Sprite
  12.     {
  13.         private var defaultText:String = "\n落ち着け・・・素数を数えて落ち着くんだ・・・\n\n素数だと思ったら「落ち着く」ボタン またはキーボードの→キー\n素数じゃないと思ったら「落ち着かない」ボタン またはキーボードの←キー\n\nを押すんだ・・・";
  14.         private var a:Array = [];
  15.         private var i:int = 0;
  16.         private var lastNum:int = 0;
  17.         private var thisURL:String = http://bit.ly/995VYH %23wonderfl";
  18.         
  19.         private var tf:TextField;
  20.         private var sbtn:Button;
  21.         private var pbtn:Button;
  22.         private var yes:Button;
  23.         private var no:Button;
  24.         public function C()
  25.         {
  26.             for (var c:int = 1, d:int; c++<1E3; )
  27.             {
  28.                 if (!a[c])
  29.                 {
  30.                     for (d=c; d<1E3; )
  31.                     {
  32.                         a[d+=c]=1;
  33.                     }
  34.                 }
  35.             }
  36.             
  37.         tf = new TextField();
  38.         tf.autoSize = TextFieldAutoSize.CENTER;
  39.         var tform:TextFormat = new TextFormat();
  40.         tform.align = TextFormatAlign.CENTER;
  41.         tf.defaultTextFormat = tform;
  42.         tf.text = defaultText;
  43.         addChild(tf);
  44.         tf.x = stage.stageWidth/2 - tf.textWidth/2;
  45.         tf.y = 100;
  46.             
  47.         sbtn = new Button("[spaceキー] ゲームスタート"150);
  48.         //sbtn.width = 150;
  49.         sbtn.x = stage.stageWidth/2 - sbtn.width/2;
  50.         sbtn.y = 200;
  51.         sbtn.addEventListener(MouseEvent.CLICK, onClick);
  52.         addChild(sbtn);
  53.             
  54.         pbtn = new Button("twitterにポスト"100);
  55.         pbtn.x = stage.stageWidth/2 - pbtn.width/2;
  56.         pbtn.y = 250;
  57.         pbtn.visible = false;
  58.         pbtn.addEventListener(MouseEvent.CLICK, post);
  59.         addChild(pbtn);
  60.             
  61.         yes = new Button("→落ち着く"100);
  62.         yes.x = stage.stageWidth/2 + 10;
  63.         yes.y = 200;
  64.         yes.addEventListener(MouseEvent.CLICK, onYes);
  65.         addChild(yes);
  66.             
  67.         no = new Button("落ち着かない←"100);
  68.         no.x = stage.stageWidth/2 - no.width - 10;
  69.         no.y = 200;
  70.         no.addEventListener(MouseEvent.CLICK, onNo);
  71.         addChild(no);
  72.             
  73.         yes.visible = false;
  74.         no.visible = false;
  75.             
  76.         stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
  77.                 }
  78.         private function onClick(evt:MouseEvent):void
  79.         {
  80.             startGame();
  81.         }
  82.             
  83.         private function startGame():void
  84.         {
  85.             sbtn.visible = false;
  86.             pbtn.visible = false;
  87.             yes.visible = true;
  88.             no.visible = true;
  89.             
  90.             lastNum = 0;
  91.             
  92.             tf.text = String(i);
  93.         }
  94.             
  95.         private function onYes(evt:Event):void
  96.         {
  97.             check(true);
  98.         }
  99.             
  100.         private function onNo(evt:Event):void
  101.         {
  102.             check(false);
  103.         }
  104.             
  105.         private function onKeyDown(evt:KeyboardEvent):void
  106.         {
  107.             switch (evt.keyCode)
  108.             {
  109.                 case 32 :
  110.                     if (sbtn.visible)
  111.                     {
  112.                         startGame();
  113.                     }
  114.                     break;
  115.                 case 39 :
  116.                     if (yes.visible)
  117.                     {
  118.                         check(true);
  119.                     }
  120.                     break;
  121.                 case 37 :
  122.                     if (no.visible)
  123.                     {
  124.                         check(false);
  125.                     }
  126.                     break;
  127.                 default :
  128.                     break;
  129.             }
  130.         }
  131.             
  132.         private function check(b:Boolean):void
  133.         {
  134.             if (i == 0 || i == 1)
  135.             {
  136.                 if (b)
  137.                 {
  138.                     endGame();
  139.                     return;
  140.                 }
  141.             }
  142.             else
  143.             {
  144.                 if (a[i] && b)
  145.                 {
  146.                     endGame();
  147.                     return;
  148.                 }
  149.                 else if (!a[i] && !b)
  150.                 {
  151.                     endGame();
  152.                     return;
  153.                 }
  154.             }
  155.             
  156.             if(!a[i]) lastNum = i;
  157.             i++;
  158.             tf.text = String(i);
  159.         }
  160.             
  161.         private function endGame():void
  162.         {
  163.             sbtn.visible = true;
  164.             pbtn.visible = true;
  165.             yes.visible = false;
  166.             no.visible = false;
  167.             
  168.             if(lastNum == 0 || lastNum == 1) tf.text = "メメタァ\n\n最後に数えた素数:なし";
  169.             else tf.text = "メメタァ\n\n最後に数えた素数:"+lastNum;
  170.             
  171.             i = 0;
  172.         }
  173.             
  174.         private function post(evt:MouseEvent):void
  175.         {
  176.             var st:String;
  177.             if(lastNum== -1)
  178.             {
  179.                 st = "http://twitter.com/home?status="+escapeMultiByte("素数を数えられませんでした。") + thisURL;
  180.             }
  181.             else
  182.             {
  183.                 st = "http://twitter.com/home?status=" + lastNum + escapeMultiByte("まで素数を数えて落ち着きました。") + thisURL;
  184.             }
  185.             navigateToURL(new URLRequest(st));
  186.         }            
  187.     }
  188. }
  189. import flash.display.*;
  190. import flash.text.*;
  191. class Button extends SimpleButton
  192. {
  193.     public function Button(label:String, width:int = 0):void
  194.     {
  195.         var up:Sprite = _buildImage(label, 0x0, width);
  196.         var over:Sprite = _buildImage(label, 0x333333, width);
  197.         var down:Sprite = _buildImage(label, 0x333333, width);
  198.         down.y = 1;
  199.         super(up, over, down, up);
  200.     }
  201.     private static function _buildImage(label:String, color:int, width:int = 0):Sprite
  202.     {
  203.         var text:TextField = new TextField();
  204.         text.defaultTextFormat = new TextFormat('Verdana'10, 0xffffff, truenullnullnullnull, TextFormatAlign.CENTER);
  205.         text.autoSize = TextFieldAutoSize.LEFT;
  206.         text.selectable = false;
  207.         text.text = label;
  208.         text.x = (width - text.width) >> 1;
  209.         text.y = 5;
  210.         var base:Shape = new Shape();
  211.         var g:Graphics = base.graphics;
  212.         g.beginFill(color);
  213.         g.drawRect(00, width, text.height + 10);
  214.         g.endFill();
  215.         var sp:Sprite = new Sprite();
  216.         sp.addChild(base);
  217.         sp.addChild(text);
  218.         return sp;
  219.     }
  220. }
noswf

落ち着け・・・素数を数えて落ち着くんだ・・・ forked from: 落ち着け・・・素数を数えて落ち着くんだ・・・ [diff(4)]

  1. // forked from undo's 落ち着け・・・素数を数えて落ち着くんだ・・・
  2. // forked from nitoyon's Enumerate Prime Numbers (227letters) (Sieve of Eratosthenes)
  3. // inspired by http://twitter.com/javascripter/statuses/8367943818
  4. package{
  5.     import flash.text.*;
  6.     import flash.display.*;
  7.     import flash.events.*;
  8.     import flash.net.*;
  9.     import flash.utils.escapeMultiByte;
  10.         
  11.     public class C extends Sprite
  12.     {
  13.         private var startNum:int = 2e3;
  14.         private var defaultText:String = "\n落ち着け・・・素数を数えて落ち着くんだ・・・\n\n素数だと思ったら「落ち着く」ボタン またはキーボードの→キー\n素数じゃないと思ったら「落ち着かない」ボタン またはキーボードの←キー\n\nを押すんだ・・・";
  15.         private var a:Array = [];
  16.         private var i:int = startNum; // 最初に生成される素数表以上数えるともう何でも落ち着く悟りの境地に!!
  17.         private var lastNum:int = 0;
  18.         private var thisURL:String = http://bit.ly/995VYH %23wonderfl";
  19.         
  20.         private var tf:TextField;
  21.         private var sbtn:Button;
  22.         private var pbtn:Button;
  23.         private var yes:Button;
  24.         private var no:Button;
  25.         public function C()
  26.         {
  27.             for (var c:int = 1, d:int; c++<1E3; )
  28.             {
  29.                 if (!a[c])
  30.                 {
  31.                     for (d=c; d<1E3; )
  32.                     {
  33.                         a[d+=c]=1;
  34.                     }
  35.                 }
  36.             }
  37.             
  38.         tf = new TextField();
  39.         tf.autoSize = TextFieldAutoSize.CENTER;
  40.         var tform:TextFormat = new TextFormat();
  41.         tform.align = TextFormatAlign.CENTER;
  42.         tf.defaultTextFormat = tform;
  43.         tf.text = defaultText;
  44.         addChild(tf);
  45.         tf.x = stage.stageWidth/2 - tf.textWidth/2;
  46.         tf.y = 100;
  47.             
  48.         sbtn = new Button("[spaceキー] ゲームスタート"150);
  49.         //sbtn.width = 150;
  50.         sbtn.x = stage.stageWidth/2 - sbtn.width/2;
  51.         sbtn.y = 200;
  52.         sbtn.addEventListener(MouseEvent.CLICK, onClick);
  53.         addChild(sbtn);
  54.             
  55.         pbtn = new Button("twitterにポスト"100);
  56.         pbtn.x = stage.stageWidth/2 - pbtn.width/2;
  57.         pbtn.y = 250;
  58.         pbtn.visible = false;
  59.         pbtn.addEventListener(MouseEvent.CLICK, post);
  60.         addChild(pbtn);
  61.             
  62.         yes = new Button("→落ち着く"100);
  63.         yes.x = stage.stageWidth/2 + 10;
  64.         yes.y = 200;
  65.         yes.addEventListener(MouseEvent.CLICK, onYes);
  66.         addChild(yes);
  67.             
  68.         no = new Button("落ち着かない←"100);
  69.         no.x = stage.stageWidth/2 - no.width - 10;
  70.         no.y = 200;
  71.         no.addEventListener(MouseEvent.CLICK, onNo);
  72.         addChild(no);
  73.             
  74.         yes.visible = false;
  75.         no.visible = false;
  76.             
  77.         stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
  78.                 }
  79.         private function onClick(evt:MouseEvent):void
  80.         {
  81.             startGame();
  82.         }
  83.             
  84.         private function startGame():void
  85.         {
  86.             sbtn.visible = false;
  87.             pbtn.visible = false;
  88.             yes.visible = true;
  89.             no.visible = true;
  90.             
  91.             lastNum = 0;
  92.             
  93.             tf.text = String(i);
  94.         }
  95.             
  96.         private function onYes(evt:Event):void
  97.         {
  98.             check(true);
  99.         }
  100.             
  101.         private function onNo(evt:Event):void
  102.         {
  103.             check(false);
  104.         }
  105.             
  106.         private function onKeyDown(evt:KeyboardEvent):void
  107.         {
  108.             switch (evt.keyCode)
  109.             {
  110.                 case 32 :
  111.                     if (sbtn.visible)
  112.                     {
  113.                         startGame();
  114.                     }
  115.                     break;
  116.                 case 39 :
  117.                     if (yes.visible)
  118.                     {
  119.                         check(true);
  120.                     }
  121.                     break;
  122.                 case 37 :
  123.                     if (no.visible)
  124.                     {
  125.                         check(false);
  126.                     }
  127.                     break;
  128.                 default :
  129.                     break;
  130.             }
  131.         }
  132.             
  133.         private function check(b:Boolean):void
  134.         {
  135.             if (i == 0 || i == 1)
  136.             {
  137.                 if (b)
  138.                 {
  139.                     endGame();
  140.                     return;
  141.                 }
  142.             }
  143.             else
  144.             {
  145.                 if (a[i] && b)
  146.                 {
  147.                     endGame();
  148.                     return;
  149.                 }
  150.                 else if (!a[i] && !b)
  151.                 {
  152.                     endGame();
  153.                     return;
  154.                 }
  155.             }
  156.             
  157.             if(!a[i]) lastNum = i;
  158.             i++;
  159.             tf.text = String(i);
  160.         }
  161.             
  162.         private function endGame():void
  163.         {
  164.             sbtn.visible = true;
  165.             pbtn.visible = true;
  166.             yes.visible = false;
  167.             no.visible = false;
  168.             
  169.             if(lastNum == 0 || lastNum == 1) tf.text = "メメタァ\n\n最後に数えた素数:なし";
  170.             else tf.text = "メメタァ\n\n最後に数えた素数:"+lastNum;
  171.             
  172.             i = startNum;
  173.         }
  174.             
  175.         private function post(evt:MouseEvent):void
  176.         {
  177.             var st:String;
  178.             if(lastNum== -1)
  179.             {
  180.                 st = "http://twitter.com/home?status="+escapeMultiByte("素数を数えられませんでした。") + thisURL;
  181.             }
  182.             else
  183.             {
  184.                 st = "http://twitter.com/home?status=" + lastNum + escapeMultiByte("まで素数を数えて落ち着きました。") + thisURL;
  185.             }
  186.             navigateToURL(new URLRequest(st));
  187.         }            
  188.     }
  189. }
  190. import flash.display.*;
  191. import flash.text.*;
  192. class Button extends SimpleButton
  193. {
  194.     public function Button(label:String, width:int = 0):void
  195.     {
  196.         var up:Sprite = _buildImage(label, 0x0, width);
  197.         var over:Sprite = _buildImage(label, 0x333333, width);
  198.         var down:Sprite = _buildImage(label, 0x333333, width);
  199.         down.y = 1;
  200.         super(up, over, down, up);
  201.     }
  202.     private static function _buildImage(label:String, color:int, width:int = 0):Sprite
  203.     {
  204.         var text:TextField = new TextField();
  205.         text.defaultTextFormat = new TextFormat('Verdana'10, 0xffffff, truenullnullnullnull, TextFormatAlign.CENTER);
  206.         text.autoSize = TextFieldAutoSize.LEFT;
  207.         text.selectable = false;
  208.         text.text = label;
  209.         text.x = (width - text.width) >> 1;
  210.         text.y = 5;
  211.         var base:Shape = new Shape();
  212.         var g:Graphics = base.graphics;
  213.         g.beginFill(color);
  214.         g.drawRect(00, width, text.height + 10);
  215.         g.endFill();
  216.         var sp:Sprite = new Sprite();
  217.         sp.addChild(base);
  218.         sp.addChild(text);
  219.         return sp;
  220.     }
  221. }
noswf
  1. // forked from undo's 落ち着け・・・素数を数えて落ち着くんだ・・・
  2. // forked from nitoyon's Enumerate Prime Numbers (227letters) (Sieve of Eratosthenes)
  3. // inspired by http://twitter.com/javascripter/statuses/8367943818
  4. package{
  5.     import flash.text.*;
  6.     import flash.display.*;
  7.     import flash.events.*;
  8.     import flash.net.*;
  9.     import flash.utils.escapeMultiByte;
  10.     
  11.     public class C extends Sprite
  12.     {
  13.         private var defaultText:String = "\n落ち着け・・・素数を数えて落ち着くんだ・・・\n\n素数だと思ったら「落ち着く」ボタン またはキーボードの→キー\n素数じゃないと思ったら「落ち着かない」ボタン またはキーボードの←キー\n\nを押すんだ・・・";
  14.         private var a:Array = [];
  15.         private var i:int = 0;
  16.         private var lastNum:int = 0;
  17.         private var thisURL:String = http://bit.ly/blMbVu %23wonderfl";
  18.         
  19.         private var tf:TextField;
  20.         private var sbtn:Button;
  21.         private var pbtn:Button;
  22.         private var yes:Button;
  23.         private var no:Button;
  24.         
  25.         private var startTime:uint;
  26.         private var elapsed:uint;
  27.         private var timeDisp:TextField;
  28.         
  29.         public function C()
  30.         {
  31.             for (var c:int = 1, d:int; c++<1E3; )
  32.             {
  33.                 if (!a[c])
  34.                 {
  35.                     for (d=c; d<1E3; )
  36.                     {
  37.                         a[d+=c]=1;
  38.                     }
  39.                 }
  40.             }
  41.             timeDisp = new TextField();
  42.             addChild(timeDisp);
  43.             
  44.             
  45.         tf = new TextField();
  46.         tf.autoSize = TextFieldAutoSize.CENTER;
  47.         var tform:TextFormat = new TextFormat();
  48.         tform.align = TextFormatAlign.CENTER;
  49.         tf.defaultTextFormat = tform;
  50.         tf.text = defaultText;
  51.         addChild(tf);
  52.         tf.x = stage.stageWidth/2 - tf.textWidth/2;
  53.         tf.y = 100;
  54.             
  55.         sbtn = new Button("[spaceキー] ゲームスタート"150);
  56.         //sbtn.width = 150;
  57.         sbtn.x = stage.stageWidth/2 - sbtn.width/2;
  58.         sbtn.y = 200;
  59.         sbtn.addEventListener(MouseEvent.CLICK, onClick);
  60.         addChild(sbtn);
  61.             
  62.         pbtn = new Button("twitterにポスト"100);
  63.         pbtn.x = stage.stageWidth/2 - pbtn.width/2;
  64.         pbtn.y = 250;
  65.         pbtn.visible = false;
  66.         pbtn.addEventListener(MouseEvent.CLICK, post);
  67.         addChild(pbtn);
  68.             
  69.         yes = new Button("→落ち着く"100);
  70.         yes.x = stage.stageWidth/2 + 10;
  71.         yes.y = 200;
  72.         yes.addEventListener(MouseEvent.CLICK, onYes);
  73.         addChild(yes);
  74.             
  75.         no = new Button("落ち着かない←"100);
  76.         no.x = stage.stageWidth/2 - no.width - 10;
  77.         no.y = 200;
  78.         no.addEventListener(MouseEvent.CLICK, onNo);
  79.         addChild(no);
  80.             
  81.         yes.visible = false;
  82.         no.visible = false;
  83.             
  84.         stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
  85.         
  86.                 }
  87.         
  88.         private function onFrame(e:Event):void {
  89.             var tmp:uint = (new Date()).time;
  90.             elapsed = tmp - startTime;
  91.         
  92.             var ms:uint = elapsed;
  93.         
  94.             var div:uint = 1000 * 60 * 60;
  95.             var hour:uint = ms / div;
  96.             ms -= hour * div;
  97.             div /= 60;
  98.             var min:uint = ms / div;
  99.             ms -= min * div;
  100.             div /= 60;
  101.             var sec:uint = ms / div;
  102.             ms -= sec * div;
  103.         
  104.             var tx:String = hour.toString() + ":"
  105.             if (min < 10) tx += "0";
  106.             tx += min.toString() + "'";
  107.             if (sec < 10) tx += "0";
  108.             tx += sec.toString() + "'";
  109.             if (ms < 100) tx += "0";
  110.             tx += uint(ms / 10).toString();
  111.         
  112.             timeDisp.text = tx;
  113.         }
  114.                 
  115.                 
  116.         private function onClick(evt:MouseEvent):void
  117.         {
  118.             startGame();
  119.             
  120.             startTime = (new Date()).time;
  121.             stage.addEventListener(Event.ENTER_FRAME, onFrame);
  122.         }
  123.             
  124.         private function startGame():void
  125.         {
  126.             sbtn.visible = false;
  127.             pbtn.visible = false;
  128.             yes.visible = true;
  129.             no.visible = true;
  130.             
  131.             lastNum = 0;
  132.             
  133.             tf.text = String(i);
  134.         }
  135.             
  136.         private function onYes(evt:Event):void
  137.         {
  138.             check(true);
  139.         }
  140.             
  141.         private function onNo(evt:Event):void
  142.         {
  143.             check(false);
  144.         }
  145.             
  146.         private function onKeyDown(evt:KeyboardEvent):void
  147.         {
  148.             switch (evt.keyCode)
  149.             {
  150.                 case 32 :
  151.                     if (sbtn.visible)
  152.                     {
  153.                         startGame();
  154.                     }
  155.                     break;
  156.                 case 39 :
  157.                     if (yes.visible)
  158.                     {
  159.                         check(true);
  160.                     }
  161.                     break;
  162.                 case 37 :
  163.                     if (no.visible)
  164.                     {
  165.                         check(false);
  166.                     }
  167.                     break;
  168.                 default :
  169.                     break;
  170.             }
  171.         }
  172.             
  173.         private function check(b:Boolean):void
  174.         {
  175.             if (i == 0 || i == 1)
  176.             {
  177.                 if (b)
  178.                 {
  179.                     endGame();
  180.                     return;
  181.                 }
  182.             }
  183.             else
  184.             {
  185.                 if (a[i] && b)
  186.                 {
  187.                     endGame();
  188.                     return;
  189.                 }
  190.                 else if (!a[i] && !b)
  191.                 {
  192.                     endGame();
  193.                     return;
  194.                 }
  195.             }
  196.             
  197.             if(!a[i]) lastNum = i;
  198.             i++;
  199.             tf.text = String(i);
  200.         }
  201.             
  202.         private function endGame():void
  203.         {
  204.             sbtn.visible = true;
  205.             pbtn.visible = true;
  206.             yes.visible = false;
  207.             no.visible = false;
  208.             stage.removeEventListener(Event.ENTER_FRAME, onFrame);
  209.             
  210.             if(lastNum == 0 || lastNum == 1) tf.text = "メメタァ\n\n最後に数えた素数:なし";
  211.             else tf.text = "メメタァ\n\n最後に数えた素数:"+lastNum;
  212.             
  213.             i = 0;
  214.         }
  215.             
  216.         private function post(evt:MouseEvent):void
  217.         {
  218.             var st:String;
  219.             if(lastNum== -1)
  220.             {
  221.                 st = "http://twitter.com/home?status="+escapeMultiByte("素数を数えられませんでした。") + thisURL;
  222.             }
  223.             else
  224.             {
  225.                 st = "http://twitter.com/home?status=" + lastNum + escapeMultiByte("まで素数を数えて落ち着きました。 time:") + timeDisp.text + thisURL;
  226.             }
  227.             navigateToURL(new URLRequest(st));
  228.         }
  229.     }
  230. }
  231. import flash.display.*;
  232. import flash.text.*;
  233. class Button extends SimpleButton
  234. {
  235.     public function Button(label:String, width:int = 0):void
  236.     {
  237.         var up:Sprite = _buildImage(label, 0x0, width);
  238.         var over:Sprite = _buildImage(label, 0x333333, width);
  239.         var down:Sprite = _buildImage(label, 0x333333, width);
  240.         down.y = 1;
  241.         super(up, over, down, up);
  242.     }
  243.     private static function _buildImage(label:String, color:int, width:int = 0):Sprite
  244.     {
  245.         var text:TextField = new TextField();
  246.         text.defaultTextFormat = new TextFormat('Verdana'10, 0xffffff, truenullnullnullnull, TextFormatAlign.CENTER);
  247.         text.autoSize = TextFieldAutoSize.LEFT;
  248.         text.selectable = false;
  249.         text.text = label;
  250.         text.x = (width - text.width) >> 1;
  251.         text.y = 5;
  252.         var base:Shape = new Shape();
  253.         var g:Graphics = base.graphics;
  254.         g.beginFill(color);
  255.         g.drawRect(00, width, text.height + 10);
  256.         g.endFill();
  257.         var sp:Sprite = new Sprite();
  258.         sp.addChild(base);
  259.         sp.addChild(text);
  260.         return sp;
  261.     }
  262. }
noswf
Get Adobe Flash Player