forked from: 後だしじゃんけんリベンジ、負けるが勝ちとは限らない

by Aksor.Al forked from 後だしじゃんけんリベンジ、負けるが勝ちとは限らない (diff: 1)
伊藤家の食卓やってた「後出しじゃんけん」は簡単すぎるとお嘆きのあなたへ!
今度はマジカルバナナでやっていた、「後出しじゃんけん」です。

そのつど、「勝って」、「負けて」、「あいこ」と指示が出ますので、
指示通りに勝ったり負けたりしてください。

ちなみに音声も出るようにしました。
音声合成はxpNavoを利用して作成しています。

ちょっと「もやもやっ」としています。

ソースは大した事してませんし、汚いですw
♥0 | Line 371 | Modified 2011-01-18 06:05:04 | MIT License
play

ActionScript3 source code

/**
 * Copyright Aksor.Al ( http://wonderfl.net/user/Aksor.Al )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4Clu
 */

// forked from narutohyper's 後だしじゃんけんリベンジ、負けるが勝ちとは限らない
package  
{
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.text.*;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.events.Event;
    import flash.utils.Timer;
    import flash.system.LoaderContext;
    import flash.media.SoundLoaderContext;
    import flash.geom.Point;
    import flash.geom.Rectangle;

    import flash.net.*;
    import flash.utils.escapeMultiByte;
    import flash.system.Security;
    import flash.net.URLRequest; 

    import jp.progression.casts.CastDocument;
    import jp.progression.commands.lists.LoaderList;
    import jp.progression.commands.lists.SerialList;
    import jp.progression.commands.net.LoadBitmapData;
    import jp.progression.commands.net.LoadSound;
    import jp.progression.commands.net.LoadURL;
    import jp.progression.commands.Func
    import jp.progression.data.Resource;
    import jp.progression.data.getResourceById;


    /** 
    * 
    * 伊藤家の食卓やってた「後出しじゃんけん」は簡単すぎるとお嘆きのあなたへ!
    * 今度はマジカルバナナでやっていた、「後出しじゃんけん」です。
    * 
    * そのつど、「勝って」、「負けて」、「あいこ」と指示が出ますので、
    * 指示通りに勝ったり負けたりしてください。
    * 
    * ちなみに音声も出るようにしました。
    * 音声合成はxpNavoを利用して作成しています。
    * 
    * ちょっと「もやもやっ」としています。
    * 
    * ソースは大した事してませんし、汚いですw
    * 
    */
    
    [SWF(backgroundColor = 0xffffff, frameRate = 40, width = 465, height = 465)]
    public class main extends Sprite
    {
        public var baseBmd:BitmapData;

        public var sound:Array

        public var text1:Sprite
        public var text2:Sprite
        public var text3:Sprite
        public var text4:Sprite

        public var spEn:Array
        public var spMy:Array

        public function main() {

            var imgUrl:String='http://marubayashi.net/archive/sample/magical/sample.jpg';
            sound=[];

            new SerialList(null,
                function():void {
                    var cmd:LoaderList = new LoaderList();
                    cmd.addCommand(
                        new LoadBitmapData(new URLRequest(imgUrl),
                            {
                                context: new LoaderContext(true),
                                catchError: function(target:Object, error:Error):void {
                                    target.executeComplete();
                                }
                            }
                        )
                    );
                    for (var i:uint=1;i<5;i++) {
                        cmd.addCommand(
                            new LoadSound(new URLRequest('http://marubayashi.net/archive/sample/magical/voice_0'+i+'.mp3'),
                                {
                                    context: new SoundLoaderContext(1000,true),
                                    catchError: function(target:Object, error:Error):void {
                                        target.executeComplete();
                                    }
                                }
                            )
                        );
                    }
                    this.parent.insertCommand(cmd);
                }
                ,
                function():void {
                    baseBmd = getResourceById(imgUrl).toBitmapData();
                    for (var i:uint=1;i<5;i++) {
                        sound[i-1] = getResourceById('http://marubayashi.net/archive/sample/magical/voice_0'+i+'.mp3').toSound();
                    }


                    imgComplete()
                }
            ).execute();


        }

        private function imgComplete():void {
            //じゃんけん画像の切り出し

            spEn=[]
            spMy=[]

            spEn[0]=makeCard(baseBmd,465/2, 80,  0,  0,100,100,180)
            spEn[1]=makeCard(baseBmd,465/2, 80,100,  0,100,100,180)
            spEn[2]=makeCard(baseBmd,465/2, 80,  0,100,100,100,180)

            spMy[0]=makeCard(baseBmd,465/2-120,350,  0,  0,100,100)
            spMy[1]=makeCard(baseBmd,465/2,      350,100,  0,100,100)
            spMy[2]=makeCard(baseBmd,465/2+120,350,  0,100,100,100)

            text1=makeCard(baseBmd,465/2-10, 465/2-50,100,100,100,25)
            text1.rotation=-10
            text2=makeCard(baseBmd,465/2+30, 465/2-20,100,125,100,25)
            text2.rotation=20
            text3=makeCard(baseBmd,120,     140,100,150,100,25)
            text3.rotation=10
            text3.scaleX=1*1.5
            text3.scaleY=1.5*1.5
            text4=makeCard(baseBmd,485-120, 200,100,175,100,25)
            text4.rotation=-10
            text4.scaleX=1*1.5
            text4.scaleY=1.5*1.5

            var format:TextFormat=new TextFormat();
            format.color=0x000000
            format.size=13;
            format.font='_等幅';
            format.leading = 10;
            format.align = "center"
            format.bold=true;
            var guide:TextField=setTextField(format,(464-100)/2,100,100,18)
            guide.appendText('伊藤家の食卓やってた「後出しじゃんけん」は\n簡単すぎるとお嘆きのあなたへ!\n');
            guide.appendText('今度はマジカルバナナでやっていた、「後出しじゃんけん」です。\n')
            guide.appendText('そのつど、「勝って、負けて、あいこ」と指示が出ますので、\n')    
            guide.appendText('指示通りに勝ったり負けたりしてください。\n')            
            guide.appendText('間違うとゲームオーバーです\nちなみにもやっとした音声も出るようにしました。')
            addChild(guide);
            
            format.size=14;
            format.align = "left"
            var guide2:TextField=setTextField(format,50,50,100,100,1)
            guide2.text=''
            addChild(guide2);

            format.align = "center"
            var guide3:TextField=setTextField(format,(464-100)/2,200,100,100)
            guide3.text=''
            addChild(guide3);
            guide3.visible=false

            format.align = "center"
            var guide4:TextField=setTextField(format,(464-150),50,120,100)
            guide4.text=''
            addChild(guide4);



            var bt:Button = new Button('START',150)
            bt.x = stage.stageWidth/2 - bt.width/2;
            bt.y = 300;
            bt.addEventListener(MouseEvent.CLICK, init);
            addChild(bt);

            var bt2:Button = new Button('もう一度',150)
            bt2.x = stage.stageWidth/2 - bt.width/2 +100;
            bt2.y = 380;
            bt2.addEventListener(MouseEvent.CLICK, init);
            addChild(bt2);
            bt2.visible=false

            var bt3:Button = new Button('結果をTwitterに投稿する',150)
            bt3.x = stage.stageWidth/2 - bt.width/2 -100;
            bt3.y = 380;
            bt3.addEventListener(MouseEvent.CLICK, post);
            addChild(bt3);
            bt3.visible=false

            var timer:Timer=new Timer(600, 10)
            timer.addEventListener(TimerEvent.TIMER, timerHandler);
            var result:uint=0;
            var counter:uint;
            var enType:uint;
            var myType:uint;
            var nextType:uint
            

            function init():void {
                bt2.visible=false
                bt3.visible=false
                guide3.visible=false
                guide4.visible=true
                result=0;
                guide2.text='';
                gameStart()
            }


            function gameStart():void {
                guide.visible=false
                bt.visible=false
                timer.start()
                counter=0;

                text1.visible=false
                text2.visible=false
                text3.visible=false
                text4.visible=false

                for(var i:uint=0;i<3;i++) {
                    spEn[i].visible=false
                    spMy[i].visible=true
                    spMy[i].y=350
                    spMy[i].alpha=0.5
                    spMy[i].addEventListener(MouseEvent.MOUSE_OVER, mouseHandler);
                    spMy[i].addEventListener(MouseEvent.MOUSE_OUT, mouseHandler);
                    spMy[i].addEventListener(MouseEvent.CLICK, mouseHandler);
                }
            }

            function timerHandler(e:TimerEvent):void{
                counter++;
                if(counter==1) {
                    //次の宣言
                    var tempType:uint=Math.floor(Math.random()*6);
                    if (tempType>=0 && tempType<2) {
                        guide4.text='次は\n「勝って」下さい。';
                        sound[0].play(700)
                        nextType=0;
                    } else if (tempType>=2 && tempType<5) {
                        guide4.text='次は\n「負けて」下さい。';
                        sound[1].play(700)
                        nextType=1;                        
                    } else {
                        guide4.text='次は\n「あいこ」の体で。';
                        sound[2].play(700)
                        nextType=2;                        
                    }

                } else if(counter==4) {
                    sound[3].play(100)
                    //じゃん
                    text1.visible=true
                } else if(counter==5) {
                    //けん
                    text2.visible=true
                } else if(counter==6) {
                    //ぽん
                    text3.visible=true
                    enType=Math.floor(Math.random()*3)
                    spEn[enType].visible=true
                } else if(counter==7) {
                    //ぽん
                    text4.visible=true
                } else if(counter==9) {
                    myType=3
                    for(var i:uint=0;i<3;i++) {
                        if (spMy[i].y==300) {
                            myType=i
                        }
                        spMy[i].removeEventListener(MouseEvent.MOUSE_OVER, mouseHandler);
                        spMy[i].removeEventListener(MouseEvent.MOUSE_OUT, mouseHandler);
                        spMy[i].removeEventListener(MouseEvent.CLICK, mouseHandler);
                    }
                    //判定
                    timer.stop()
                    timer.reset()

                    //負け勝負
                    if (nextType==0) {
                        //勝ち勝負
                        if ((enType==0&&myType==2)||(enType==1&&myType==0)||(enType==2&&myType==1)) {
                            result++
                            guide2.text='ただいま\n'+result+'連勝中'
                            gameStart()
                        } else {
                            endGame()
                        }
                    } else if (nextType==1) {
                        //負け勝負
                        if ((enType==0&&myType==1)||(enType==1&&myType==2)||(enType==2&&myType==0)) {
                            result++
                            guide2.text='ただいま\n'+result+'連勝中'
                            gameStart()
                        } else {
                            endGame()
                        }
                    } else if (nextType==2) {
                        //あいこ勝負
                        if (enType==myType) {
                            result++
                            guide2.text='ただいま\n'+result+'連勝中'
                            gameStart()
                        } else {
                            endGame()
                        }
                    }

                }
            }

            function endGame():void{

                if (nextType==0) {
                    if (enType==myType) {
                        guide3.text='あいこですので、GameOverです'
                    } else if ((enType==0&&myType==1)||(enType==1&&myType==2)||(enType==2&&myType==0)) {
                        guide3.text='あなたが負けましたので、GameOverです'
                    } else if(myType==3) {
                        guide3.text='時間切れですので、GameOverです'
                    }
                } else if (nextType==1) {
                    if (enType==myType) {
                        guide3.text='あいこですので、GameOverです'
                    } else if ((enType==0&&myType==2)||(enType==1&&myType==0)||(enType==2&&myType==1)) {
                        guide3.text='あなたが勝ちましたので、GameOverです'
                    } else if(myType==3) {
                        guide3.text='時間切れですので、GameOverです'
                    }
                } else if (nextType==2) {
                    if(myType==3) {
                        guide3.text='時間切れですので、GameOverです'
                    } else if ((enType==0&&myType==2)||(enType==1&&myType==0)||(enType==2&&myType==1)) {
                        guide3.text='あなたが勝ちましたので、GameOverです'
                    } else if ((enType==0&&myType==1)||(enType==1&&myType==2)||(enType==2&&myType==0)) {
                        guide3.text='あなたが負けましたので、GameOverです'
                    }
                }
                

                text1.visible=false
                text2.visible=false
                text3.visible=false
                text4.visible=false

                guide3.visible=true

                bt2.visible=true
                bt3.visible=true
            }


            function mouseHandler(e:MouseEvent):void {
                if (e.type==MouseEvent.MOUSE_OVER) {
                        e.target.alpha=1
                } else if (e.type==MouseEvent.MOUSE_OUT) {
                        e.target.alpha=0.5
                } else if (e.type==MouseEvent.CLICK) {
                        //e.target.alpha=50
                    e.target.alpha=1
                    e.target.y=300

                    for(var i:uint=0;i<3;i++) {
                        spMy[i].removeEventListener(MouseEvent.MOUSE_OVER, mouseHandler);
                        spMy[i].removeEventListener(MouseEvent.MOUSE_OUT, mouseHandler);
                        spMy[i].removeEventListener(MouseEvent.CLICK, mouseHandler);
                    }
                }
            }



            function post(evt:MouseEvent):void {
                var st:String;
                var thisURL:String = " http://bit.ly/cijOAw %23wonderfl";
                st = "http://twitter.com/home?status="+escapeMultiByte(result+"回で終了。「後だしじゃんけんリベンジ、負けるが勝ちとは限らない!もやっとバージョン」") + thisURL;
                navigateToURL(new URLRequest(st));
            }



        }


        private function makeCard(bmd:BitmapData,_x:Number,_y:Number,_nx:Number,_ny:Number,_w:Number,_h:Number,_round:Number=0):Sprite {
            var tempBmd:BitmapData=new BitmapData(_w,_h,false,0xFFFFFFFF)
            var tempBm:Bitmap=new Bitmap(tempBmd,'auto',true)
            var tempSp:Sprite=new Sprite()

            tempBmd.copyPixels(bmd,new Rectangle(_nx,_ny,_w,_h),new Point(0,0))
            tempSp.addChild(tempBm)
            tempBm.scaleY=1.4
            tempBm.x=-tempBm.width/2
            tempBm.y=-tempBm.height/2;
            tempSp.x=_x;
            tempSp.y=_y;
            tempSp.blendMode=BlendMode.MULTIPLY;

            tempSp.rotation=_round
            addChild(tempSp)
            tempSp.visible=false

            return tempSp
        }


        private function setTextField(_format:TextFormat,_x:uint=0,_y:uint=0,_w:uint=100,_h:uint=40,_type:uint=0):TextField {

            var tbox:TextField=new TextField()
            tbox.x=_x;
            tbox.y=_y;
            tbox.width=_w;
            tbox.height=_h;
        
            if (_type) {
                tbox.autoSize=TextFieldAutoSize.LEFT
            } else {
                tbox.autoSize=TextFieldAutoSize.CENTER
            }
                tbox.selectable=false;
                tbox.mouseEnabled=false;
                _format.color=0x000000


            tbox.defaultTextFormat=_format

            return tbox;
        }


    }


}


import flash.display.*;
import flash.text.*;
class Button extends SimpleButton
{

    public function Button(label:String, width:int = 0):void
    {
        var up:Sprite = _buildImage(label, 0xCCCCCC, width);
        var over:Sprite = _buildImage(label, 0xFFCCCC, width);
        var down:Sprite = _buildImage(label, 0xCC9999, width);
        down.y = 1;
        super(up, over, down, up);
    }

    private static function _buildImage(label:String, color:int, width:int = 0):Sprite
    {
        var text:TextField = new TextField();
        text.defaultTextFormat = new TextFormat('Verdana', 10, 0x000000, true, null, null, null, null, TextFormatAlign.CENTER);
        text.autoSize = TextFieldAutoSize.CENTER;
        text.selectable = false;
        text.text = label;
        text.x = (width - text.width) >> 1;
        text.y = 5;
        var base:Shape = new Shape();
        var g:Graphics = base.graphics;
        g.beginFill(color);
        g.drawRect(0, 0, width, text.height + 10);
        g.endFill();
        var sp:Sprite = new Sprite();
        sp.addChild(base);
        sp.addChild(text);
        return sp;
    }
}