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

ソリティアっぽく動かす

Get Adobe Flash player
by hacker_cobulht0 27 Jan 2012
    Embed
package {     
    import flash.display.Sprite;
    import flash.events.*;
    
    [SWF(width = "465", height = "465", backgroundColor = 0xFFFFFF, frameRate = "60")]
    
    public class mock_Solitaire extends Sprite{
        //準備用
        private var trumpList:Array=[
        {num:1,surt:0}, {num:2,surt:0}, {num:3,surt:0}, {num:4,surt:0}, {num:5,surt:0}, {num:6,surt:0}, {num:7,surt:0}, {num:8,surt:0}, {num:9,surt:0}, {num:10,surt:0}, {num:11,surt:0}, {num:12,surt:0},{num:13,surt:0},
        {num:1,surt:1}, {num:2,surt:1}, {num:3,surt:1}, {num:4,surt:1}, {num:5,surt:1}, {num:6,surt:1}, {num:7,surt:1}, {num:8,surt:1}, {num:9,surt:1}, {num:10,surt:1}, {num:11,surt:1}, {num:12,surt:1},{num:13,surt:1},
        {num:1,surt:2}, {num:2,surt:2}, {num:3,surt:2}, {num:4,surt:2}, {num:5,surt:2}, {num:6,surt:2}, {num:7,surt:2}, {num:8,surt:2}, {num:9,surt:2}, {num:10,surt:2}, {num:11,surt:2}, {num:12,surt:2},{num:13,surt:2},
        {num:1,surt:3}, {num:2,surt:3}, {num:3,surt:3}, {num:4,surt:3}, {num:5,surt:3}, {num:6,surt:3}, {num:7,surt:3}, {num:8,surt:3}, {num:9,surt:3}, {num:10,surt:3}, {num:11,surt:3}, {num:12,surt:3},{num:13,surt:3}
        ];
        private var shuffleList:Array=new Array();
        
        private var pos1List:Array=new Array();
        private var pos2List:Array=new Array();
        private var pos3List:Array=new Array();
        private var pos4List:Array=new Array();
        private var pos5List:Array=new Array();
        private var pos6List:Array=new Array();
        private var pos7List:Array=new Array();
        
        private var pos8List:Array=new Array();
        
        private var goal_s0:uint=0;//Heart
        private var goal_s1:uint=0;//Dia
        private var goal_s2:uint=0;//Clover
        private var goal_s3:uint=0;//Spade
        
        private var mflag:String="no";
        private var nowCard;
        
        public function mock_Solitaire(){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);
            
            var nums:uint=trumpList.length;
            while (nums--) {
                var rd =Math.floor(Math.random()*(nums+1)); 
                shuffleList.push(trumpList[rd]);        
                trumpList.splice(rd,1);
            }
            makeGoal();
            makeSpace();
            Arrange();
        }
        //組札置き場をつくる
        private function makeGoal():void{
            for (var q:Number = 0; q<4; ++q) {
                var su_st:String;
                var co:Number;
                var su:uint;
                
                switch (q) {
                    case 0:
                        su_st="♥";
                        co=0xD03E5F;
                        su=0;
                    break;
                    case 1:
                        su_st="♦";
                        co=0xD03E5F;
                        su=1;
                    break;
                    case 2:
                        su_st="♣";
                        co=0x202728;
                        su=2;
                    break;
                    case 3:
                        su_st="♠";
                        co=0x202728;
                        su=3;
                    break;
                }
                
                var panel:GoalPosition=new GoalPosition(su_st,co,su);
                panel.x=q*65+200;
                panel.y=10;
                
                addChild(panel);
                panel.addEventListener(MouseEvent.MOUSE_DOWN, function(ev){goalClicks(ev.target.mySurt);});
            }
        }
        //7組場札置き場の空状態 をつくる
        private function makeSpace():void{
            for (var q:Number = 0; q<7; ++q) {
                var panel:spacePosition=new spacePosition(q);
                panel.x=q*65+5
                panel.y=170
                addChild(panel);
                panel.addEventListener(MouseEvent.MOUSE_DOWN, spaceClicks);
            }
        }        
        //7組場札置き場にカード配置
        private function Arrange():void{
            var cx:uint=1;
            var cy:uint=1;
            for (var q:Number = 0; q<shuffleList.length; ++q) {
                var mc:Card=new Card(shuffleList[q],cx,q);
                if(cx<8){
                    if(cy<cx){
                        mc.x=cx*65-60;
                        mc.y=cy*20+150;                
                        cy++;                        
                        this["pos"+cx+"List"].push(mc);
                        
                    }else{
                        mc.x=cx*65-60;
                        mc.y=cy*20+150;
                        mc.ura.visible=false;
                        mc.ura.alpha=0;
                        
                        this["pos"+cx+"List"].push(mc);
                        
                        cx++;
                        cy=1;
                    }
                }else{
                    mc.x=5;
                    mc.y=10;
                    mc.ura.visible=false;
                    mc.ura.alpha=0;
                    pos8List.push(mc);
                }
                addChild(mc);
                mc.addEventListener(MouseEvent.MOUSE_DOWN, cardClicks);
            }
        }
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
        
        //各トランプカードを押した場合
        private function cardClicks(ev){
            
            //----------------------------------------------------------------------------------------------------                
                        ///////カードをつかむ
                        if(mflag=="no"&&ev.target.parent.ura.visible==false){
                            nowCard=ev.target.parent;
                            mflag="lift";
                            ev.target.parent.ura.visible=true;
                            ev.target.parent.ura.alpha=0.5;                            
                        }
                        else if(mflag=="lift"&&ev.target.parent.gFLAG==false){
                            ///////カードを元の場所に戻す
                            if(ev.target.parent.myPOS==nowCard.myPOS){
                                nowCard.ura.visible=false;
                                nowCard.ura.alpha=0;
                                mflag="no";    
                            }
                            ///////赤黒赤黒に並べられるかどうか判定
                            else if(ev.target.parent.myPOS!=nowCard.myPOS&&ev.target.parent.myPOS!=8){
                                if(ev.target.parent.myOBJECT["num"]-1==nowCard.myOBJECT["num"]){
                                    var ue:String=mySurtCL(ev.target.parent.myOBJECT["surt"]);
                                    var sita:String=mySurtCL(nowCard.myOBJECT["surt"]);
                                    if(ue!=sita){
                                        func_akakuro(ev.target.parent);
                                    }
                                }
                            }                            
                        }
                        ///////中身はgoalClicksと同じ (上がったカードのmyPOSには一切触れない)                        
                        else if(mflag=="lift"&&ev.target.parent.gFLAG==true){
                            goalClicks(ev.target.parent.myOBJECT["surt"]);
                        }
            //----------------------------------------------------------------------------------------------------
            
        }
        
        //組札置き場にカードを置く (上がったカードのmyPOSには今後一切触れない)
        private function goalClicks(kSurt){
            if(mflag=="lift"&&kSurt==nowCard.myOBJECT["surt"]){
                if(nowCard.myOBJECT["num"]-1==this["goal_s"+kSurt]){
                    nowCard.x=kSurt*65+200;
                    nowCard.y=40;
                    nowCard.ura.visible=false;
                    nowCard.ura.alpha=0;
                    
                    var lastIndex:int = Object(root).numChildren - 1;
                    Object(root).setChildIndex(nowCard, lastIndex);
                    
                    this["pos"+nowCard.myPOS+"List"].pop();
                    this["goal_s"+kSurt]+=1;
                    nowCard.gFLAG=true;
                    mflag="no";
                    
                    nextOPEN(nowCard.myPOS);
                    decision();
                }
            }
        }
        //赤黒に並べる
        private function func_akakuro(ueCard){
            var prevPOS=nowCard.myPOS;
            var _slice:Number=cntLine(this["pos"+nowCard.myPOS+"List"],nowCard.myOBJECT);
            var _arr=this["pos"+nowCard.myPOS+"List"].slice(_slice);
            
            //一番手前のカードだけ
            if(_arr.length<=1){
            nowCard.x=ueCard.myPOS*65-60;
            nowCard.y=ueCard.y+20;
            nowCard.ura.visible=false;
            nowCard.ura.alpha=0;
            
            var lastIndex:int = Object(root).numChildren - 1;
            Object(root).setChildIndex(nowCard, lastIndex);
            
            this["pos"+(ueCard.myPOS)+"List"].push(nowCard)
            this["pos"+nowCard.myPOS+"List"].pop();            
            
            nowCard.myPOS=ueCard.myPOS;
            mflag="no";
            
            nextOPEN(prevPOS);
            
            //束を移動
            }else if(_arr.length>1){
                for(var q:uint=0; q <_arr.length; q++){
                    var movCard=_arr[q];
                    movCard.x=ueCard.myPOS*65-60;
                    movCard.y=20*(q+1)+ueCard.y;
                    movCard.ura.visible=false;
                    movCard.ura.alpha=0;
                    
                    var lastIndex_2:int = Object(root).numChildren - 1;
                    Object(root).setChildIndex(movCard, lastIndex_2);                    
                    
                    this["pos"+(ueCard.myPOS)+"List"].push(movCard);
                    
                    movCard.myPOS=ueCard.myPOS;
                }
                this["pos"+prevPOS+"List"].splice(_slice);        
                mflag="no";                
                nextOPEN(prevPOS);
            }
        }
        
        //次の手札を見せる
        private function nextOPEN(arg){
            if(arg!=8&&this["pos"+arg+"List"].length>0){
                var _index:uint=this["pos"+arg+"List"].length-1;
                this["pos"+arg+"List"][_index].ura.visible=false;
                this["pos"+arg+"List"][_index].ura.alpha=0;
            }
        }
        //自分が列の何行目にいるか
        private function cntLine(_list,_obj):Number{
            for(var q:uint=0; q <_list.length; q++){
                if(_list[q].myOBJECT["num"]==_obj["num"]&&_list[q].myOBJECT["surt"]==_obj["surt"]){
                return q;}
            }
            return 0;
        }
        //自分は何色か
        private function mySurtCL(surtNum):String{
            switch (surtNum) {
                    case 0:
                        return "aka";
                    break;
                    case 1:
                        return "aka";
                    break;
                    case 2:
                        return "kuro";
                    break;
                    case 3:
                        return "kuro";
                    break;
                    default:
                        return "error";
                    break;
                }
        }
        
        
        //7組場札の開いた場所にカードを置きたい場合
        private function spaceClicks(ev){
            var prevPOS=nowCard.myPOS;
            var _slice:Number=cntLine(this["pos"+nowCard.myPOS+"List"],nowCard.myOBJECT);
            var _arr=this["pos"+nowCard.myPOS+"List"].slice(_slice);
            
            if(mflag=="lift"&&this["pos"+(ev.target.myPOS_7)+"List"].length==0){
            //一番手前のカードだけ
            if(_arr.length<=1){
                    nowCard.x=ev.target.myPOS_7*65-60;
                    nowCard.y=170;
                    nowCard.ura.visible=false;
                    nowCard.ura.alpha=0;
                    
                    var lastIndex:int = Object(root).numChildren - 1;
                    Object(root).setChildIndex(nowCard, lastIndex);
                    
                    this["pos"+(ev.target.myPOS_7)+"List"].push(nowCard)
                    this["pos"+nowCard.myPOS+"List"].pop();                    

                    nowCard.myPOS=ev.target.myPOS_7;
                    mflag="no";
                    
                    nextOPEN(prevPOS);
            //束を移動
            }else if(_arr.length>1){
                for(var q:uint=0; q <_arr.length; q++){
                    var movCard=_arr[q];
                    movCard.x=ev.target.myPOS_7*65-60;
                    movCard.y=20*q+170;
                    movCard.ura.visible=false;
                    movCard.ura.alpha=0;
                    
                    var lastIndex_2:int = Object(root).numChildren - 1;
                    Object(root).setChildIndex(movCard, lastIndex_2);                    
                    
                    this["pos"+(ev.target.myPOS_7)+"List"].push(movCard);
                    
                    movCard.myPOS=ev.target.myPOS_7;
                }
                this["pos"+prevPOS+"List"].splice(_slice);        
                mflag="no";                
                nextOPEN(prevPOS);
            }
            
            }
        }
        
        
        
        
        
        
        
        
        
        
        private function decision():void{
            if(goal_s0==13&&goal_s1==13&&goal_s2==13&&goal_s3==13){trace("Congratulation!!")}
        }
        /*private function func_Trace(arg:Array,arg2:String){
            trace("\n",arg2);
            for(var q:uint=0; q <arg.length; q++){
                trace(arg[q].myOBJECT["num"],arg[q].myOBJECT["surt"]);
            }
            trace("\n");
        }*/
    }
}








//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
import flash.display.Sprite;
import flash.display.Shape;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.GlowFilter;

class Card extends Sprite{    
    private var omote:omote_pic;    
    public var ura:ura_pic;
    
    public var myPOS:uint;
    public var myOBJECT:Object;
    
    public var gFLAG:Boolean=false;
    
    public function Card(obj,pos,arg_ura){
        this.name="card"+obj["num"]+"_"+obj["surt"];
        myOBJECT=obj;
        myPOS=pos;
        
        var su:String;
        var co:Number;
        
        switch (obj["surt"]) {
            case 0:
                su="♥";
                co=0xFF496C;//D03E5F
            break;
            case 1:
                su="♦";
                co=0xFD7C6E;
            break;
            case 2:
                su="♣";
                co=0x506767;//202728
            break;
            case 3:
                su="♠";
                co=0x6E5160;
            break;
        }
        
        omote=new omote_pic(su+""+String(obj["num"]),co);
        ura =new ura_pic(arg_ura);
        
        addChildAt(omote,0);
        addChildAt(ura,1);
    }
}



class omote_pic extends Sprite{
public function omote_pic(str:String,col:Number){
    var _tf:TextField = new TextField();
    _tf.defaultTextFormat =  new TextFormat("_ゴシック",25,col);
    _tf.selectable = false;
    _tf.text=str;
    _tf.width=_tf.height=50;
    
    var bmd:BitmapData=new BitmapData(_tf.width,_tf.height, true, 0x00ffffff);
    bmd.draw(_tf);
    this.addChild(new Bitmap(bmd));
    
    this.graphics.beginFill(0xFFFFFF);
    this.graphics.drawRoundRect(0,0,60,80,10);
    this.graphics.endFill();
}
}

class ura_pic extends Sprite{
    var arr1:Array=[0xFFFFBB,0xC5E384];
    var arr11:Array=[0xC5E384,0xFFFFBB];
    var arr2:Array=[0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0/**/,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0]
public function ura_pic(arg_ura){
    var col:uint;
    col=arr1[arr2[arg_ura]];
    this.graphics.beginFill(col);
    this.graphics.drawRoundRect(0,0,60,80,10);
    this.graphics.endFill();    
    
    filters = [new GlowFilter(arr11[arr2[arg_ura]],1,10,10,1,1,true)];
}
}

class GoalPosition extends Sprite{
    public var mySurt:uint;
public function GoalPosition(str:String,col:Number,msurt:uint){
    mySurt=msurt;
    
    var _tf:TextField = new TextField();
    _tf.defaultTextFormat =  new TextFormat("_ゴシック",30,0xC5E384);//ゴールスペース色
    _tf.selectable = false;
    _tf.text="  "+str;
    _tf.width=_tf.height=50;
    
    var bmd:BitmapData=new BitmapData(_tf.width,_tf.height, true, 0x00ffffff);
    bmd.draw(_tf);
    this.addChild(new Bitmap(bmd));
    
    this.graphics.beginFill(0xFFFFDD);//ゴールスペース色2=空きポケ色
    this.graphics.drawRoundRect(0,0,60,80,10);
    this.graphics.endFill();
}
}

class spacePosition extends Sprite{
    public var myPOS_7:uint;
public function spacePosition(arg:uint){
    myPOS_7=arg+1;
    
    this.graphics.beginFill(0xFFFFDD);//ゴールスペース色2=空きポケ色
    this.graphics.drawRoundRect(0,0,60,80,10);
    this.graphics.endFill();
}
}

class back_ground extends Sprite{
public function back_ground( ){
    var arr:Array=[0xFCDC6B,0xFCE983,0xF0E991,0xEDEABF,0xC5E285,0xA8E39F,0x9FE2BF,0x77DEE7,0x9BCEEB,0xC5D0E6,0xAEADD7,/*0x9D81BA,*/0xCDA4DE,0xE6A8D7,0xFDD7E4,0xFDBDB4,0xFFCFAB,0xFED8B4,0xFBE7B5];
    var bmp:BitmapData = new BitmapData(465, 465, false, 0xffffff);
    var sh:Sprite = new Sprite();
    for(var j:int=0; j < 31; j++){
        var cl=j % arr.length;
        sh.graphics.beginFill(arr[cl]);
        sh.graphics.drawRect(0,j*15,465,15);
        sh.graphics.endFill();
        
        var sh2:Shape=new Shape();
        sh.addChild(sh2);
        sh2.graphics.beginFill(arr[cl],0.5);
        sh2.graphics.drawRect(j*15,0,15,465);
        sh2.graphics.endFill();
    }
    bmp.draw(sh);
    addChild(new Bitmap(bmp))
}
}