GameOver.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { _decorator, director, Label } from 'cc';
  2. import { UIBase } from '../../GameFrameWork/UIBase';
  3. import { resMgr } from '../../../Frames/ResourcesMgr';
  4. import { GameOverData } from './Data/GameOverData';
  5. import { UIMgr } from '../../../Frames/UIManager';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('GameOver')
  8. export class GameOver extends UIBase {
  9. // //是否胜利
  10. // win: boolean = null;
  11. // killCount: number = null;
  12. // killPercent: number = null;
  13. // //金币奖励
  14. // killAward: number = null;
  15. // lifeAward: number = null;
  16. // stageClearAward: number = null;
  17. // totalAward: number = null;
  18. // //经验奖励
  19. // xp: number = null;
  20. // //钻石奖励
  21. // lifeDia: number = null;
  22. // stageClearDia: number = null;
  23. // totalDia: number = null;
  24. gameOverDt: GameOverData = null;
  25. protected onStart() {
  26. this.gameOverDt = GameOverData.Instance;
  27. this.onBtnClick("_btnLeft", this._onBtnBack);
  28. this._calculatedReward();
  29. this._config();
  30. }
  31. // config() {
  32. // this.getSprite("_gameOverUITitle").spriteFrame = this.win ?
  33. // resMgr.getSpriteFrame("GameWin") :
  34. // resMgr.getSpriteFrame("GameOver");
  35. // this.getLabel("_labelRight").string = this.win ? "下一关" : "重新开始";
  36. // const labelDate = {
  37. // "_killCount":this.killCount,
  38. // "_lifePercent":`${this.killPercent} %`,
  39. // "_kill":this.killAward,
  40. // "_life":this.lifeAward,
  41. // "_stageClear":this.stageClearAward,
  42. // "_total":this.totalAward,
  43. // "_xp":this.xp,
  44. // "_lifeDia":this.lifeDia,
  45. // "_stageClearDia":this.stageClearDia,
  46. // "_totalDia":this.totalDia,
  47. // }
  48. // this._setLabels(labelDate);
  49. // // this.getLabel("_killCount").string = String(this.killCount);
  50. // // this.getLabel("_lifePercent").string = `${String(this.killPercent)} %`;
  51. // // this.getLabel("_kill").string = String(this.killAward);
  52. // // this.getLabel("_life").string = String(this.lifeAward);
  53. // // this.getLabel("_stageClear").string = String(this.stageClearAward);
  54. // // this.getLabel("_total").string = String(this.totalAward);
  55. // // this.getLabel("_xp").string = String(this.xp);
  56. // // this.getLabel("_lifeDia").string = String(this.lifeDia);
  57. // // this.getLabel("_stageClearDia").string = String(this.stageClearDia);
  58. // // this.getLabel("_totalDia").string = String(this.totalDia);
  59. // }
  60. // private _setLabels(labelDate){
  61. // for(const [labelName, value] of labelDate){
  62. // this.getLabel(labelName).string = String(value);
  63. // }
  64. // }
  65. private _calculatedReward() {
  66. if (this.gameOverDt.KillCount >= 20) {
  67. this.gameOverDt.KillAward = 100;
  68. this.gameOverDt.Xp = 30;
  69. } else if (this.gameOverDt.KillCount < 20) {
  70. this.gameOverDt.KillAward = 50;
  71. this.gameOverDt.Xp = 15;
  72. }
  73. if (this.gameOverDt.LifePercent === 100) {
  74. this.gameOverDt.LifeAward = 40;
  75. this.gameOverDt.LifeDia = 10;
  76. } else if (this.gameOverDt.LifePercent >= 50 && this.gameOverDt.LifePercent < 100) {
  77. this.gameOverDt.LifeAward = 30;
  78. this.gameOverDt.LifeDia = 6;
  79. } else if (this.gameOverDt.LifePercent >= 0 && this.gameOverDt.LifePercent < 50) {
  80. this.gameOverDt.LifeAward = 20;
  81. this.gameOverDt.LifeDia = 2;
  82. }
  83. // if(this.gameOverDt.Win){
  84. // this.gameOverDt.StageClearDia = 10;
  85. // } else {
  86. // this.gameOverDt.StageClearDia = 2;
  87. // }
  88. this.gameOverDt.StageClearDia = this.gameOverDt.Win ? 10 : 2;
  89. this.gameOverDt.TotalAward = this.gameOverDt.KillAward + this.gameOverDt.LifeAward;
  90. this.gameOverDt.TotalDia = this.gameOverDt.LifeDia + this.gameOverDt.StageClearDia;
  91. }
  92. private _config() {
  93. this.getSprite("_gameOverUITitle").spriteFrame = this.gameOverDt.Win ?
  94. resMgr.getSpriteFrame("GameWin") : resMgr.getSpriteFrame("GameOver");
  95. this.getNode("_btnRight").getChildByName("Label").getComponent(Label).string =
  96. this.gameOverDt.Win ? "下一关" : "重新开始";
  97. const labelData = new Map<string, number | string>();
  98. labelData.set("_killCount", this.gameOverDt.KillCount);
  99. labelData.set("_lifePercent", `${this.gameOverDt.LifePercent} %`);
  100. labelData.set("_kill", this.gameOverDt.KillAward);
  101. labelData.set("_life", this.gameOverDt.LifeAward);
  102. //通关奖励:StageClearAward
  103. labelData.set("_stageClear", this.gameOverDt.StageClearAward);
  104. labelData.set("_total", this.gameOverDt.TotalAward);
  105. labelData.set("_xp", this.gameOverDt.Xp);
  106. labelData.set("_lifeDia", this.gameOverDt.LifeDia);
  107. labelData.set("_stageClearDia", this.gameOverDt.StageClearDia);
  108. labelData.set("_totalDia", this.gameOverDt.TotalDia);
  109. this._setLabels(labelData);
  110. }
  111. private _setLabels(labelData: Map<string, number | string>) {
  112. for (const [labelName, value] of labelData.entries()) {
  113. this.getLabel(labelName).string = String(value);
  114. }
  115. }
  116. private _onBtnBack() {
  117. //销毁
  118. this.gameOverDt.clearData();
  119. UIMgr.closeUI("GameOver");
  120. director.loadScene("StartScene");
  121. }
  122. }