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

SlidePuzzle2

Get Adobe Flash player
by hacker_cobulht0 18 Jun 2012
/**
 * Copyright hacker_cobulht0 ( http://wonderfl.net/user/hacker_cobulht0 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qhpd
 */

package {     
    import flash.display.Sprite;
    import flash.events.*;
    import flash.text.*;
    
    [SWF(width = "465", height = "465", backgroundColor = 0xffffff, frameRate = "60")]
    
    public class SlidePuzzle2 extends Sprite{
        //chick
        private var _chk:mainChick=new mainChick();
        //sozai-other
        private var tf:TextField = new TextField();
        private var goalP:goalPoint = new goalPoint();
        
        //基本視点とサイズ
        private static const startX:uint=70;
        private static const startY:uint=70;
        private static const pSize:uint=80;        
        private static const overX:uint=startX+4*pSize;
        private static const overY:uint=startY+4*pSize;
        
        //パネル
        private var myList:Array=new Array();
        private var shList:Array=new Array();        
        
        //速さ
        private var _speed:Number = 5;        
        //進む方向
        private var _direction:String="mg";
        
        //ひよこを動かす関連
        private var nowPanel;
        
        public function SlidePuzzle2(){
            if (stage) init();else addEventListener(Event.ADDED_TO_STAGE,init );
        }
        public function init(ev:Event = null){
            removeEventListener( Event.ADDED_TO_STAGE, init ) ;
            var bg:back_ground=new back_ground();
            addChildAt(bg,0);
            
            //最初に パネルについて
            for (var q:int=0; q < 16; q++) {
                var mc;
                
                if(q==0||q==1){mc=new Panel1();}
                else if(q==2||q==3){mc=new Panel2();}
                else if(q==4||q==5||q==6){mc=new Panel3();}
                else if(q==7||q==8){mc=new Panel4();}
                else if(q==9||q==10){mc=new Panel5();}
                else if(q==11||q==12){mc=new Panel6();}
                else if(q==13||q==14){mc=new Panel7();}
                else if(q==15){mc=new nonePanel();}
                
                mc.name="_p"+q
                mc.x=startX+(q%4)*pSize;
                mc.y=startY+Math.floor(q / 4)*pSize;
                addChild(mc);
                mc.addEventListener(MouseEvent.MOUSE_UP,pClick);
                
                myList.push(mc);
            }            
            
            //シャッフル
            var rdList:Array=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
            var nums:uint=rdList.length;
            while (nums--) {
                var rd =Math.floor(Math.random()*(nums+1)); 
                shList.push(rdList[rd]);        
                rdList.splice(rd,1);
            };            
            //シャッフル通りに並べなおす
            for (q=0; q < 16; q++) {
                if(q!=0){
                mc=myList[shList[q-1]];
                mc.x=startX+(q%4)*pSize;
                mc.y=startY+Math.floor(q / 4)*pSize;
                }
            }
            
            //Goal地点
                                    //テキストフォーマット作成                
                                var fmt:TextFormat = new TextFormat();
                                fmt.size  = 18;
                                fmt.align = TextFormatAlign.CENTER;
                                fmt.color = 0xFFFFFF;
                                fmt.font="Impact";
                                    //テキストフィールド作成
                                
                                tf.defaultTextFormat = fmt;
                                tf.text = "G\no\na\nl";
                                tf.selectable = false;
                                
                                tf.height=200;
                                tf.x=startX+3*pSize+50;
                                tf.y=startY+3*pSize;
                                addChild(tf);
                                
                                goalP.x=overX;
                                goalP.y=overY-40;
                                addChild(goalP);
            
            
            //ひよこ配置
            _chk.x=startX;
            _chk.y=startY+(pSize/2);
            addChild(_chk);                            
                                
            
            //初期設定
            nowPanel=myList[0];
            addEventListener(Event.ENTER_FRAME,f_ef);
        }
        
        
        
        
        
        
        
        
        
        
        private function f_ef(ev){
            
            //画像の向きについて
            if(_direction=="mg"){_chk.scaleX=-1;}else if(_direction=="hd"){_chk.scaleX=1;};            
            
            
            var _obj:Object=nowPanel.getObj(_direction,_chk,_speed);
                _direction=_obj.drc;
                if(_obj.stts=="next"){//trace((myList[15].x-startX)/80,(myList[15].y-startY)/80);
                    var tmp=nowPanel;
                    nowPanel=nextSearch(nowPanel,_direction);
                    tmp.obj={drc:"",stts:"moving"};
                    tmp.mcnt=0;
                    if(tmp._type>=4){tmp.mcnt2=0;}
                    
                }else if(_obj.stts=="batu"){
                    _GameOver();
                };
            
            //Clear判定
            if(_chk.pic.body.hitTestObject(goalP)&&_direction=="mg"){_GameClear();}
            
        };
        
        
        
        
        private function nextSearch(argP,argD):Object{            
            
            var nsP=myList[15];//nonePanelの情報
            var nsX;
            var nsY;
            
            switch(argD){
             case "ue":
                    nsX=argP.x;
                    nsY=argP.y-pSize;
               break;
             case "st":
                  nsX=argP.x;
                    nsY=argP.y+pSize;
               break;
             case "hd":
                   nsX=argP.x-pSize;
                    nsY=argP.y;
               break;
             case "mg":
                   nsX=argP.x+pSize;
                    nsY=argP.y;
               break;
            default:
               break;
            }
            
            for(var q:int=0; q < myList.length; q++){
                var mc=myList[q];
                if(mc.x==nsX&&mc.y==nsY){
                    nsP=mc;
                }
            }
            
            return nsP;
        }
        
        
        
        
        
        //----------------------------------------------------------------------------------------------------
        //パネルを押したとき
        private function pClick(ev){
            var mc=ev.target.parent;
            var nmc=myList[15];            
            if(mc.x==nmc.x&&mc.y-pSize==nmc.y){nmc.y+=pSize;mc.y-=pSize;}//ue
            else if(mc.x==nmc.x&&mc.y+pSize==nmc.y){nmc.y-=pSize;mc.y+=pSize;}//st
            else if(mc.x==nmc.x-pSize&&mc.y==nmc.y){nmc.x-=pSize;mc.x+=pSize;}//hd
            else if(mc.x==nmc.x+pSize&&mc.y==nmc.y){nmc.x+=pSize;mc.x-=pSize;}//mg
        }
        //----------------------------------------------------------------------------------------------------
        //GameOver
        private function _GameOver(){
            removeEventListener(Event.ENTER_FRAME,f_ef);
            
            var batu:Sprite=new Sprite();
            batu.graphics.lineStyle(5,0xCD4A4A);
            batu.graphics.moveTo(_chk.x-10,_chk.y-10);
            batu.graphics.lineTo(_chk.x+10,_chk.y+10);
            batu.graphics.moveTo(_chk.x+10,_chk.y-10);
            batu.graphics.lineTo(_chk.x-10,_chk.y+10);
            batu.graphics.endFill();
            addChild(batu);
            _chk.visible=false;
            
        }
        //GAmeClear!!
        private function _GameClear(){
            removeEventListener(Event.ENTER_FRAME,f_ef);
            tf.y-=10;
            tf.text = "C\nl\ne\na\nr\n!";
        }
    }
}





import flash.display.*;
import flash.events.*;

//BackGround
class back_ground extends Sprite{    
    private var arr:Array=[0x7DCCB6,0x9ADDCC];
public function back_ground(){
    for(var j:int=0; j < 24; j++){
        this.graphics.beginFill(arr[j%2],1);
        this.graphics.drawRect(0,j*20,465,20);
        this.graphics.endFill();        
    }
}
}


//Chick
class mainChick extends Sprite{
    public var pic:drawChick=new drawChick();
public function mainChick(){
    addChild(pic);
    pic.scaleX=pic.scaleY=1.2;
    pic.x=-10;
    pic.y=-5;
}
}
class drawChick extends Sprite{
    private var head:Sprite=new Sprite();
    public var body:Sprite=new Sprite();
    private var scarf:Sprite=new Sprite();
    public var foot:Sprite=new Sprite();
    
    private var arr1:Array=[0xFD7C6E,0xF28E98,0xFF9985];
public function drawChick(){
        head.graphics.beginFill(0xFCE883);//head
        head.graphics.drawCircle(0,0,10);
        head.graphics.endFill();
        var head_1:Sprite = new Sprite();
        head_1.graphics.beginFill(0x1DACD6);//eye
        head_1.graphics.drawCircle(-1,-1,2);
        head_1.graphics.endFill();
        head_1.graphics.beginFill(0xFAA76C);//mouse
        head_1.graphics.drawEllipse(-15,-2,7,4);
        head_1.graphics.endFill();
        head.addChild(head_1);
        addChild(head);
        
        body.graphics.beginFill(0xFCE883);//body
        body.graphics.drawEllipse(2,2,30,20);
        body.graphics.endFill();
        var body_1:Sprite = new Sprite();
        body_1.graphics.beginFill(0xFCE883);//teil
        body_1.graphics.moveTo(20,5);
        body_1.graphics.lineTo(35,-1);
        body_1.graphics.lineTo(32,13);
        body_1.graphics.endFill();
        body.addChild(body_1);
        addChild(body);    
        
        /*foot.graphics.lineStyle(2,0xF6721E);//foot
        foot.graphics.moveTo(18,23);
        foot.graphics.lineTo(18,25);
        foot.graphics.moveTo(18,25);
        foot.graphics.lineTo(15,30);
        foot.graphics.moveTo(18,25);
        foot.graphics.lineTo(12,28);
        foot.graphics.moveTo(18,25);
        foot.graphics.lineTo(10,25);        
        foot.graphics.endFill();
        
        addChild(foot);*/
        
        var rd:uint=Math.floor (Math.random () * arr1.length) ;
        var skf_cal=arr1[rd]
        scarf.graphics.beginFill(skf_cal);
        scarf.graphics.drawEllipse(-5,8,14,3);
        scarf.graphics.endFill();    
        scarf.rotation=-40;        
        var scarf_1:Sprite = new Sprite();    
        scarf_1.graphics.beginFill(skf_cal);
        scarf_1.graphics.drawEllipse(0,0,15,5);
        scarf_1.graphics.endFill();    
        scarf_1.rotation=-60;
        scarf_1.x=5;scarf_1.y=8;        
        var scarf_2:Sprite = new Sprite();    
        scarf_2.graphics.beginFill(skf_cal);
        scarf_2.graphics.drawEllipse(0,0,15,5);
        scarf_2.graphics.endFill();    
        scarf_2.rotation=-20;
        scarf_2.x=5;scarf_2.y=8;
        scarf.addChild(scarf_2);
        scarf.addChild(scarf_1);
        addChild(scarf);
    }
}











/*
□□□
■■■
□□□
*/
class Panel1 extends Sprite{
    public var _type:uint=1;
    
        public var obj:Object={drc:"",stts:"moving"};
        public var mcnt:uint=0;
    
    public function Panel1(){
        var pic:_Panel=new _Panel();
        addChild(pic);
        
        pic.graphics.lineStyle(10,0xB4BE1F,1,false,"normal","none");
        pic.graphics.moveTo(0,40);
        pic.graphics.lineTo(80,40);
        pic.graphics.endFill();
    }   
    //----------------------------------------------------------------------------------------------------        
    public function getObj(argD,argC,argS):Object{
        if(argD=="mg"){
            obj.drc=argD;
            if(mcnt==80*argS){obj.stts="next";}else{mcnt++;}
            argC.x=this.x+(mcnt/argS);
            argC.y=this.y+40;
                             
        }else if(argD=="hd"){
            obj.drc=argD;
            if(mcnt==80*argS){obj.stts="next";}else{mcnt++;}
            argC.x=(this.x+80)-(mcnt/argS);
            argC.y=this.y+40;
            
        }else if(argD=="ue"||argD=="st"){
            obj.drc=argD;
            obj.stts="batu";
        }
        return obj;
    }
}





/*
□■□
□■□
□■□
*/
class Panel2 extends Sprite{
    public var _type:uint=2;
    
        public var obj:Object={drc:"",stts:"moving"};
        public var mcnt:uint=0;
    
    public function Panel2( ){
        var pic:_Panel=new _Panel();
        addChild(pic);
        
        pic.graphics.lineStyle(10,0xB4BE1F,1,false,"normal","none");
        pic.graphics.moveTo(40,0);
        pic.graphics.lineTo(40,80);
        pic.graphics.endFill();
    }        
    //----------------------------------------------------------------------------------------------------
    public function getObj(argD,argC,argS):Object{
        if(argD=="st"){
            obj.drc=argD;
            if(mcnt==80*argS){obj.stts="next";}else{mcnt++;}
            argC.y=this.y+(mcnt/argS);
            argC.x=this.x+40;
                             
        }else if(argD=="ue"){
            obj.drc=argD;
            if(mcnt==80*argS){obj.stts="next";}else{mcnt++;}
            argC.y=(this.y+80)-(mcnt/argS);
            argC.x=this.x+40;
            
        }else if(argD=="mg"||argD=="hd"){
            obj.drc=argD;
            obj.stts="batu";
        }
        return obj;
    }
}




/*
□■□
■■■
□■□
*/
class Panel3 extends Sprite{
    public var _type:uint=3;
    
        public var obj:Object={drc:"",stts:"moving"};
        public var mcnt:uint=0;
    
    public function Panel3( ){
        var pic:_Panel=new _Panel();
        addChild(pic);
        
        pic.graphics.lineStyle(10,0xB4BE1F,1,false,"normal","none");
        pic.graphics.moveTo(0,40);
        pic.graphics.lineTo(80,40);
        pic.graphics.moveTo(40,0);
        pic.graphics.lineTo(40,80);
        pic.graphics.endFill();
    }
    //----------------------------------------------------------------------------------------------------
    public function getObj(argD,argC,argS):Object{
        if(argD=="mg"){
            obj.drc=argD;
            if(mcnt==80*argS){obj.stts="next";}else{mcnt++;}
            argC.x=this.x+(mcnt/argS);
            argC.y=this.y+40;
                             
        }else if(argD=="hd"){
            obj.drc=argD;
            if(mcnt==80*argS){obj.stts="next";}else{mcnt++;}
            argC.x=(this.x+80)-(mcnt/argS);
            argC.y=this.y+40;
            
        }else if(argD=="st"){
            obj.drc=argD;
            if(mcnt==80*argS){obj.stts="next";}else{mcnt++;}
            argC.y=this.y+(mcnt/argS);
            argC.x=this.x+40;
                             
        }else if(argD=="ue"){
            obj.drc=argD;
            if(mcnt==80*argS){obj.stts="next";}else{mcnt++;}
            argC.y=(this.y+80)-(mcnt/argS);
            argC.x=this.x+40;
            
        }
        return obj;
    }
}










/*
□□□
□■■
□■□
*/
class Panel4 extends Sprite{
    public var _type:uint=4;
    
        public var obj:Object={drc:"",stts:"moving"};
        public var mcnt:uint=0;
        public var mcnt2:uint=0;
    
    public function Panel4( ){
        var pic:_Panel=new _Panel();

        addChild(pic);
        
        pic.graphics.lineStyle(10,0xB4BE1F,1,false,"normal","none");
        pic.graphics.moveTo(80,40);
        pic.graphics.lineTo(40,40);
        pic.graphics.lineTo(40,80);
        pic.graphics.endFill();
    }
    //----------------------------------------------------------------------------------------------------
    public function getObj(argD,argC,argS):Object{
        if((mcnt2==0&&argD=="mg")||(mcnt2==0&&argD=="st")){
            obj.drc=argD;
            obj.stts="batu";
        //mg
        }else if(argD=="hd"){
            mcnt2=1;
            
            obj.drc="hd";
            if(mcnt==40*argS){obj.drc="st";}else{mcnt++;}
            argC.x=(this.x+80)-(mcnt/argS);
            argC.y=this.y+40;
        }else if(mcnt2>0&&argD=="st"){
            obj.drc="st";
            if(mcnt2==40*argS){obj.stts="next";}else{mcnt2++;}
            argC.y=(this.y+40)+(mcnt2/argS);
            argC.x=this.x+40;
        //st
        }else if(argD=="ue"){
            mcnt2=1;
            
            obj.drc="ue";
            if(mcnt==40*argS){obj.drc="mg";}else{mcnt++;}
            argC.y=(this.y+80)-(mcnt/argS);
            argC.x=this.x+40;
        }else if(mcnt2>0&&argD=="mg"){
            obj.drc="mg";
            if(mcnt2==40*argS){obj.stts="next";}else{mcnt2++;}
            argC.x=(this.x+40)+(mcnt2/argS);
            argC.y=this.y+40;
        }
        
        return obj;
    }
}




/*
□■□
□■■
□□□
*/
class Panel5 extends Sprite{
    public var _type:uint=5;
    
        public var obj:Object={drc:"",stts:"moving"};
        public var mcnt:uint=0;        
        public var mcnt2:uint=0;
    
    public function Panel5( ){
        var pic:_Panel=new _Panel();
        addChild(pic);
        
        pic.graphics.lineStyle(10,0xB4BE1F,1,false,"normal","none");
        pic.graphics.moveTo(40,0);
        pic.graphics.lineTo(40,40);
        pic.graphics.lineTo(80,40);
        pic.graphics.endFill();
    }
    //----------------------------------------------------------------------------------------------------
    public function getObj(argD,argC,argS):Object{
        if((mcnt2==0&&argD=="mg")||(mcnt2==0&&argD=="ue")){
            obj.drc=argD;
            obj.stts="batu";
        //mg
        }else if(argD=="hd"){
            mcnt2=1;
            
            obj.drc="hd";
            if(mcnt==40*argS){obj.drc="ue";}else{mcnt++;}
            argC.x=(this.x+80)-(mcnt/argS);
            argC.y=this.y+40;
        }else if(mcnt2>0&&argD=="ue"){
            obj.drc="ue";
            if(mcnt2==40*argS){obj.stts="next";}else{mcnt2++;}
            argC.y=(this.y+40)-(mcnt2/argS);
            argC.x=this.x+40;
        //st
        }else if(argD=="st"){
            mcnt2=1;
            
            obj.drc="st";
            if(mcnt==40*argS){obj.drc="mg";}else{mcnt++;}
            argC.y=this.y+(mcnt/argS);
            argC.x=this.x+40;
        }else if(mcnt2>0&&argD=="mg"){
            obj.drc="mg";
            if(mcnt2==40*argS){obj.stts="next";}else{mcnt2++;}
            argC.x=(this.x+40)+(mcnt2/argS);
            argC.y=this.y+40;
        }    
        
        return obj;
    }
}




/*
□■□
■■□
□□□
*/
class Panel6 extends Sprite{
    public var _type:uint=6;
    
        public var obj:Object={drc:"",stts:"moving"};
        public var mcnt:uint=0;
        public var mcnt2:uint=0;
    
    public function Panel6( ){
        var pic:_Panel=new _Panel();
        addChild(pic);
        
        pic.graphics.lineStyle(10,0xB4BE1F,1,false,"normal","none");
        pic.graphics.moveTo(0,40);
        pic.graphics.lineTo(40,40);
        pic.graphics.lineTo(40,0);
        pic.graphics.endFill();
    }
    //----------------------------------------------------------------------------------------------------
    public function getObj(argD,argC,argS):Object{
        if((mcnt2==0&&argD=="hd")||(mcnt2==0&&argD=="ue")){
            obj.drc=argD;
            obj.stts="batu";
        //mg
        }else if(argD=="mg"){
            mcnt2=1;
            
            obj.drc="mg";
            if(mcnt==40*argS){obj.drc="ue";}else{mcnt++;}
            argC.x=this.x+(mcnt/argS);
            argC.y=this.y+40;
        }else if(mcnt2>0&&argD=="ue"){
            obj.drc="ue";
            if(mcnt2==40*argS){obj.stts="next";}else{mcnt2++;}
            argC.y=(this.y+40)-(mcnt2/argS);
            argC.x=this.x+40;
        //st
        }else if(argD=="st"){
            mcnt2=1;
            
            obj.drc="st";
            if(mcnt==40*argS){obj.drc="hd";}else{mcnt++;}
            argC.y=this.y+(mcnt/argS);
            argC.x=this.x+40;
        }else if(mcnt2>0&&argD=="hd"){
            obj.drc="hd";
            if(mcnt2==40*argS){obj.stts="next";}else{mcnt2++;}
            argC.x=(this.x+40)-(mcnt2/argS);
            argC.y=this.y+40;
        }    
        
        return obj;
    }
}




/*
□□□
■■□
□■□
*/
class Panel7 extends Sprite{
    public var _type:uint=7;
    
        public var obj:Object={drc:"",stts:"moving"};
        public var mcnt:uint=0;
        public var mcnt2:uint=0;
    
    public function Panel7( ){
        var pic:_Panel=new _Panel();
        addChild(pic);
        
        pic.graphics.lineStyle(10,0xB4BE1F,1,false,"normal","none");
        pic.graphics.moveTo(0,40);
        pic.graphics.lineTo(40,40);
        pic.graphics.lineTo(40,80);
        pic.graphics.endFill();
    }
    //----------------------------------------------------------------------------------------------------
    public function getObj(argD,argC,argS):Object{
        if((mcnt2==0&&argD=="hd")||(mcnt2==0&&argD=="st")){
            obj.drc=argD;
            obj.stts="batu";
        //mg
        }else if(argD=="mg"){
            mcnt2=1;
            
            obj.drc="mg";
            if(mcnt==40*argS){obj.drc="st";}else{mcnt++;}
            argC.x=this.x+(mcnt/argS);
            argC.y=this.y+40;
        }else if(mcnt2>0&&argD=="st"){
            obj.drc="st";
            if(mcnt2==40*argS){obj.stts="next";}else{mcnt2++;}
            argC.y=(this.y+40)+(mcnt2/argS);
            argC.x=this.x+40;
        //ue
        }else if(argD=="ue"){
            mcnt2=1;
            
            obj.drc="ue";
            if(mcnt==40*argS){obj.drc="hd";}else{mcnt++;}
            argC.y=(this.y+80)-(mcnt/argS);
            argC.x=this.x+40;
        }else if(mcnt2>0&&argD=="hd"){
            obj.drc="hd";
            if(mcnt2==40*argS){obj.stts="next";}else{mcnt2++;}
            argC.x=(this.x+40)-(mcnt2/argS);
            argC.y=this.y+40;
        }    
        return obj;
    }
}


//----------------------------------------------------------------------------------------------------
//myList[15]
class nonePanel extends Sprite{
    public var _type:uint=99;
    
        public var obj:Object={drc:"",stts:"moving"};
        public var mcnt:uint=0;
        
    public function nonePanel( ){
        this.graphics.beginFill(0x7DCCB6,0.2);
        this.graphics.drawRoundRect(0,0,80,80,25);
        this.graphics.endFill();
    }
    public function getObj(argD,argC,argS):Object{
        obj.drc=argD;
        obj.stts="batu";
        return obj;
    }
}
class _Panel extends Sprite{
    public function _Panel( ){
        this.graphics.beginFill(0xB4BE1F);
        this.graphics.drawRoundRect(0,0,80,80,25);
        this.graphics.endFill();
        this.graphics.beginFill(0xD8D41B);//e1e79f
        this.graphics.drawRoundRect(8,8,64,64,25);    
        this.graphics.endFill();
    }
}


//----------------------------------------------------------------------------------------------------
class goalPoint extends Sprite{
    public function goalPoint( ){
        this.graphics.beginFill(0x9ADDCC);
        this.graphics.drawCircle(0,0,10);
        this.graphics.endFill();
    }
}