GameEndTip.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
  2. import { GameManager } from '../Manager/GameManager';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('GameEndTip')
  5. export class GameEndTip extends Component {
  6. @property(SpriteFrame)
  7. successBg: SpriteFrame = null;
  8. @property(SpriteFrame)
  9. failBg: SpriteFrame = null;
  10. @property(Label)
  11. curLevelLabel: Label = null;
  12. @property(Label)
  13. curScoreLabel: Label = null;
  14. @property(Label)
  15. totalScoreLabel: Label = null;
  16. @property(Label)
  17. btnLabel: Label = null;
  18. @property(Node)
  19. reusltIcon: Node = null;
  20. result: boolean = false;
  21. start() {
  22. }
  23. showEndView(curLevel: number, curScore: number, totalScore: number, result: boolean, isTime: boolean) {
  24. if (result) {
  25. this.reusltIcon.getComponent(Sprite).spriteFrame = this.successBg;
  26. this.btnLabel.string = '下一关';
  27. } else {
  28. this.reusltIcon.getComponent(Sprite).spriteFrame = this.failBg;
  29. this.btnLabel.string = '继续';
  30. }
  31. this.result = result;
  32. if (isTime) {
  33. this.curLevelLabel.string = '超时游戏失败';
  34. } else {
  35. this.curLevelLabel.string = '当前关卡: 第' + curLevel + '关';
  36. }
  37. this.curScoreLabel.string = '本关得分: ' + curScore;
  38. this.totalScoreLabel.string = '总得分: ' + totalScore;
  39. console.log('curLevel:' + curLevel);
  40. }
  41. backHomeBtn() {
  42. this.node.active = false;
  43. // GameManager.getInstance().BackHomePage();
  44. }
  45. levelBtn() {
  46. this.node.active = false;
  47. if (this.result) {
  48. GameManager.getInstance().NextLevel();
  49. } else {
  50. GameManager.getInstance().RestartGame();
  51. }
  52. }
  53. }