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

SlidePuzzle

Get Adobe Flash player
by hacker_cobulht0 12 Oct 2010
//上下左右キーで操作
package {
    import flash.display.Sprite;
    import flash.display.DisplayObject;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;
    
    import org.libspark.betweenas3.BetweenAS3;
    import org.libspark.betweenas3.tweens.ITween;
    import org.libspark.betweenas3.easing.*;
    
    [SWF(width = "465", height = "465", backgroundColor = 0x7DCCB6, frameRate = "60")]
public class SlidePuzzle extends Sprite {
    private var my_array1:Array=[
        [11,11,11,11,11],
        [11,1,2,3,11],
        [11,4,5,6,11],
        [11,7,8,9,11],
        [11,11,11,11,11]
    ];
    private var nowY:uint=0;
    private var nowX:uint=0;
    private var blockList:Array=new Array();
    private var keyfla:Boolean=true;

public function SlidePuzzle() {
    var bg:back_ground=new back_ground();
    addChildAt(bg,0);
    bg.addEventListener(Event.ENTER_FRAME,function(e){                                        
        var _radian:Number = e.target.angel* Math.PI / 180;
        e.target.y = 5* Math.sin(_radian);
        e.target.angel+=1;
    });
    func_Shuffle();
}
private function func_Shuffle(){
    var _last:uint=99;
    var _lastY:uint=0;
    var _lastX:uint=0;
    for(var j=0; j<12; j++){
        var rd:uint=Math.floor(Math.random()*3)+1;
        var rd2:uint=Math.floor(Math.random()*2);
        my_array1[_lastY][_lastX]=11;
        if(j%2==0){
            //たてまぜ
            if(rd2==0){
                //うえからしたへ
                my_array1[4][rd]=my_array1[3][rd];
                my_array1[3][rd]=my_array1[2][rd];
                my_array1[2][rd]=my_array1[1][rd];
                my_array1[1][rd]=_last;
                _last=my_array1[4][rd];
                _lastY=4;
                _lastX=rd;    
            }else if(rd2==1){
                //したからうえへ
                my_array1[0][rd]=my_array1[1][rd];
                my_array1[1][rd]=my_array1[2][rd];
                my_array1[2][rd]=my_array1[3][rd];
                my_array1[3][rd]=_last;
                _last=my_array1[0][rd];
                _lastY=0;
                _lastX=rd;    
            }
        }else if(j%2==1){
            //よこまぜ
            if(rd2==0){
                //ひだりからみぎへ
                my_array1[rd][4]=my_array1[rd][3];
                my_array1[rd][3]=my_array1[rd][2];
                my_array1[rd][2]=my_array1[rd][1];
                my_array1[rd][1]=_last;
                _last=my_array1[rd][4];
                _lastY=rd;
                _lastX=4;    
            }else if(rd2==1){
                //みぎからひだりへ
                my_array1[rd][0]=my_array1[rd][1];
                my_array1[rd][1]=my_array1[rd][2];
                my_array1[rd][2]=my_array1[rd][3];
                my_array1[rd][3]=_last;
                _last=my_array1[rd][0];
                _lastY=rd;
                _lastX=0;                
            }
        }//
    }
    nowY=_lastY;
    nowX=_lastX;
    funcMakeBlock();
    stage.addEventListener(KeyboardEvent.KEY_DOWN, funcKey);
}
private function funcMakeBlock(){
    for(var j=0; j<5; j++){
        for(var q=0; q<5; q++){
            var num:uint=my_array1[j][q];
            if(num!=11){
                var _mc=new Blocks(num);
                _mc.y=_mc.yp=j*93;
                _mc.x=q*93;
                _mc.name="item"+num;
                _mc.posy=j;
                _mc.posx=q;

                addChild(_mc);
                blockList[num]=_mc;
                
            }
        }
    }
}
private function funcKey(event:KeyboardEvent){
    if(keyfla==true){
          if(event.keyCode==38){funcUE();}
          else if(event.keyCode==40){funcST();}
          else if(event.keyCode==37){funcLE();}
          else if(event.keyCode==39){funcRI();}
    }
}
private function funcUE(){
    if(my_array1[nowY-1][nowX]==11){
        my_array1[nowY-1][nowX]=my_array1[nowY][nowX]
        my_array1[nowY][nowX]=11;
        nowY-=1;
        funcDispBlock();
    }else if(my_array1[nowY-1][nowX]!=undefined){
        my_array1[0][nowX]=my_array1[1][nowX];
        my_array1[1][nowX]=my_array1[2][nowX];        
        my_array1[2][nowX]=my_array1[3][nowX];
        my_array1[3][nowX]=my_array1[4][nowX];        
        my_array1[4][nowX]=11
        nowY=0;
        funcDispBlock();
    }decision(my_array1);
};
private function funcST(){
    if(my_array1[nowY+1][nowX]==11){
        my_array1[nowY+1][nowX]=my_array1[nowY][nowX]
        my_array1[nowY][nowX]=11;
        nowY+=1;
        funcDispBlock();
    }else if(my_array1[nowY+1][nowX]!=undefined){
        my_array1[4][nowX]=my_array1[3][nowX];
        my_array1[3][nowX]=my_array1[2][nowX];        
        my_array1[2][nowX]=my_array1[1][nowX];
        my_array1[1][nowX]=my_array1[0][nowX];        
        my_array1[0][nowX]=11;
        nowY=4;
        funcDispBlock();
    }decision(my_array1);
};
private function funcLE(){
    if(my_array1[nowY][nowX-1]==11){
        my_array1[nowY][nowX-1]=my_array1[nowY][nowX]
        my_array1[nowY][nowX]=11;
        nowX-=1;
        funcDispBlock();
    }else if(my_array1[nowY][nowX-1]!=undefined){
        my_array1[nowY][0]=my_array1[nowY][1];
        my_array1[nowY][1]=my_array1[nowY][2];        
        my_array1[nowY][2]=my_array1[nowY][3];
        my_array1[nowY][3]=my_array1[nowY][4];        
        my_array1[nowY][4]=11;
        nowX=0;
        funcDispBlock();
    }decision(my_array1);
};
private function funcRI(){
    if(my_array1[nowY][nowX+1]==11){
        my_array1[nowY][nowX+1]=my_array1[nowY][nowX]
        my_array1[nowY][nowX]=11;
        nowX+=1;
        funcDispBlock();
    }else if(my_array1[nowY][nowX+1]!=undefined){
        my_array1[nowY][4]=my_array1[nowY][3];
        my_array1[nowY][3]=my_array1[nowY][2];        
        my_array1[nowY][2]=my_array1[nowY][1];
        my_array1[nowY][1]=my_array1[nowY][0];        
        my_array1[nowY][0]=11;
        nowX=4;
        funcDispBlock();
    }decision(my_array1);
};

private function funcDispBlock(){
    for(var j=0; j<5; j++){
        for(var q=0; q<5; q++){
            var num:uint=my_array1[j][q];
            if(num!=11){
                var _mc=blockList[num];
                //_mc.y=_mc.yp=j*93;
                //_mc.x=q*93;
                _mc.yp=j*93;
                BetweenAS3.tween(_mc,{x:q*93,y:j*93},null,1,Back.easeOut).play();
            }
        }
    }
}

private function decision(arg:Array){if(arg[1][1]==1&&arg[1][2]==2&&arg[1][3]==3&&arg[2][1]==4&&arg[2][2]==5&&arg[2][3]==6&&arg[3][1]==7&&arg[3][2]==8&&arg[3][3]==9){clearMessage();};}
private function clearMessage(){
    keyfla=false;
    var _sp:clearPanel=new clearPanel();
    addChild(_sp);
}
private function disp(arg:Array){trace(arg[0],"\n",arg[1],"\n",arg[2],"\n",arg[3],"\n",arg[4]);}
//
}
}

//----------------------------------------------------------------------------------------------------

import flash.display.Sprite;
import flash.text.*;

class Blocks extends Sprite{
    public var posy:uint=0;
    public var posx:uint=0;

public var angel:uint=1;
    public var yp:uint=1;    
    private var tf:TextField = new TextField();
public function Blocks(arg:uint){
    var _sp:Sprite;
    if(arg==99){
        _sp=new drawChick();
        _sp.x=28;_sp.y=38;
        _sp.scaleX=_sp.scaleY=1.8;
    }else{
        _sp=new Sprite();
        _sp.graphics.beginFill(0xB4BE1F);
        _sp.graphics.drawRoundRect(0,0,93,93,50);
        _sp.graphics.endFill();
        _sp.graphics.beginFill(0xD8D41B);
        _sp.graphics.drawRoundRect(8,8,77,77,50);    
        _sp.graphics.endFill();
        
        //textformat
        var    fmt:TextFormat = new TextFormat();           
        fmt.size  = 60;
        fmt.align=TextFormatAlign.LEFT;
        fmt.color =0xffffff;//8D9220
        fmt.font="Impact";
    
        //text
        tf.defaultTextFormat = fmt;
        tf.text = String(arg);
        tf.width=tf.height=100;
        tf.x=28;tf.y=5;
        tf.selectable = false;
        _sp.addChild(tf);    
        
    }
    addChild(_sp);
}        
}

class drawChick extends Sprite{
    private var head:Sprite=new Sprite();
    private var body:Sprite=new Sprite();
    private var scarf:Sprite=new Sprite();
    /*public var foot:Sprite=new Sprite();
    
    public var dire:uint=Math.floor(Math.random()*2);
    public var angel:uint=1;*/
public function drawChick(){
        head.graphics.beginFill(0xFFCC33);
        head.graphics.drawCircle(0,0,10);//head
        head.graphics.endFill();
        var head_1:Sprite = new Sprite();
        head_1.graphics.beginFill(0x34929A);//eye
        head_1.graphics.drawCircle(-1,-1,2);
        head_1.graphics.endFill();
        head_1.graphics.beginFill(0xF6712E);//mouse
        head_1.graphics.drawEllipse(-15,-2,7,4);        
        head_1.graphics.endFill();
        head.addChild(head_1);
        addChild(head);
        
        body.graphics.beginFill(0xFFCC33);//body
        body.graphics.drawEllipse(2,2,30,20);
        body.graphics.endFill();
        var body_1:Sprite = new Sprite();
        body_1.graphics.beginFill(0xFFCC33);//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);    */

        scarf.graphics.beginFill(0xEF324E);
        scarf.graphics.drawEllipse(-5,8,14,3);
        scarf.graphics.endFill();    
        scarf.rotation=-40;        
        var scarf_1:Sprite = new Sprite();    
        scarf_1.graphics.beginFill(0xEF324E);
        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(0xEF324E);
        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 back_ground extends Sprite{
    public var angel:uint=1;
    private var arr:Array=[0x7DCCB6,0x9ADDCC];
public function back_ground(){
    var bg:Sprite=new Sprite();
    for(var j:int=0; j < 24; j++){
        bg.graphics.beginFill(arr[j%2],1);
        bg.graphics.drawRect(0,j*20,465,20);
        bg.graphics.endFill();        
    }
    addChild(bg);
}
}





class clearPanel extends Sprite{
    private var tf:TextField = new TextField();
public function clearPanel(){
    var bg:Sprite=new Sprite();
        bg.graphics.beginFill(0xffffff,0.8);
        bg.graphics.drawRect(0,0,465,465);
        bg.graphics.endFill();
        
        //textformat
        var    fmt:TextFormat = new TextFormat();  
        fmt.size  = 60;
        fmt.align=TextFormatAlign.LEFT;
        fmt.color =0xFEAA9F;
        fmt.font="Impact";
    
        //text
        tf.defaultTextFormat = fmt;
        tf.text = "Congratulation!!";
        tf.width=456;
        tf.x=30;tf.y=190;
        tf.selectable = false;
        bg.addChild(tf);    
    addChild(bg);
}
}