global.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. module.exports = {
  2. // 初始化配置
  3. initConfig:function() {
  4. // 公共的
  5. this.name = "我的名字"
  6. // 判断是否登录状态
  7. this.login = false
  8. // 判断是展示好友排行还是群排行,1为好友排行,2为群排行
  9. // 判断是否刚刚打开游戏
  10. this.firstOpen = true
  11. // 记录得分
  12. this.score = 0;
  13. // 是否无限模式
  14. this.infiMode = false;
  15. var best = cc.sys.localStorage.getItem("save_best_score");
  16. // 设置最高分数
  17. if (best == null || best == "") {
  18. this.bestscore = 0
  19. } else {
  20. this.bestscore = parseInt (best)
  21. }
  22. best = cc.sys.localStorage.getItem("save_best_time");
  23. // 设置最高时间
  24. if (best == null || best == "") {
  25. this.besttime = 0;
  26. } else {
  27. this.besttime = parseInt (best);
  28. }
  29. console.log ("最高时间 = " + this.besttime + ", 最高分 = " + this.bestscore);
  30. },
  31. // 外部调用
  32. // 保存最高分
  33. saveBestScore:function() {
  34. // 如果传入的分数大于之前保存的最高分,则保存
  35. if (this.score > this.bestscore) {
  36. this.bestscore = this.score;
  37. cc.sys.localStorage.setItem("save_best_score", this.bestscore.toString())
  38. }
  39. },
  40. // 保存最长时间
  41. saveBestTime:function() {
  42. // 如果传入的分数大于之前保存的最高时间,则保存
  43. if (this.score > this.besttime) {
  44. this.besttime = this.score;
  45. cc.sys.localStorage.setItem("save_best_time", this.besttime.toString())
  46. }
  47. }
  48. };
  49. require("global").initConfig()