module virus {
    import MD5 = easy.MD5;
    export class GameData {
        public static _bg(bg,id):void{
            if(id==1){
                easy.TweenEffect.setAnchorXY(bg,0.5,1);
                bg.x=easy.GlobalSetting.DISPLAY_WIDTH/2;
                bg.y=easy.GlobalSetting.DISPLAY_HEIGHT;
                bg.scaleX=bg.scaleY=easy.GlobalSetting.DISPLAY_WIDTH/750;
            }else if(id==2){
                easy.TweenEffect.setAnchorXY(bg,0.5,1);
                bg.x=easy.GlobalSetting.DISPLAY_WIDTH/2;
                bg.y=easy.GlobalSetting.DISPLAY_HEIGHT;
                bg.scaleX=bg.scaleY=easy.GlobalSetting.DISPLAY_WIDTH/750;
            }else if(id==3){
                easy.TweenEffect.setAnchorXY(bg,0.5,1);
                bg.x=easy.GlobalSetting.DISPLAY_WIDTH/2;
                if(easy.GlobalSetting.DISPLAY_HEIGHT>1334){
                    bg.y=1334*easy.GlobalSetting.DISPLAY_WIDTH/750;
                }else{
                    bg.y=easy.GlobalSetting.DISPLAY_HEIGHT;
                }
                bg.scaleX=bg.scaleY=easy.GlobalSetting.DISPLAY_WIDTH/750;
            }
        }
        public static _multiple:number=1;//总倍数
        public static _time10:number=0;//游戏持续时间
        public static virusnum:number=0;//消灭怪物数量
        public static oldvirusnum:number=0;//最好的旧成绩
        public static dinaji1=0;
        public static dinaji2=0;
        public static dinaji3=0;

        public static _random_str:string="";
        public static _const_str = "meisujiaer";

        public static _url="http://www.jiyou-tech.com/2020/506/src/";
        //开始游戏
        public static beginGame():void{
            easy.HttpUtil.getData(GameData._url+"beginGame.php","",this.beginGamerply,this);
        }
        public static beginGamerply(str):void{
            var json=JSON.parse(str);
            console.log(json);
            if(json["code"]==200){
                GameData._random_str=json["token"];
            }else{
                GameData.oldvirusnum=0;
            }
        }
        //提交成绩
        public static md5=new MD5();
        public static endGame():void{
            var sign = this.md5.hex_md5(GameData._random_str+GameData._const_str+GameData.virusnum);
            var parm="score="+GameData.virusnum+"&sign="+sign;
            easy.HttpUtil.postData(GameData._url+"endGame.php",parm,this.endGamerply,this);
        }
        public static endGamerply(str):void{
            var json=JSON.parse(str);
            console.log(json);
        }
        //获取排行榜
        public static get_rank(_virusnum):void{
            var parm="score="+_virusnum;
            easy.HttpUtil.getData(GameData._url+"rank.php",parm,this.get_rankrply,this);
        }
        public static GET_RANK_LIST:string = "get_rank_list";//获取排行榜
        public static rankall=[];
        public static mydata=0;//我的排行
        public static get_rankrply(str):void{
            var json=JSON.parse(str);
            console.log(json);
            if(json["code"]==200){
                GameData.rankall=json["rankData"];
                GameData.mydata=json["myData"];
                if(json["myData"]){
                    GameData.oldvirusnum=json["myData"]["score"];
                }else{
                    GameData.oldvirusnum=0;
                }
                easy.MyEvent.sendEvent(virus.GameData.GET_RANK_LIST);
            }else{
                easy.MessageTips.showMessage(""+json["msg"]);
            }
        }
    }
}
