Top.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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() {
  33. this.haertLabel.string = (parseInt(this.haertLabel.string) + 1) + "";
  34. }
  35. Add_Score_Bool = true
  36. Add_Score() {
  37. if (this.Add_Score_Bool) {
  38. this.ScoreLabel.string = (parseInt(this.ScoreLabel.string) + 1) + "";
  39. }
  40. }
  41. Set_Add_Score_BOOL(b: boolean) {
  42. this.Add_Score_Bool = b
  43. }
  44. Reset_Score() {
  45. this.ScoreLabel.string = '0'
  46. }
  47. }