じゃんけんシミュVS 3Person

by YAZUMA forked from じゃんけんシミュ (diff: 525)
超汚いソース
♥0 | Line 483 | Modified 2010-06-26 05:33:48 | MIT License
play

ActionScript3 source code

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

// forked from YAZUMA's じゃんけんシミュ
// 超汚いソース
package
{
    import flash.display.*;
    import flash.text.*;
    import flash.net.URLRequest;
    import flash.events.*;
    import flash.utils.Timer;

        [SWF(backgroundColor=0x0,width=400,height=400,frameRate=60)]

    import flash.geom.Matrix;
    import flash.geom.Rectangle;
    import flash.geom.Point;
    import flash.net.URLLoader;
    public class janken extends Sprite
    {
        public var NPC:int = 0;
        public var NPCjadge:Array = [3];
        public var NPChands:Array = [30];
        public var NPC2:int = 0;
        public var NPC3:int = 0;
        public var PC:int = 0;
        public var person:int = 0;
        public var guu:int = 0;
        public var choki:int = 0;
        public var paa:int = 0;
        public var counter:int = 0;
        public var super_counter:int = 0;
        public var double:int = 0;
        public var beforehand:int = 0;
        public var beforehand2:int = 0;
        public var beforehandPC:int = 0;
        public var beforehandPC2:int = 0;
        public var jadgement:int;
        public var win:int = 0;
        public var lose:int = 0;
        public var drow:int = 0;
        public var time:int = 0;
        public var jann:int = 0;
        public var winpar:int = 0;
        public var s:Sprite = new Sprite;
        public var s2:Sprite = new Sprite;
        public var logo:Sprite;
        public var uRLRequest:URLRequest;
        public var loader:Loader = new Loader(); 
        public var loader2:Loader = new Loader();
        public var loader3:Loader = new Loader();
        public var loader4:Loader = new Loader();
        public var loaderA:Loader = new Loader();
        public var loaderB:Loader = new Loader();
        public var textbox:TextField = new TextField();
        public var outputBox:TextField = new TextField();
        public var nowtime:TextField = new TextField();
        public var jadgebox:TextField = new TextField();
        public var parcentage:TextField = new TextField();
        public var mode:TextField = new TextField();
        public var lebel:TextField = new TextField();
        public var player1:TextField = new TextField();
        public var player2:TextField = new TextField();
        public var player3:TextField = new TextField();
        public var player4:TextField = new TextField();
        public var drow_write:TextField = new TextField();
        public var jadgeformat:TextFormat = new TextFormat("HGS創英角ゴシックUB", 20);
        public var text:String = "ココに試行回数を入力";
        public var myTimer:Timer;
        
        public function janken():void {
            addChild(s);
            textbox.type = TextFieldType.INPUT;
            textbox.maxChars = 3;
            textbox.restrict = "0-9";
            textbox.background = true;
            textbox.width = 150;
            textbox.height = 30;
            textbox.x = 10;
            textbox.y = 10;
            textbox.textColor = 0x6A5ACD;
            addChild(textbox);
            textbox.text = text;
            textbox.addEventListener(Event.CHANGE, textInputCapture);
            textbox.addEventListener(MouseEvent.CLICK, click_text);
            outputBox.background = true;
            //outputBox.text = textbox.text+"回ジャンケンします";
            outputBox.x = 10;
            outputBox.y = 25;
            outputBox.width = 150;
            outputBox.height = 30;
            nowtime.background = true;
            nowtime.x = 10;
            nowtime.y = 40;
            nowtime.height = 30;
            jadgebox.background = true;
            jadgebox.x = 380;
            jadgebox.y = 10;
            jadgebox.height = 45;
            jadgebox.width = 100;
            jadgebox.textColor = 0x0f0f00;
            jadgebox.defaultTextFormat = jadgeformat;
            jadgebox.antiAliasType = "flash.text.AntiAliasType.ADVANCED";
            parcentage.background = true;
            parcentage.x = 383;
            parcentage.y = 35;
            parcentage.width = 75;
            parcentage.height = 17;
            mode.background = true;
            mode.x = 190;
            mode.y = 10;
            mode.height = 18;
            mode.width = 70;
            mode.text = "Manual mode";
            mode.textColor = 0x9ACD32;
            mode.addEventListener(MouseEvent.CLICK, change_mode);
            addChild(mode);
            lebel.background = true;
            lebel.x = 205;
            lebel.y = 35;
            lebel.height = 18;
            lebel.width = 70;
            lebel.text = "Easy";
            lebel.textColor = 0x1E90FF;
            lebel.addEventListener(MouseEvent.CLICK, change_lebel);
            addChild(lebel);
            player1.background = true;
            player1.x = 60;
            player1.y = 260;
            player1.text = "John";
            addChild(player1);
            player2.background = true;
            player2.x = 210;
            player2.y = 190;
            player2.text = "Becky";
            addChild(player2);
            player3.background = true;
            player3.x = 370;
            player3.y = 260;
            player3.text = "Tony";
            addChild(player3);
            player4.background = true;
            player4.x = 220;
            player4.y = 340;
            player4.text = "You";
            addChild(player4);
            drow_write.background = true;
            drow_write.x = 384;
            drow_write.y = 52;
            addChild(drow_write);
        }
 
        //画像表示
        public function handmaker(jan_loader:Loader):void{
            person++;
            NPC = Math.floor(Math.random()* (99 - 0 +1 ) )+0;
            NPC = NPC % 3;
            if(lebel.text == "Hard" && person == 3)hard_lebel();
            if(lebel.text == "Personality" && person == 1)Personality();
            if(lebel.text == "Personality" && person == 2)Personality2();
            if (NPC==0){                 
                uRLRequest = new URLRequest("http://trt.up.seesaa.net/image/goo-02.gif");  
            }else if(NPC ==1){
                 uRLRequest = new URLRequest("http://trt.up.seesaa.net/image/cyoki-02.gif");  
            }else{
                 uRLRequest = new URLRequest("http://trt.up.seesaa.net/image/paa-02.gif");  
            }
            configureListeners(jan_loader.contentLoaderInfo);
            jan_loader.load(uRLRequest);
            if(person == 3){
                person = 0;
                jann++;
                nowtime.text = jann + "/" + time;

            }
            if(person == 1)NPC2 = NPC;
            if(person == 2)NPC3 = NPC;
            //hardモードの記録
            if(NPChands.length == 30){
                for(var i:int = 0;i < 30;i++){
                    NPChands[i] = NPChands[i+1];
                }
                NPChands[29] = NPC;
                if(person==3)NPChands[29] = PC;
            }else
            NPChands[NPChands.length] = NPC;
            if(person==3)NPChands[NPChands.length] = PC;
        }

        public function configureListeners(dispatcher:IEventDispatcher):void{
            //縮小表示
            dispatcher.addEventListener(Event.COMPLETE, completeHandler);
        }
        public function completeHandler(evt:Event):void{
            loader.width = 120;
            loader.height = 120;
            loader.x = 10;
            loader.y = 140;
            loaderA.width = 120;
            loaderA.height = 120;
            loaderA.x = 170;
            loaderA.y = 70;
            loaderB.width = 120;
            loaderB.height = 120;
            loaderB.x = 330;
            loaderB.y = 140;
            s.graphics.clear();
            s.addChild(loader);
            s.addChild(loaderB);
            s.addChild(loaderA);
            addChild(s);
        }
        public function handmaker2(uRLRequest1:URLRequest,uRLRequest2:URLRequest,uRLRequest3:URLRequest):void{
             configureListeners2(loader2.contentLoaderInfo);
            loader2.load(uRLRequest1);
            configureListeners2(loader3.contentLoaderInfo);
            loader3.load(uRLRequest2);
            configureListeners2(loader4.contentLoaderInfo);
            loader4.load(uRLRequest3);
            loader2.addEventListener(MouseEvent.CLICK, loader2_click);
            loader3.addEventListener(MouseEvent.CLICK, loader3_click);
            loader4.addEventListener(MouseEvent.CLICK, loader4_click);
        }
        public function loader2_click(evt:MouseEvent):void{
            if(jann < time){
                handmaker(loader);
                NPCjadge[0] = NPC;
                handmaker(loaderA);
                NPCjadge[1] = NPC;
                handmaker(loaderB);
                NPCjadge[2] = NPC;
                PC = 0;
                guu++;
                if(jann > 0)beforehandPC2 = beforehandPC;
                beforehandPC = PC;
                jadge2();
            }
        }
        public function loader3_click(evt:MouseEvent):void{
            if(jann < time){
                handmaker(loader);
                NPCjadge[0] = NPC;
                handmaker(loaderA);
                NPCjadge[1] = NPC;
                handmaker(loaderB);
                NPCjadge[2] = NPC;
                PC = 1;
                choki++;
                if(jann > 0)beforehandPC2 = beforehandPC;
                beforehandPC = PC;
                jadge2();
            }
        }
        public function loader4_click(evt:MouseEvent):void{
            if(jann < time){
                handmaker(loader);
                NPCjadge[0] = NPC;
                handmaker(loaderA);
                NPCjadge[1] = NPC;
                handmaker(loaderB);
                NPCjadge[2] = NPC;
                PC = 2;
                paa++;
                if(jann > 0)beforehandPC2 = beforehandPC;
                beforehandPC = PC;
                jadge2();
            }
        }
        public function configureListeners2(dispatcher:IEventDispatcher):void{
            //縮小表示
            dispatcher.addEventListener(Event.COMPLETE, completeHandler2);
        }
        public function completeHandler2(evt:Event):void{
            loader2.width = 100;
            loader2.height = 100;
            loader2.x = 70;
            loader2.y = 360;
            addChild(loader2);
            loader3.width = 100;
            loader3.height = 100;
            loader3.x = 180;
            loader3.y = 360;
            addChild(loader3);
            loader4.width = 100;
            loader4.height = 100;
            loader4.x = 290;
            loader4.y = 360;
            addChild(loader4);
        }
        //以下試行回数入力テキストボックス用
        public function textInputCapture(event:Event):void{
            var str:String = textbox.text;    
            createOutBox(str);
            if(time != 0)removeChild(logo);
            jann = 0;
            win = 0;
            lose = 0;
            drow = 0;
            guu = 0;choki = 0;paa = 0;double = 0;
            removeChild(s);
            jadgebox.text = "";
            drow_write.text = "あいこ:0回";
            if(mode.text == "Auto mode")auto_mode();
        }
        public function click_text(event:MouseEvent):void{
            textbox.text = "";
            jann = 0;
            time = 0;
            parcentage.text = "勝率:0%";
        }
        public function change_mode(event:MouseEvent):void{
            if(mode.text == "Manual mode"){
                mode.textColor = 0xF4A460;
                mode.text = "Auto mode";
                auto_mode();
            }else{
                mode.textColor = 0x9ACD32;
                mode.text = "Manual mode";
            }
        }
        public function change_lebel(event:MouseEvent):void{
            if(lebel.text == "Easy"){
                lebel.textColor = 0xDC143C;
                lebel.text = "Hard";
            }else if(lebel.text == "Hard"){
                lebel.textColor = 0x7FFF00;
                lebel.text = "Personality";
            }else{
                lebel.textColor = 0x1E90FF;
                lebel.text = "Easy";
            }
        }
        public function createOutBox(str:String):void{
            outputBox.text = textbox.text+"回ジャンケンします";
            time = int(textbox.text);
            addChild(outputBox);
            nowtime.text = jann+"/"+time;
            addChild(nowtime);
            addChild(jadgebox);
            addChild(parcentage);
            var uRLRequest1:URLRequest = new URLRequest("http://trt.up.seesaa.net/image/goo-02.gif");  
             var uRLRequest2:URLRequest = new URLRequest("http://trt.up.seesaa.net/image/cyoki-02.gif");  
             var uRLRequest3:URLRequest = new URLRequest("http://trt.up.seesaa.net/image/paa-02.gif");  
            handmaker2(uRLRequest1,uRLRequest2,uRLRequest3);
        }
        public function jadge2():void{
            var win_num:int = 0;
            var lose_num:int = 0;
            var drow_num:int = 0;
            NPCjadge[0] = (PC - NPCjadge[0] + 3) % 3;
            NPCjadge[1] = (PC - NPCjadge[1] + 3) % 3;
            NPCjadge[2] = (PC - NPCjadge[2] + 3) % 3;
            for(var num:int = 0;num < 3;num++){
                if(NPCjadge[num] == 0)drow_num++;
                if(NPCjadge[num] == 1)lose_num++;
                if(NPCjadge[num] == 2)win_num++;
            }
            //判定開始 まずはあいこ
            if(drow_num == 3){
                jadgebox.textColor = 0x008000;
                jadgebox.text = "あいこ";
                drow++;
                parcentage.text = "勝率:" + Math.floor((win/(jann))*100) + "%";
                if(jann == drow)parcentage.text = "勝率:0%";
            }else if(lose_num>0 && win_num>0){
                jadgebox.textColor = 0x008000;
                jadgebox.text = "あいこ";
                drow++;
                parcentage.text = "勝率:" + Math.floor((win/(jann))*100) + "%";
                if(jann == drow)parcentage.text = "勝率:0%";
            }else if(lose_num == 0 && win_num > 0){
                //勝ち
                jadgebox.textColor = 0xFF0000;
                jadgebox.text = "勝ち!";
                win++;
                parcentage.text = "勝率:" + Math.floor((win/(jann))*100) + "%";
            }else if(lose_num > 0 && win_num == 0){
                //負け
                jadgebox.textColor = 0x00008B;
                jadgebox.text = "負け";
                lose++;
                parcentage.text = "勝率:" + Math.floor((win/(jann))*100) + "%";
            }
            drow_write.text = "あいこ:" + drow + "回";
            winpar = Math.floor((win/(jann-drow))*100);
            if(jann == time)score();
        }
        //審判 ↓は1:1用
        public function jadge():void{
            jadgement = (PC - NPC + 3) % 3;
            if(jann > 0)beforehandPC2 = beforehandPC;
            beforehandPC = PC;
            if(jadgement == 0){
                //あいこ
                jadgebox.textColor = 0x008000;
                jadgebox.text = "あいこ";
                drow++;
                parcentage.text = "勝率:" + Math.floor((win/(jann))*100) + "%";
                if(jann == drow)parcentage.text = "勝率:0%";
            }else if(jadgement == 1){
                //負け
                jadgebox.textColor = 0x00008B;
                jadgebox.text = "負け";
                lose++;
                parcentage.text = "勝率:" + Math.floor((win/(jann))*100) + "%";
            }else if(jadgement == 2){
                //勝ち
                jadgebox.textColor = 0xFF0000;
                jadgebox.text = "勝ち!";
                win++;
                parcentage.text = "勝率:" + Math.floor((win/(jann))*100) + "%";
            }
        }
        //Auto mode
        public function auto_mode():void{
            for(var i:int = jann; jann < time; i++){
                PC = Math.floor(Math.random()* (100 - 0 +1 ) )+0;
                PC = PC % 3;
                handmaker(loader);
                handmaker(loaderA);
                handmaker(loaderB);
                jadge2();
            }  
        }
        public function hard_lebel():void{

            var guu_par:int = 100 * guu / jann;
            var choki_par:int = 100 * choki / jann;
            var paa_par:int = 100 * paa / jann;
            var num:int = Math.floor(Math.random()* (2 - 0 +1 ) )+0;
            choki_par += guu_par;
            paa_par += choki_par;
            var parce:int = Math.floor(Math.random()* (100 - 0 +1 ) )+0;
            /*if(num != 0){
                if(0 <= parce && parce < guu_par){
                    NPC = 0;
                    //else if(paa_par-choki_par > choki_par-guu_par)NPC = 1;
                    if(num == 1) NPC = 2;
                }
                if(guu_par <= parce&& parce < choki_par){
                    NPC = 1;
                    //else if(paa_par-choki_par > guu_par)NPC = 2;
                    if(num == 1) NPC = 0;
                }
                if(choki_par <= parce){
                    NPC = 2;
                    //else if(choki_par-guu_par > guu_par)NPC = 2;
                    if(num == 1) NPC = 1;
                }
            }else{
                NPC = PC + 1;
                if(NPC == 3)NPC = 0; 
                if(num != 1)NPC = PC;
                if(NPC == -1)NPC = 2;
            }    */    
                if(num != 0){
                    NPC = PC + 1;
                    if(NPC == 3)NPC = 0;
                }else NPC = PC - 1;
                if(NPC == - 1)NPC = 2;
            if(beforehandPC2 == PC){
                    NPC = PC + 1;
                    if(NPC == 3)NPC = 0;
            }
            if(super_counter > 0){
                NPC = PC - 1;
                if(NPC == -1)NPC = 2;
            }
            if(NPC == beforehand)counter++;
            if(PC != beforehandPC2)super_counter = 0;
            if(PC == beforehandPC2){
                super_counter++;
                double++;
            }
        }
        public function Personality():void{
            var parce:int = Math.floor(Math.random()* (100 - 0 +1 ) )+0;
            NPC = 2;
            if(parce < 70)NPC = 1;
            if(parce < 40)NPC = 0;
        }
        public function Personality2():void{
            var parce:int = Math.floor(Math.random()* (100 - 0 +1 ) )+0;
            NPC = 2;
            if(parce < 50)NPC = 1;
            if(parce < 30)NPC = 0;
        }
        public function score():void{
            var i:int = 3;
            //var winpar:int = int(parcentage.text);//Math.floor((win/(jann - drow))*100);
            if(winpar < 65)i = 2;
            if(winpar < 50)i = 1;
            if(winpar<40)i = 0;
            logo = new g(i);
            logo.x = 420;
            logo.y = 300;
            logo.z = 300;
            addChild(logo);
            logo.rotationX = -60;
        }
    }
}
import flash.display.*;
import flash.text.*;
import flash.events.Event;
import flash.display.Sprite;
class g extends Sprite{
    public var tf1:TextField = new TextField();
    public var text_format:TextFormat=new TextFormat("Arial",42,0xDAA520,true,null,null,null,null,TextFormatAlign.JUSTIFY);
    private var cnt:int;
    public function g(i:int){ 
        var num:int = i;
        if(num == 0)tf1.text = "Too Bad!";
        if(num == 1)tf1.text = "Somewhat bad.";
        if(num == 2)tf1.text = "Good!";
        if(num == 3)tf1.text = "Congraturation!!         You have a good luck!!!";
        tf1.width = 500; //表示テキスト横幅
        tf1.height = 1000;   //表示テキスト縦幅
        tf1.x = -300;         //表示テキスト横位置
        tf1.y = 350;         //表示テキスト縦位置
        tf1.wordWrap= true
        //tf1.type = "input";
        tf1.multiline = true;
        tf1.textColor = 0xff0000;
        //tf1.autoSize=TextFieldAutoSize.LEFT;
        tf1.setTextFormat(text_format);
        addChild(tf1);      //追加
        this.addEventListener(Event.ENTER_FRAME, watch);
    }
    
    private function watch(e:Event ):void{
        tf1.y -=2;
    }
}