Top.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { EventManager } from './EventManager';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('Top')
  5. export class Top extends Component {
  6. @property(Label)
  7. haertLabel: Label = null;
  8. @property(Label)
  9. ScoreLabel: Label = null;
  10. protected onLoad(): void {
  11. EventManager.instance.et.on(EventManager.EventType.Add_haert, this.Add_haert, this);
  12. EventManager.instance.et.on(EventManager.EventType.Cut_haert, this.Cut_haert, this);
  13. EventManager.instance.et.on(EventManager.EventType.Add_Score, this.Add_Score, this);
  14. EventManager.instance.et.on(EventManager.EventType.Set_Add_Score_BOOL, this.Set_Add_Score_BOOL, this);
  15. EventManager.instance.et.on(EventManager.EventType.Reset_Score, this.Reset_Score, this);
  16. }
  17. Cut_haert() {
  18. if (parseInt(this.haertLabel.string) > 0) {
  19. this.haertLabel.string = (parseInt(this.haertLabel.string) - 1) + "";
  20. EventManager.instance.et.emit(EventManager.EventType.Reset_Role);
  21. } else {
  22. //死了
  23. console.error('死了');
  24. EventManager.instance.et.emit(EventManager.EventType.Set_Add_Score_BOOL, false);
  25. EventManager.instance.et.emit(EventManager.EventType.Die_Role);
  26. EventManager.instance.et.emit(EventManager.EventType.OpenUIPnael);
  27. }
  28. }
  29. protected start(): void {
  30. EventManager.instance.et.emit(EventManager.EventType.Reset_Score);
  31. }
  32. Add_haert(num: number) {
  33. if (parseInt(this.haertLabel.string) < 3) {
  34. this.haertLabel.string = (parseInt(this.haertLabel.string) + 1) + "";
  35. }
  36. if (num) {
  37. this.haertLabel.string = num + "";
  38. }
  39. }
  40. Add_Score_Bool = true
  41. Add_Score() {
  42. if (this.Add_Score_Bool) {
  43. this.ScoreLabel.string = (parseInt(this.ScoreLabel.string) + 10) + "";
  44. }
  45. }
  46. Set_Add_Score_BOOL(b: boolean) {
  47. this.Add_Score_Bool = b
  48. }
  49. Reset_Score() {
  50. this.ScoreLabel.string = '0'
  51. }
  52. }