/**
 * Copyright (c) 2014,www.easygame.org
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the easygame.org nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
module virus{

    /**
     * <p>HallUI的逻辑类</p>
     * @date  :2020-02-11 17:58:48
     * @EasyGame.org Tools
     */ 
    export class HallView  extends easy.View{
        public constructor() {
            super();
        }
        /**
         * 初始化主场景的组件,加入场景时,主动调用一次
         * 子类覆写该方法,添加UI逻辑
         */  
        public createChildren():void {
            super.createChildren();
            this.ui = new HallUI();
        }
        /**
         * 获取ui对象
         * @returns
         */
        public get ui():HallUI{
            return <HallUI>this._ui;
        }

        /**
         * 设置ui对象
         * @param
         */
        public set ui(myui:HallUI){
            this.setUI(myui);
        }
        /**
         * 初始化一些必要的逻辑数据
         * 这个方法是在第一次加入stage的时候,做调用
         */
        public initData():void {
            super.initData();
            //TODO 添加协议弱响应的方法,一般是用来驱动刷新当前的ui
            //参数说明:第一个参数是协议的id号
            //        第二个参数是本类public的方法,方法唯一的参数就是对应的协议实例,如下方法全名为onPktLoginResult(pkt:MyProtocalCmd)
            //this.addHandlePacket(ID_PACKET, "onPktLoginResult")


            //TODO 添加事件的弱响应的方法,一般是用来驱动刷新当前的ui
            //注意:必须调用MessageControler.addEvent()注册事件名称,否者不会转发到这里
            //参数说明:第一个参数是事件名称
            //        第二个参数是本类public的方法,方法唯一的参数就是MyEvent实例,如下方法全名为onMyEventLoginResult(event:easy.MyEvent)
            //this.addHandleEvent("LOGIN_RESULT", "onMyEventLoginResult");
            this.addHandleEvent(virus.GameData.GET_RANK_LIST, "get_rank_list");//获取排行榜
            //TODO UI层声明的组件,可能会用到,请自行启用
            GameData._bg(this.ui.groupbut1,1);
            //group1
            easy.TweenEffect.setAnchorXY(this.ui.imgall1_4);
            easy.TweenEffect.setAnchorXY(this.ui.imgbut1_5);
            this.ui.group1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTouchGroup, this);
            this.ui.grouptishi.touchEnabled=true;
            this.ui.grouptishi.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTouchGroupTishi, this);
            //group2
            easy.TweenEffect.setAnchorXY(this.ui.imgopen1);
            easy.TweenEffect.setAnchorXY(this.ui.imgopen2);
            GameData._bg(this.ui.imgbg2,1);
            GameData._bg(this.ui.groupbut2,2);
            GameData._bg(this.ui.imgbg3,3);
            easy.TweenEffect.setAnchorXY(this.ui.imgtu2_1,0,1);
            this.ui.imgtu2_1.y=734+easy.GlobalSetting.DISPLAY_HEIGHT-1334+336;
            this.ui.imgtu2_2.y=720+easy.GlobalSetting.DISPLAY_HEIGHT-1334;
            for(var i:number=1;i<4;i++){
                this.ui["imgbtn"+i].data=i;
                easy.TweenEffect.setAnchorXY(this.ui["imgbtn"+i]);
                this.ui["imgbtn"+i].addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBtn1, this);
                this.ui["imgbtn"+i].addEventListener(egret.TouchEvent.TOUCH_END, this.onTouchBtn2, this);
            }
            this.ui.groupbtn4.touchEnabled=true;
            this.ui.imgbut2_6.touchEnabled=true;
            easy.TweenEffect.setAnchorXY(this.ui.imgbut2_6);
            this.ui.imgbut2_6.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTouchtu4, this);
            easy.TweenEffect.setAnchorXY(this.ui.grouptishi2,0.9,1);

            //group3
            easy.TweenEffect.setAnchorXY(this.ui.groupover);
            easy.TweenEffect.setAnchorXY(this.ui.btnover1);
            this.ui.btnover1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTouchBtnOver1, this);
            easy.TweenEffect.setAnchorXY(this.ui.btnover2);
            this.ui.btnover2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTouchBtnOver2, this);
            easy.TweenEffect.setAnchorXY(this.ui.btnclose);
            this.ui.btnclose.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTouchBtnClose, this);

            this.myscrollView1.setContent(this.ui.grouptemp3);
            this.myscrollView1.width=590;
            this.myscrollView1.height=616;
            this.myscrollView1.bounces=true;
            this.myscrollView1.scrollSpeed=0.5;
            this.myscrollView1.verticalScrollPolicy="auto";
            this.ui.grouptemp2.addChild(this.myscrollView1);
            this.myscrollView1.addEventListener(egret.Event.CHANGE,this.scrollChange,this);

            this.ui.imgrank3.touchEnabled=true;
            this.ui.imgrank3.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.startMove, this);
        }
        private myscrollView1:egret.ScrollView=new egret.ScrollView();
        private scrollChange(event:egret.Event):void{
            this.ui.imgrank3.y=370+500*(this.myscrollView1.scrollTop/(this.ui.grouptemp3.height-616));
            if(this.ui.imgrank3.y<370){
                this.ui.imgrank3.y=370;
            }
            if(this.ui.imgrank3.y>870){
                this.ui.imgrank3.y=870;
            }
        }
        private offsetY:number;//设定X坐标偏移量
        private startMove(event:egret.TouchEvent):void {
            this.offsetY = event.stageY - this.ui.imgrank3.y;
            this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onMove, this);
            this.addEventListener(egret.TouchEvent.TOUCH_END, this.stopMove, this);
        }
        private onMove(event:egret.TouchEvent):void{
            this.ui.imgrank3.y = event.stageY - this.offsetY;
            this.myscrollView1.scrollTop=(this.ui.grouptemp3.height-616)*((this.ui.imgrank3.y-370)/500);
            if(this.ui.imgrank3.y<370){
                this.ui.imgrank3.y=370;
            }
            if(this.ui.imgrank3.y>870){
                this.ui.imgrank3.y=870;
            }
            if(this.myscrollView1.scrollTop<0){
                this.myscrollView1.scrollTop=0;
            }
            if(this.myscrollView1.scrollTop>this.ui.grouptemp3.height-616){
                this.myscrollView1.scrollTop=this.ui.grouptemp3.height-616;
            }
        }
        private stopMove(event:egret.TouchEvent):void {
            this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.onMove, this);
            this.removeEventListener(egret.TouchEvent.TOUCH_END, this.stopMove, this);
        }
        private onTouchGroup():void{
            if(window["kaiguan"]){
                if(GameData.oldvirusnum>0){
                    this.gameopen();
                }else{
                    this.ui.grouptishi.visible=true;
                    this.ui.group2.alpha=0;
                    this.ui.group2.visible=true;
                    egret.Tween.get(this.ui.group2).to({alpha:1},500);
                    this.ui.imgtishi1.visible=true;
                    this.ui.imgtishi2.visible=false;
                    this.ui.imgtishi3.visible=false;
                }
            }else{
                this.ui.grouptishi.visible=true;
                this.ui.group2.alpha=0;
                this.ui.group2.visible=true;
                egret.Tween.get(this.ui.group2).to({alpha:1},500);
                this.ui.imgtishi1.visible=true;
                this.ui.imgtishi2.visible=false;
                this.ui.imgtishi3.visible=false;
            }
        }
        private onTouchGroupTishi():void{
            if(this.ui.imgtishi1.visible){
                this.ui.imgtishi1.visible=false;
                this.ui.imgtishi2.visible=true;
            }else if(this.ui.imgtishi2.visible){
                this.ui.imgtishi2.visible=false;
                this.ui.imgtishi3.visible=true;
            }else if(this.ui.imgtishi3.visible){
                this.ui.grouptishi.visible=false;
                this.gameopen();
            }
        }
        //打怪
        private onTouchBtn1(event:egret.TouchEvent):void {
            this.ui["imgbtn"+event.currentTarget.data].texture=this.ui.spriteSheet.getTexture("btn"+event.currentTarget.data+"_2");
        }
        private onTouchBtn2(event:egret.TouchEvent):void {
            egret.Tween.removeTweens(this.ui.imgtu2_1);
            this.ui.imgtu2_1.scaleX=this.ui.imgtu2_1.scaleY=1;
            egret.Tween.get(this.ui.imgtu2_1).to({scaleX:1.1,scaleY:1.1},50).to({scaleX:1,scaleY:1},50,egret.Ease.backOut);
            var data=event.currentTarget.data;
            this.ui["imgbtn"+data].texture=this.ui.spriteSheet.getTexture("btn"+data+"_1");
            var panduan=false;
            for(var i = 0;i < this._tempgame.length;i++){
                if(data==this._tempgame[i]._shuzu[0]){
                    panduan=true;
                    this._tempgame[i]._shuzu.splice(0, 1);
                    this._tempgame[i].ui["grouptemp"+data].visible=false;
                    egret.Tween.removeTweens(this._tempgame[i]);
                    var suiji10 = Math.floor(Math.random() * 5 + 5);
                    egret.Tween.get(this._tempgame[i]).to({x:this._tempgame[i].x+10},30).to({x:this._tempgame[i].x-10},60).to({x:this._tempgame[i].x+10},60).to({x:this._tempgame[i].x},30).wait(200).to({x:70,y:this.ui.imgtu2_1.y+30-336},(easy.GlobalSetting.DISPLAY_HEIGHT-this._tempgame[i].y)*suiji10/(1+GameData._multiple/5));
                }
            }
            for(var i = 0;i < this._tempgame.length;i++){
                if(!this._tempgame[i].ui.grouptemp1.visible && !this._tempgame[i].ui.grouptemp2.visible && !this._tempgame[i].ui.grouptemp3.visible){
                    this._tempgame[i]._isok=false;
                    egret.Tween.removeTweens(this._tempgame[i]);
                    egret.Tween.get(this._tempgame[i]).to({x:this._tempgame[i].x+10},25).to({x:this._tempgame[i].x-10},50).to({x:this._tempgame[i].x+10},50).to({x:this._tempgame[i].x},25).to({alpha:0},50).to({visible:false});
                    if(window["musicstart"])window["audioPlay3"]("siwang1");
                }
            }
            egret.setTimeout(function () {
                for(var i = 0;i < this._tempgame.length;i++){
                    if(!this._tempgame[i].ui.grouptemp1.visible && !this._tempgame[i].ui.grouptemp2.visible && !this._tempgame[i].ui.grouptemp3.visible){
                        this.burst1++;
                        if(this.burst1>=this.burst2*10){
                            this.burst1=this.burst2*10;
                            this.ui.imgbut2_3.visible=false;
                            this.ui.imgbut2_6.visible=true;
                            egret.Tween.get(this.ui.grouptishi2).to({scaleX:1,scaleY:1},500,egret.Ease.backOut);
                        }
                        this.ui.imgbut2_4.y=255-155*(this.burst1/(this.burst2*10));
                        this._tempgame[i].removeFromParent();
                        easy.ObjectPool.recycleClass(this._tempgame[i],"gametemp");
                        this._tempgame.splice(i, 1);
                        i--;
                        GameData.virusnum++;//消灭怪物数量
                        this.ui.labelImg2.text=""+GameData.virusnum;
                    }
                }
            },this,200);
            if(!panduan){
                if(window["musicstart"])window["audioPlay3"]("shibai");
                egret.Tween.removeTweens(this.ui.imgtu2_1);
                this.ui.imgtu2_1.x=0;
                egret.Tween.get(this.ui.imgtu2_1).to({x:30},30).to({x:-30},60).to({x:30},60).to({x:0},30);
                for(var i:number=1;i<4;i++){
                    this.ui["imgbtn"+i].texture=this.ui.spriteSheet.getTexture("btn"+i+"_3");
                }
                egret.Tween.removeTweens(this.ui.imgtu2_2);
                this.ui.imgtu2_2.alpha=0;
                this.ui.imgtu2_2.x=170;
                this.ui.imgtu2_2.y=720+easy.GlobalSetting.DISPLAY_HEIGHT-1334;
                egret.Tween.get(this.ui.imgtu2_2).to({alpha:1,x:170+50,y:720+easy.GlobalSetting.DISPLAY_HEIGHT-1334-50},500).to({alpha:0},500);
                this.ui.groupbtn4.visible=true;
                egret.Tween.get(this.ui.groupbtn4).wait(1000).to({visible:false}).call(function () {
                    for(var i:number=1;i<4;i++){
                        this.ui["imgbtn"+i].texture=this.ui.spriteSheet.getTexture("btn"+i+"_1");
                    }
                },this);
            }else{
                GameData["dinaji"+data]++;
                if(window["musicstart"])window["audioPlay3"]("gongji");
            }

        }
        //爆发
        private onTouchtu4(event:egret.TouchEvent):void {
            if(window["musicstart"])window["audioPlay3"]("dazhao");
            egret.clearInterval(this._time1);
            egret.clearInterval(this.newgame1);
            this.ui.imgbut2_3.visible=true;
            this.ui.imgbut2_6.visible=false;
            this.ui.grouptishi2.scaleX=this.ui.grouptishi2.scaleY=0;
            this.burst1=0;//爆发值
            this.burst2+=1;//爆发次数
            this.ui.imgbut2_4.y=255;
            GameData.virusnum+=this._tempgame.length;//消灭怪物数量
            this.ui.labelImg2.text=""+GameData.virusnum;
            this.ui.imglogo.visible=false;
            this.ui.imglogo1.visible=false;
            this.ui.imglogo1_1.visible=false;
            this.ui.imglogo3.visible=false;
            if(GameData.dinaji1>GameData.dinaji2 && GameData.dinaji1>GameData.dinaji3) {
                this.onTouchtu42(1);
            }
            else if(GameData.dinaji2>GameData.dinaji1 && GameData.dinaji2>GameData.dinaji3) {
                this.onTouchtu42(2);
            }
            else if(GameData.dinaji3>GameData.dinaji1 && GameData.dinaji3>GameData.dinaji2) {
                this.onTouchtu42(3);
            }
            else {
                var suiji10 = Math.floor(Math.random() * 3 + 1);
                this.onTouchtu42(suiji10);
            }
            this.ui.imgbg3.alpha=0;
            egret.Tween.get(this.ui.imgbg3).to({alpha:1},1000).wait(2000).to({alpha:0},1000);
            for(var i = 0;i < this._tempgame.length;i++) {
                this._tempgame[i]._isok = false;
                egret.Tween.removeTweens(this._tempgame[i]);
                egret.Tween.get(this._tempgame[i]).to({x:this._tempgame[i].x+10},25).to({x:this._tempgame[i].x-10},50).to({x:this._tempgame[i].x+10},50).to({x:this._tempgame[i].x},25).to({alpha:0},50).to({visible:false});
                if(window["musicstart"])window["audioPlay3"]("siwang1");
            }
            egret.setTimeout(function () {
                this._tempgame=[];
                this.ui.grouptemp.removeChildren();
                this.ui.imgbg3.texture=null;
                GameData.dinaji1=0;
                GameData.dinaji2=0;
                GameData.dinaji3=0;
                this._time1=egret.setInterval(this._time,this,1000);
                this.newgame1=egret.setInterval(this.newgame,this,2000/(1+GameData._multiple/5));

                this.ui.imglogo.visible=true;
                this.ui.imglogo1.visible=false;
                this.ui.imglogo1_1.visible=false;
                this.ui.imglogo3.visible=false;
            },this,4000);
        }
        private onTouchtu42(_id):void{
            if(_id==1){
                this.ui.imglogo1.visible=true;
                this.ui.imglogo1_1.visible=true;
                this.ui.imgbg3.texture=easy.ResManager.getTexture("bg2_1");
                this.ui.imglogo1.alpha=0;
                egret.Tween.get(this.ui.imglogo1).to({alpha:1},1000).wait(1000).to({alpha:0},1000);
                this.ui.imglogo1_1.alpha=0;
                egret.Tween.get(this.ui.imglogo1_1).to({alpha:1},1000).wait(1000).to({alpha:0},1000);
            }else if(_id==2){
                this.ui.imglogo.visible=true;
                this.ui.imgbg3.texture=easy.ResManager.getTexture("bg2_2");
            }else if(_id==3){
                this.ui.imglogo3.visible=true;
                this.ui.imgbg3.texture=easy.ResManager.getTexture("bg2_3");
                this.ui.imglogo3.alpha=0;
                egret.Tween.get(this.ui.imglogo3).to({alpha:1},1000).wait(1000).to({alpha:0},1000);
            }
        }
        //打开排行榜
        private onTouchBtnOver1(event:egret.TouchEvent):void {
            GameData.get_rank(GameData.virusnum);
        }
        private get_rank_list(event:egret.TouchEvent):void {
            this.myscrollView1.scrollTop=0;
            this.ui.imgrank3.y=370;
            this.ui.imgover2.visible=false;
            this.ui.groupover.visible=false;
            this.ui.grouprank.visible=true;
            this.ui.grouptemp3.removeChildren();
            for(var i:number=0;i<GameData.rankall.length;i++){
                var temptable:virus.temp_rankTemplate = new virus.temp_rankTemplate();
                this.ui.grouptemp3.addChild(temptable);
                temptable.enter();
                temptable.validateNow();
                temptable.name="temptable"+i;
                temptable._rank((i+1),GameData.rankall[i]);
                temptable.y=i*118;
            }
            this.ui.grouptemp3.height=GameData.rankall.length*118;
            this.ui.temp_rank._rank(999,GameData.mydata,1);
            if(this.ui.grouptemp3.height>616){
                this.ui.imgrank3.touchEnabled=true;
                this.ui.imgrank3.visible=true;
            }else{
                this.ui.imgrank3.touchEnabled=false;
                this.ui.imgrank3.visible=false;
            }
        }
        //重新开始游戏
        private onTouchBtnOver2(event:egret.TouchEvent):void {
            this.ui.group3.visible=false;
            this.gameopen();
            egret.Tween.removeTweens(this.ui.group2);
            this.ui.group2.alpha=1;
        }
        //关闭排行榜
        private onTouchBtnClose(event:egret.TouchEvent):void {
            this.ui.imgover2.visible=true;
            this.ui.groupover.visible=true;
            this.ui.grouprank.visible=false;
        }

        /**
         * 进入的逻辑
         * 可以再次根据外部数据情况做一些逻辑处理
         */
        public enter():void {
            super.enter();
            this.reduction();
            this.animation();
            //TODO 在这里写,进入时,初始数据的操作
        }
        //还原
        public burst1=0;//爆发值
        public burst2=1;//爆发次数
        private reduction():void{
            this.ui.group1.visible=true;
            this.ui.group2.visible=false;
            this.ui.group3.visible=false;
            this.ui.imglogo.y=-100;
            this.ui.imgall1_1.alpha=0;
            this.ui.imgall1_1.x=387+50;
            this.ui.imgall1_1.y=125-100;
            this.ui.imgall1_2.alpha=0;
            this.ui.imgall1_2.x=634+100;
            this.ui.imgall1_2.y=89-100;
            this.ui.imgall1_3.alpha=0;
            this.ui.imgall1_3.x=475+200;
            this.ui.imgall1_3.y=186-200;
            this.ui.imgall1_4.scaleX=this.ui.imgall1_4.scaleY=0;
            this.ui.imgall1_5.alpha=0;
            this.ui.imgall1_5.y=569+50;
            this.ui.imgbut1_3.alpha=0;
            this.ui.imgbut1_3.x=-114-300;
            this.ui.imgbut1_3.y=589+600;
            this.ui.imgbut1_5.scaleX=this.ui.imgbut1_5.scaleY=0;
            this.ui.group1.touchEnabled=false;

            this.ui.imglogo.visible=true;
            this.ui.imglogo1.visible=false;
            this.ui.imglogo1_1.visible=false;
            this.ui.imglogo3.visible=false;

            this.ui.grouptishi.visible=false;

            this.ui.group2.alpha=0;
            this.ui.imgbut2_4.mask=this.ui.imgbut2_5;
            this.ui.imgbut2_4.y=255;
            this.ui.grouptishi2.scaleX=this.ui.grouptishi2.scaleY=0;
            this.ui.imgbut2_6.visible=false;
            egret.Tween.get(this.ui.imgbut2_6,{loop:true}).to({scaleX:1.1,scaleY:1.1},1000).to({scaleX:1,scaleY:1},1000);

            this.ui.imgtu2_2.alpha=0;
            GameData.virusnum=0;//消灭怪物数量
            this.ui.labelImg1.text=""+GameData.oldvirusnum;
            this.ui.labelImg2.text=""+GameData.virusnum;
        }
        //动画
        private animation():void{
            egret.Tween.get(this.ui.imglogo).to({y:0},500);
            egret.Tween.get(this.ui.imgall1_1).wait(500).to({alpha:1,x:387,y:125},800);
            egret.Tween.get(this.ui.imgall1_2).wait(1000).to({alpha:1,x:634,y:89},800);
            egret.Tween.get(this.ui.imgall1_3).wait(1500).to({alpha:1,x:475,y:186},800);
            egret.Tween.get(this.ui.imgall1_4).wait(2000).to({scaleX:1,scaleY:1},800,egret.Ease.backOut);
            egret.Tween.get(this.ui.imgall1_5).wait(2500).to({alpha:1,y:569},800);
            egret.Tween.get(this.ui.imgbut1_3).wait(3000).to({alpha:1,x:-114,y:589},800,egret.Ease.backOut);
            egret.Tween.get(this.ui.imgbut1_5).wait(3500).to({scaleX:1,scaleY:1},800,egret.Ease.backOut).call(function () {
                this.ui.group1.touchEnabled=true;
            },this);
        }
        public _time1;//时间记录
        public newgame1;//生成障碍物
        public moveBarrier1;//障碍物移动
        private gameopen():void {
            this.ui.grouptishi.visible=false;
            GameData.beginGame();
            this.ui.group1.touchEnabled=false;
            //清空界面
            this._tempgame=[];
            this.ui.grouptemp.removeChildren();
            //还原数据
            GameData._time10=0;//游戏持续时间
            GameData.virusnum=0;//消灭怪物数量
            GameData._multiple=1;//总倍数
            this.ui.labelImg1.text=""+GameData.oldvirusnum;
            this.ui.labelImg2.text=""+GameData.virusnum;
            this.burst1=0;//爆发值
            this.burst2=1;//爆发次数
            this.ui.imgbg3.texture=null;
            this.ui.imgtu2_2.alpha=0;
            this.ui.imgtu2_2.x=170;
            this.ui.imgtu2_2.y=720;
            this.ui.imgbut2_3.visible=true;
            this.ui.imgbut2_6.visible=false;
            this.ui.imgbut2_4.mask=this.ui.imgbut2_5;
            this.ui.imgbut2_4.y=255;
            for(var i:number=1;i<4;i++){
                this.ui["imgbtn"+i].texture=this.ui.spriteSheet.getTexture("btn"+i+"_1");
            }
            this.ui.groupbtn4.visible=false;
            GameData.dinaji1=0;
            GameData.dinaji2=0;
            GameData.dinaji3=0;
            for(var i:number=1;i<4;i++){
                this.ui["imgbtn"+i].touchEnabled=false;
            }
            this.ui.imgtu2_1.scaleX=this.ui.imgtu2_1.scaleY=1;
            this.ui.imgtu2_1.x=0;
            this.ui.temp_music.visible=true;

            this.ui.group2.visible=true;
            this.ui.imgopen1.alpha=1;
            this.ui.imgopen1.scaleX=this.ui.imgopen1.scaleY=0;
            this.ui.imgopen2.alpha=1;
            this.ui.imgopen2.scaleX=this.ui.imgopen2.scaleY=0;
            this.ui.groupopen.alpha=1;
            this.ui.groupopen.visible=true;
            egret.Tween.get(this.ui.group2).to({alpha:1},500);
            egret.Tween.get(this.ui.imgopen1).wait(500).to({scaleX:1,scaleY:1},500,egret.Ease.backOut).wait(500).to({alpha:0},500);
            egret.Tween.get(this.ui.imgopen2).wait(2000).to({scaleX:1,scaleY:1},500,egret.Ease.backOut).wait(500).to({alpha:0},500);
            egret.Tween.get(this.ui.groupopen).wait(3500).to({alpha:0},500).call(function () {
                this.newgame();
                this._time1=egret.setInterval(this._time,this,1000);
                this.newgame1=egret.setInterval(this.newgame,this,2000);
                this.moveBarrier1=egret.setInterval(this.moveBarrier,this,1);
                for(var i:number=1;i<4;i++){
                    this.ui["imgbtn"+i].touchEnabled=true;
                }
            },this);
        }
        private _time():void {
            GameData._time10++;
            if(Math.floor(GameData._time10/30)>=GameData._multiple){
                GameData._multiple++;
                egret.clearInterval(this.newgame1);
                this.newgame1=egret.setInterval(this.newgame,this,2000/(1+GameData._multiple/5));
            }
        }
        //生成障碍物
        private _tempgame:Array<temp_gameTemplate> = [];//障碍物存储模板
        private newgame():void {
            var temo_game:virus.temp_gameTemplate = easy.ObjectPool.getByClass(temp_gameTemplate, "gametemp");
            this.ui.grouptemp.addChild(temo_game);
            temo_game.validateNow();
            temo_game.visible = true;
            temo_game.alpha=1;
            var suiji = Math.floor(Math.random() * 3 + 1);
            if(suiji==1){
                temo_game._game(2);
                temo_game.x = 0;
                temo_game.y = -184;
            }else if(suiji==2){
                temo_game._game(1);
                temo_game.x = easy.GlobalSetting.DISPLAY_WIDTH;
                temo_game.y = Math.floor(Math.random() * 500);
            }else{
                temo_game._game(1);
                temo_game.x = Math.floor(Math.random() * 500+150);
                temo_game.y = -184;
            }
            this._tempgame.push(temo_game);
            egret.Tween.removeTweens(temo_game);
            var suiji10 = Math.floor(Math.random() * 5 + 5);
            egret.Tween.get(temo_game).to({x:70,y:this.ui.imgtu2_1.y+30-336},(easy.GlobalSetting.DISPLAY_HEIGHT-temo_game.y)*suiji10/(1+GameData._multiple/5));
        }
        //判断病毒是否碰到人物
        private moveBarrier():void {
            for(var i = 0;i < this._tempgame.length;i++){
                if(this.onHit(this._tempgame[i],this.ui.imgtu2_1) && this._tempgame[i]._isok){
                    this._gameover();
                }
            }
        }
        //游戏结束
        public _gameover():void{
            this.ui.temp_music.visible=false;
            if(window["musicstart"])window["audioPlay3"]("jieshu");
            GameData.endGame();
            egret.clearInterval(this._time1);
            egret.clearInterval(this.newgame1);
            egret.clearInterval(this.moveBarrier1);
            for(var i = 0;i < this._tempgame.length;i++){
                egret.Tween.removeTweens(this._tempgame[i]);
            }
            this.ui.groupover.visible=true;
            for(var i:number=1;i<4;i++){
                this.ui["imgbtn"+i].touchEnabled=false;
            }
            this.ui.labelImg3.text=""+GameData.virusnum;
            this.ui.imgover1.alpha=0;
            this.ui.imgover2.alpha=0;
            this.ui.groupover.scaleX=this.ui.groupover.scaleY=0;
            this.ui.grouprank.visible=false;
            egret.Tween.get(this.ui.imgover1).to({alpha:1},500);
            egret.Tween.get(this.ui.imgover2).wait(1500).to({alpha:1},500);
            egret.Tween.get(this.ui.groupover).wait(2000).to({scaleX:1,scaleY:1},500,egret.Ease.backOut);
            this.ui.group3.visible=true;
        }
        /**
         * 碰撞测试
         */
        private _rect1:egret.Rectangle;
        private _rect2:egret.Rectangle;
        private onHit(obj1:egret.DisplayObject,obj2:egret.DisplayObject):boolean{
            if(!this._rect1)this._rect1 = new egret.Rectangle();
            this._rect1.x = obj1.x;
            this._rect1.y = obj1.y;
            this._rect1.width =obj1.width;
            this._rect1.height =obj1.height;
            if(!this._rect2)this._rect2 = new egret.Rectangle();
            this._rect2.x = obj2.x-90;
            this._rect2.y = obj2.y+90-336;
            this._rect2.width = obj2.width;
            this._rect2.height = obj2.height;
            return this._rect1.intersects(this._rect2);
        }
        
        /**
         * enter的过渡效果
         */
        public enterTransition():void {
            super.enterTransition();
            //TODO 可以覆盖这里,写自己想要的enter效果
        }

        /**
         * 退出的逻辑
         * 做一些数据的销毁或者初始化,保证下次进入的时候,不会残留
         */
        public outer():void {
            super.outer();
            //TODO 在这里写,退出时,清理数据的操作
        }
        
        /**
         * outer的过渡效果
         */
        public outerTransition():void {
            super.outerTransition();
            //TODO 可以覆盖这里,写自己想要的out效果
        }
        
        /**
         * 通过ResManager.getTexture(url)触发下载的url资源,会通知到当前显示的view中的onMyEventResDownloaded方法
         * 参数myevent携带两个数据
         *    url:完成加载的url
         *    data:完成加载的数据内容
         * 可以通过ResManager.getTexture(url),再次取到data数据
         * @param event
         */
        //public onMyEventResDownloaded(myevent:easy.MyEvent):void {
             //TODO 当前view动态加载的资源,请在这里添加刷新逻辑
        //}

        /**
         * View自身的材质,首次下载完成会调用加载一次,刷新UI皮肤显示
         * 使用了框架的UI机制,单ui的资源下载完成会调用改方法刷新
         * 若view中有逻辑使用到ui的素材,应该在这里做素材的赋值
         */
        public validateNow():void{
            super.validateNow();
            //TODO 初始特殊的素材资源,需要调用可以写在这里
            //if (this.ui && this.ui.spriteSheet) {
            //
            //}
        }
    }
}