import GameData from "../GameData"; import { StorageMessage } from "./Storage"; //最大工具类 var GameTool = { _startTime: 0, _endTime: 0, _totalTime: 0, getSeedRandom: function (min, max) {//包含min 不包含max max = max || 1; min = min || 0; GameData._instance.GM_INFO.currSeed = (GameData._instance.GM_INFO.currSeed * 9301 + 49297) % 233280; let rnd = GameData._instance.GM_INFO.currSeed / 233280.0; let tmp = min + rnd * (max - min); return Math.floor(tmp); }, getSetScreenResolutionFlag: function () { let size = cc.winSize; let width = size.width; let height = size.height; if ((height / width) > (16.2 / 9)) return false; return true; }, //判断全面屏适配 setFit: function (canvas) { let flag = GameTool.getSetScreenResolutionFlag(); if (flag) { // console.log("不是全面屏"); // canvas.fitWidth = false; // canvas.fitHeight = true; } else { // console.log("是全面屏"); // canvas.fitWidth = true; // canvas.fitHeight = false; } return flag; }, getTip: function () { let index = Math.floor(Math.random() * 4) + 1; switch (index) { case 1: { return "根据小球的位置,合理晃动手机,确保小球不掉出木板。" } case 2: { return "根据小球位置控制晃动幅度,过大或过小都不是个好选择。" } case 3: { return "不要被天上掉落的障碍吓到,有时候它反而会帮你保持平衡。" } case 4: { return "尝试着顶开掉落的障碍,是个很酷的玩法。" } } }, beginTiming: function () { this._startTime = new Date().getTime(); }, endTiming: function () { this._endTime = new Date().getTime(); // this._totalTime = endTime - this._startTime; }, //如果是判断时常的游戏 调用此方法 updateScoreTime: function () { let endTime = new Date().getTime(); let tempTime = endTime - this._startTime; if (tempTime < 0 || tempTime > 500) { tempTime = Math.round(cc.director.getAnimationInterval() * 1000); } this._endTime += tempTime / 1000; this._totalTime = this._endTime.toFixed(2); GameData._instance.GM_INFO.currScore = this._totalTime; this._startTime = endTime; }, //倒计时调用此方法 countDown: function () { this._endTime = new Date().getTime(); this._totalTime = Math.floor((this._endTime - this._startTime) / 1000); GameData._instance.GM_INFO.remainingTime = GameData._instance.GM_INFO.totalTime - this._totalTime; }, getGameInfo: function(node){ var jg = false; return jg; }, //根据服务器数据重置所需要所有数据 reset: function(){ console.log("本地数据丢失,重新启动游戏"); cc.director.loadScene('LoadScene'); }, setGameInfo: function(pd){ }, //输入秒,返回需要展示时间格式 getTimeMargin:(second) => { let total = second; let hour = Math.floor(total / (60 * 60));//计算整数小时数 let afterHour = total - hour * 60 * 60;//取得算出小时数后剩余的秒数 let min = Math.floor(afterHour / 60);//计算整数分 let afterMin = total - hour * 60 * 60 - min * 60;//取得算出分后剩余的秒数 return '剩余:' + hour + ':' + min + ':' + afterMin }, getTimeMargin2:(second) => { let total = second; let min = null; let afterMin = null; let hour = Math.floor(total / (60 * 60));//计算整数小时数 let afterHour = total - hour * 60 * 60;//取得算出小时数后剩余的秒数 min = Math.floor(afterHour / 60);//计算整数分 if(min < 10) min = "0"+min; afterMin = total - hour * 60 * 60 - min * 60;//取得算出分后剩余的秒数 if(afterMin < 10) afterMin = "0" + afterMin; return '剩余:' + min + ':' + afterMin }, setFrindBlock: function(userid){ }, //将时间转换为59:23 getTime: function(time){ var label = ""; var number_1 = null; var number_2 = null; number_1 = Math.floor(time/60) number_2 = time-number_1*60; if(number_1 < 10){ number_1 = "0"+number_1; } if(number_2 < 10){ number_2 = "0"+number_2; } label = number_1 + ":" + number_2; return label; }, //number 为传进来的数值,type为最多显示几位数 getNumber: function(number,type){ // console.log(type,"需要转换的数字为:",number); var count = 1000; var place = type - 3; if(number > Math.pow(count,8)*Math.pow(10,place)){ if(number/Math.pow(count,8) < 100) number = Math.floor(number/Math.pow(count,8)*10)/10+"S"; else number = Math.floor(number/Math.pow(count,8))+"S"; } else if(number > Math.pow(count,7)*Math.pow(10,place)){ if(number/Math.pow(count,7) < 100) number = Math.floor(number/Math.pow(count,7)*10)/10+"s"; else number = Math.floor(number/Math.pow(count,7))+"s"; } else if(number > Math.pow(count,6)*Math.pow(10,place)){ if(number/Math.pow(count,6) < 100) number = Math.floor(number/Math.pow(count,6)*10)/10+"Q"; else number = Math.floor(number/Math.pow(count,6))+"Q"; } else if(number > Math.pow(count,5)*Math.pow(10,place)){ if(number/Math.pow(count,5) < 100) number = Math.floor(number/Math.pow(count,5)*10)/10+"q"; else number = Math.floor(number/Math.pow(count,5))+"q"; } else if(number > Math.pow(count,4)*Math.pow(10,place)){ if(number/Math.pow(count,4) < 100) number = Math.floor(number/Math.pow(count,4)*10)/10+"t"; else number = Math.floor(number/Math.pow(count,4))+"t"; } else if(number > Math.pow(count,3)*Math.pow(10,place)){ if(number/Math.pow(count,3) < 100) number = Math.floor(number/Math.pow(count,3)*10)/10+"b"; else number = Math.floor(number/Math.pow(count,3))+"b"; } else if(number > Math.pow(count,2)*Math.pow(10,place)){ if(number/Math.pow(count,2) < 100) number = Math.floor(number/Math.pow(count,2)*10)/10+"m"; else number = Math.floor(number/Math.pow(count,2))+"m"; } else if(number > Math.pow(count,1)*Math.pow(10,place)){ if(number/Math.pow(count,1) < 100){ number = Math.floor(number/Math.pow(count,1)*10)/10+"k"; } else number = Math.floor(number/Math.pow(count,1))+"k"; } else{ number = Math.floor(number/Math.pow(count,0))+""; } // console.log("结果为"+type+"位数",number); return number; }, begainTiming: function () { this._startTime = new Date().getTime(); }, endTiming2: function () { let endTime = new Date().getTime(); this._endTime = endTime; this._totalTime = endTime - this._startTime; }, getScoreTime: function () { let endTime = new Date().getTime(); let tempTime = endTime - this._startTime; if (tempTime < 0 || tempTime > 500) { tempTime = Math.round(cc.director.getAnimationInterval() * 1000); } GameData._instance.GM_INFO.currScore += tempTime; this._startTime = endTime; }, getFormatTime: function (time) { let date = new Date(); date.setTime(time); let ms = date.getMilliseconds(); // let msString = date.getMilliseconds(); let msString = null; let secondString = null; let minString = null; msString = Math.floor(ms / 10) % 100; secondString = date.getSeconds(); minString = date.getMinutes(); if (msString < 10) { msString = "0" + msString; } if (secondString < 10) { secondString = "0" + secondString; } secondString = secondString + ":"; if (minString < 10) { minString = "0" + minString; } minString = minString + ":"; return minString + secondString + msString; }, pushLister:function () { }, removeAllLister:function () { }, }; export { GameTool };