In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

光った順番当てゲーム

ボタン点灯を1つだけにすると難しすぎるようなので、
1セット(1問)は設問時に全部点灯した状態になるように
修正してみた。 (7/22 20:30)
Get Adobe Flash player
by mousepancyo 22 Jul 2010
/**
 * Copyright mousepancyo ( http://wonderfl.net/user/mousepancyo )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jbdM
 */

/*
ボタン点灯を1つだけにすると難しすぎるようなので、
1セット(1問)は設問時に全部点灯した状態になるように
修正してみた。 (7/22 20:30)
*/
package  {
    import flash.display.Sprite;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.events.MouseEvent;
    
    [SWF(width=465, height=465, backgroundColor=0,frameRate=30)]
    
    public class Main extends Sprite{
        private var _questList:Vector.<int>
        private var _questLengthList:Vector.<int>
        private var _btnList:Vector.<Circle>
        private var _targetBtnList:Vector.<Circle>
        private var _circleSize:int = 40;
        private var _initPos:int = 140;
        private var _countX:int;
        private var _countY:int;
        private var _timer:Timer;
        private var _txt:TextField = new TextField()
        private var _fmt:TextFormat = new TextFormat("_typewriter", 14, 0xFFFFFF, true, false, false, null, null, "center")
        
        private var _ansCount:int
        private var _questLevel:int = 0
        private var _ansFlg:Boolean
        private var _msg:String

        public function Main() {
            init()
            stage.addEventListener(MouseEvent.CLICK, mouseClick)
        }
        
        private function init():void{
            var base:Sprite = new Base(0x303030, stage.stageWidth, stage.stageHeight)
            addChild(base)
            _questList = new Vector.<int>();
            _questLengthList = new Vector.<int>();
            _btnList = new Vector.<Circle>();
            //
            for(var i:int=0; i<16; i++){
                _questList.push(i)
            }
            for(i=4; i<17; i++){
                _questLengthList.push(i)
            }
            for(i=0; i<_questList.length;i++){
                var circle:Circle = new Circle(_circleSize, 0x00FF00)
                addChild(circle)
                if(_countX<=3){
                    circle.x = _initPos+(_circleSize+20)*_countX
                    circle.y = _initPos*1.5+(_circleSize+20)*_countY
                }else{
                    _countX=0
                    _countY++
                    circle.x = _initPos+(_circleSize+20)*_countX
                    circle.y =_initPos*1.5+(_circleSize+20)*_countY
                }
                _btnList.push(circle)
                _countX++
            }
            //
            _msg = "ゲームレベル:"+(_questLevel+1)+"\nGame Level : "+(_questLevel+1)
            //
            addChild(_txt)
            _txt.defaultTextFormat = _fmt
            _txt.width = stage.stageWidth
            _txt.height = 300
            _txt.mouseEnabled = false
            _txt.selectable = false
            _txt.y = 25
            _txt.text = "\n"+_msg + "\n\n下のボタンを光った順番にクリックして下さい。\nPlease click the button below to order flashed.\n\n画面クリックでゲームスタートです。\nGame Start screen, click it!"
            //
        }
        
        private function vecShuffle(vec:Vector.<int>):Vector.<int>{
            var l:int = vec.length;
            while(l--) {
                var j:int = Math.floor(Math.random()*(l+1));
                var suffle:int = vec[l];
                vec[l] = vec[j];
                vec[j] = suffle;
            }
            return vec;
        }
        
        private function questStart(delay:int, repeat:int):void{
            vecShuffle(_questList)
            var timerCount:int
            _targetBtnList = new Vector.<Circle>();
            _ansCount = 0
            _txt.text = "\n"+_msg+"\n\n下のボタンを光った順番にクリックして下さい。\nPlease click the button below to order flashed."
            //
            _timer = new Timer(delay, repeat*2)
            _timer.addEventListener(TimerEvent.TIMER, questTimer)
            _timer.addEventListener(TimerEvent.TIMER_COMPLETE, questTimerComplete)
            _timer.start()
            
            function questTimer(e:TimerEvent):void{
                if((timerCount % 2) != 1 ) {
                    _btnList[_questList[timerCount/2]].knockout = false
                    _targetBtnList.push(_btnList[_questList[timerCount/2]])
                }
                timerCount++
            }
            function questTimerComplete(e:TimerEvent):void{
                for(var i:int=0; i<_btnList.length; i++){
                    _btnList[i].knockout = true
                    _btnList[i].buttonMode = true
                    _btnList[i].addEventListener(MouseEvent.CLICK, mouseClick)
                }
                _timer.removeEventListener(TimerEvent.TIMER, questTimer)
                _timer.removeEventListener(TimerEvent.TIMER_COMPLETE, questTimerComplete)
                _timer = null
            }
        }
        
        private function nextTimerStart():void{
            for(var i:int=0; i<_btnList.length; i++){
                _btnList[i].buttonMode = false
                _btnList[i].removeEventListener(MouseEvent.CLICK, mouseClick)
            }
            //
            _timer = new Timer(1000, 3)
            _timer.addEventListener(TimerEvent.TIMER, nextTimer)
            _timer.addEventListener(TimerEvent.TIMER_COMPLETE, nextTimerComplete)
            _timer.start()
            //
            var str:String
            if(!_ansFlg){
                str = "\n"+_msg+"\n\n不正解です。もう一度やり直して下さい。\nThis is incorrect. Please try again."
            }
            
            function nextTimer(e:TimerEvent):void{
                _timer.removeEventListener(TimerEvent.TIMER, nextTimer)
                if(_ansFlg){
                    _msg = "ゲームレベル:"+(_questLevel+1)+"\nGame Level : "+(_questLevel+1)
                    str = "\n"+_msg+"\n\n正解!レベルアップしました。次の問題です。\nCorrect! I level. The following is a problem."
                }
                _txt.text = str
            }
            
            function nextTimerComplete(e:TimerEvent):void{
                _timer.removeEventListener(TimerEvent.TIMER_COMPLETE, nextTimerComplete)
                _timer = null
                //
                for(i=0; i<_btnList.length; i++){
                    _btnList[i].alpha = 1
                    _btnList[i].knockout = true
                }
                if(_ansFlg){
                    _txt.appendText("\n\n画面クリックで次へ進みます。\nGo to the next, click it!")
                }else{
                    _txt.appendText("\n\n画面クリックで再挑戦です\nClick to retry.")
                }
                _ansFlg = false
                stage.addEventListener(MouseEvent.CLICK, mouseClick)
            }
        }
        
        private function mouseClick(e:MouseEvent):void{
            if(e.currentTarget == stage){
                questStart(200, _questLengthList[_questLevel])
                stage.removeEventListener(MouseEvent.CLICK, mouseClick)
            }else{
                jadge(e.target as Circle, _targetBtnList[_ansCount])
                e.target.removeEventListener(MouseEvent.CLICK, mouseClick)
            }
            //
        }
        
        private function jadge(target:Circle, ans:Circle):void{
            if(_questLengthList[_questLevel] > _ansCount){
                if(target == ans){
                    _ansCount++
                    target.knockout = false
                    if(_questLengthList[_questLevel] == _ansCount){
                        if(_questLevel<_questLengthList.length-1){
                          _ansFlg = true
                          _questLevel++
                          nextTimerStart()
                        }else{
                            _txt.text = "全レベルクリアおめでとうございます!!\nCongratulations to clear all levels!!\n\nあなたの強力な集中力と記憶力、\nそして根気に感激です!\nStrong memory and your concentration,\n patience and is thrilled !"
                        }
                    }
                }else{
                    _ansFlg = false
                    target.alpha = 0.3
                    nextTimerStart()
                }
            }
        }        
    }    
}


//
import flash.display.Sprite;
import flash.filters.GlowFilter;
import flash.filters.BevelFilter;

class Circle extends Sprite{
    private var _glow:GlowFilter;
    private var _bevel:BevelFilter;
    private var _knockout:Boolean = true
    
    public function Circle(size:int, color:int=0xFFFFFF){
        var colors:Array = [color, 0]
        var alphas:Array = [1, 0.5]
        var ratios:Array = [0, 75]
        graphics.lineStyle(2, 0x606060, 1)
        graphics.beginGradientFill("radial", colors, alphas, ratios)
        graphics.drawCircle(0,0,size/2);
        graphics.endFill();
        //
        _glow = new GlowFilter(0xFFFFFF,0.5,12,12,4,2,false,false)
        _bevel = new BevelFilter(20,90,0xFFFFFF,1,0x000000,0.3,32,32,1.4,1,"inner",_knockout)
        this.filters = [_bevel, _glow]
    }
    
    public function set knockout(flg:Boolean):void{
        _bevel.knockout = flg
        this.filters = [_bevel, _glow]
    }
}

import flash.display.Sprite
class Base extends Sprite{
    public function Base(color:int,w:int,h:int):void{
        graphics.beginFill(color, 1)
        graphics.drawRect(0,0,w,h)
        graphics.endFill()
    }
}