UserMgr.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Node, Prefab, _decorator, assetManager, find, instantiate, sys } from 'cc';
  2. import { UserModel } from '../Model/UserModel';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('UserManager')
  5. export class UserManager {
  6. private static _instance: UserManager | null = null;
  7. public static get instance(): UserManager {
  8. if (!this._instance) this._instance = new UserManager();
  9. return this._instance;
  10. }
  11. public userModel: UserModel = null;
  12. initilizeModel(): void {
  13. this.userModel = new UserModel();
  14. this.userModel.initialize();
  15. }
  16. /**
  17. * 增加体力
  18. * @param value 增加的数量
  19. * @returns 增加后的体力值
  20. */
  21. public addPower(value: number): number {
  22. this.userModel.powerCurrent = Math.min(this.userModel.powerCurrent + value, this.userModel.powerMax);
  23. return this.userModel.powerCurrent;
  24. }
  25. /**
  26. * 减少体力
  27. * @param value 减少的数量
  28. * @returns 是否成功减少
  29. */
  30. public reducePower(value: number): boolean {
  31. if (this.userModel.powerCurrent >= value) {
  32. this.userModel.powerCurrent -= value;
  33. return true;
  34. }
  35. return false;
  36. }
  37. }