GameOver.ts 5.3 KB

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