module.exports = { // 初始化配置 initConfig:function() { // 公共的 this.name = "我的名字" // 判断是否登录状态 this.login = false // 判断是展示好友排行还是群排行,1为好友排行,2为群排行 // 判断是否刚刚打开游戏 this.firstOpen = true // 记录得分 this.score = 0; // 是否无限模式 this.infiMode = false; var best = cc.sys.localStorage.getItem("save_best_score"); // 设置最高分数 if (best == null || best == "") { this.bestscore = 0 } else { this.bestscore = parseInt (best) } best = cc.sys.localStorage.getItem("save_best_time"); // 设置最高时间 if (best == null || best == "") { this.besttime = 0; } else { this.besttime = parseInt (best); } console.log ("最高时间 = " + this.besttime + ", 最高分 = " + this.bestscore); }, // 外部调用 // 保存最高分 saveBestScore:function() { // 如果传入的分数大于之前保存的最高分,则保存 if (this.score > this.bestscore) { this.bestscore = this.score; cc.sys.localStorage.setItem("save_best_score", this.bestscore.toString()) } }, // 保存最长时间 saveBestTime:function() { // 如果传入的分数大于之前保存的最高时间,则保存 if (this.score > this.besttime) { this.besttime = this.score; cc.sys.localStorage.setItem("save_best_time", this.besttime.toString()) } } }; require("global").initConfig()