GameOverMediator.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { _decorator, Component, Node, LabelComponent } from 'cc';
  2. import { GUIManager } from '../../../engines/gui/GUIManager';
  3. import { GUIMediator } from '../../../engines/gui/GUIMediator';
  4. import { NoticeManager } from '../../../engines/notices/NoticeManager';
  5. import { SceneManager } from '../../../engines/scenes/SceneManager';
  6. import { PlatformManager } from '../../../Platform/PlatformManager';
  7. import GameConfigManager from '../../models/GameConfigManager';
  8. import { GameModel } from '../../models/GameModel';
  9. import { GameController } from '../fightings/GameController';
  10. import { UIConst } from '../UIConst';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('GameOverMediator')
  13. export class GameOverMediator extends GUIMediator {
  14. @property(Node)
  15. WinGroup: Node = null;
  16. @property({
  17. type: LabelComponent
  18. })
  19. WinAwardLabel: LabelComponent = null;
  20. @property(Node)
  21. DefeatedGroup: Node = null;
  22. private isWin: boolean;
  23. private award: number;
  24. onLoad() {
  25. PlatformManager.showBanner()
  26. }
  27. OnShow(data?: any): void {
  28. super.OnShow(data);
  29. this.isWin = data;
  30. this.WinGroup.active = this.isWin;
  31. this.DefeatedGroup.active = !this.isWin;
  32. //胜利
  33. if (this.isWin == true) {
  34. this.WinGroup.active = true;
  35. this.DefeatedGroup.active = false;
  36. let levelConfig: any = GameConfigManager.GetLevelConfig(GameModel.single.currentLevel - 1);
  37. //关卡基础奖励
  38. this.award = levelConfig.awards + levelConfig.killAward * GameModel.single.killCount;
  39. this.WinAwardLabel.string = this.award.toString();
  40. } else {//失败
  41. //失败不算奖励
  42. this.WinGroup.active = false;
  43. this.DefeatedGroup.active = true;
  44. }
  45. }
  46. /**
  47. * 开始下一关
  48. */
  49. PlayNextLevel(): void {
  50. this.AddAward();
  51. this.HideSelf();
  52. GameController.single.PlayNextLevel();
  53. }
  54. /**
  55. * 重玩
  56. */
  57. Replay(): void {
  58. PlatformManager.showRewardedVideo(() => {
  59. PlatformManager.hideBanner();
  60. this.AddAward();
  61. this.HideSelf();
  62. GameController.single.Replay();
  63. }, () => {
  64. NoticeManager.ShowPrompt("复活失败");
  65. })
  66. }
  67. /**
  68. * 返回主界面
  69. */
  70. BackToMain(): void {
  71. this.AddAward();
  72. SceneManager.single.Swicth("PrepareScene");
  73. GUIManager.single.Hide(UIConst.FIGHTING_UI);
  74. //关闭自身
  75. this.HideSelf();
  76. }
  77. /**
  78. * 去全屏幕界面
  79. */
  80. GoToFullOutput(): void {
  81. this.AddAward();
  82. GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
  83. this.HideSelf();
  84. }
  85. /**
  86. * 十倍之后去全屏界面
  87. */
  88. getTenAward():void{
  89. this.AddAdAward(10, ()=>{
  90. GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
  91. this.HideSelf();
  92. });
  93. }
  94. /**
  95. * 十倍奖励
  96. * @param value
  97. */
  98. private AddAdAward(value: number = 1, success): void {
  99. if (this.isWin) {
  100. PlatformManager.showRewardedVideo(() => {
  101. GameModel.single.gold += this.award * value;
  102. success();
  103. }, () => {
  104. NoticeManager.ShowPrompt("领取失败");
  105. })
  106. }
  107. }
  108. /**
  109. * 获取奖励
  110. */
  111. private AddAward(value: number = 1): void {
  112. if (this.isWin) {
  113. GameModel.single.gold += this.award * value;
  114. }
  115. }
  116. OnHide(): void {
  117. }
  118. }