LevelModel.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { JsonUtil } from "db://assets/core_tgx/base/utils/JsonUtil";
  2. import { Tablelevels_config } from "../../../module_basic/table/Tablelevels_config";
  3. import { Tablemain_config } from "../../../module_basic/table/Tablemain_config";
  4. import { GlobalConfig } from "../../../start/Config/GlobalConfig";
  5. import { sys } from "cc";
  6. import { CarCarColorsSysterm } from "../Systems/CarCarColorsSysterm";
  7. import { CarColorsGlobalInstance } from "../CarColorsGlobalInstance";
  8. /**道具类型
  9. * @param REVOKE 撤销
  10. * @param ADDNUT 增加螺丝
  11. */
  12. export enum TYPE_ITEM {
  13. REVOKE = 1,
  14. ADDNUT = 2,
  15. }
  16. export enum TYPE_GAME_STATE {
  17. GAME_STATE_INIT = 0, //准备阶段
  18. GAME_STATE_START = 1, //开始
  19. GAME_STATE_END = 2, //结束(倒计时结束)
  20. GAME_STATE_RESULT = 3, //结算
  21. GAME_STATE_PAUSE = 4, //暂停
  22. }
  23. /**关卡数据模型
  24. */
  25. export class LevelModel {
  26. public levelConfig: Tablelevels_config;
  27. /** 当前关卡等级*/
  28. public level: number = 1;
  29. /** 每关星星结算*/
  30. public star: number = 3;
  31. /** 储存每关星星结算*/
  32. public levelStarsMap: Map<number, number> = new Map<number, number>();
  33. /** 保存可随机的关卡*/
  34. public randomLevelList: number[] = [];
  35. /** 输赢*/
  36. public isWin: boolean = false;
  37. /** 是否结束*/
  38. public isEnd: boolean = false;
  39. /** 当前游戏状态*/
  40. public curGameState: TYPE_GAME_STATE = TYPE_GAME_STATE.GAME_STATE_INIT;
  41. constructor() {
  42. this.levelConfig = new Tablelevels_config();
  43. this.getRandomLevelList();
  44. const isDebug = GlobalConfig.isDebug;
  45. if (isDebug) {
  46. this.level = GlobalConfig.initilizeLevel;
  47. } else {
  48. const level = sys.localStorage.getItem('level');
  49. if (!level) {
  50. this.level = 1;
  51. } else {
  52. if (level > GlobalConfig.levelTotal) {
  53. const randomLevel = this.randomLevelList[Math.floor(Math.random() * this.randomLevelList.length - 1)];
  54. this.level = randomLevel;
  55. } else {
  56. this.level = parseInt(level);
  57. }
  58. }
  59. };
  60. this.levelConfig.init(this.level);
  61. }
  62. /** 可随机的关卡合集*/
  63. getRandomLevelList() {
  64. const table = JsonUtil.get(Tablelevels_config.TableName);
  65. if (!table) {
  66. console.warn('Get level table is fail!');
  67. }
  68. this.randomLevelList = Object.values(table).filter(item => item['random'] == 1)
  69. .map(item => item['level']);
  70. // console.log('随机关卡列表:', this.randomLevelList);
  71. }
  72. /** 清除关卡数据*/
  73. clearLevel() {
  74. CarColorsGlobalInstance.instance.carSysterm.clearAll();
  75. this.isWin = false;
  76. this.isEnd = false;
  77. this.star = 3;
  78. }
  79. }