GameOverMediator.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { _decorator, Component, Node, LabelComponent } from 'cc';
  2. import { GUIManager } from '../../../engines/gui/GUIManager';
  3. import { GUIMediator } from '../../../engines/gui/GUIMediator';
  4. import { SceneManager } from '../../../engines/scenes/SceneManager';
  5. import GameConfigManager from '../../models/GameConfigManager';
  6. import { GameModel } from '../../models/GameModel';
  7. import { GameController } from '../fightings/GameController';
  8. import { UIConst } from '../UIConst';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('GameOverMediator')
  11. export class GameOverMediator extends GUIMediator {
  12. @property(Node)
  13. WinGroup:Node=null;
  14. @property({
  15. type:LabelComponent
  16. })
  17. WinAwardLabel:LabelComponent=null;
  18. @property(Node)
  19. DefeatedGroup:Node=null;
  20. private isWin:boolean;
  21. private award:number;
  22. onLoad(){
  23. }
  24. OnShow(data?:any):void{
  25. super.OnShow(data);
  26. this.isWin=data;
  27. this.WinGroup.active=this.isWin;
  28. this.DefeatedGroup.active=!this.isWin;
  29. //胜利
  30. if(this.isWin==true){
  31. this.WinGroup.active=true;
  32. this.DefeatedGroup.active=false;
  33. let levelConfig:any=GameConfigManager.GetLevelConfig(GameModel.single.currentLevel-1);
  34. //关卡基础奖励
  35. this.award=levelConfig.awards+levelConfig.killAward*GameModel.single.killCount;
  36. this.WinAwardLabel.string=this.award.toString();
  37. }else{//失败
  38. //失败不算奖励
  39. this.WinGroup.active=false;
  40. this.DefeatedGroup.active=true;
  41. }
  42. }
  43. /**
  44. * 开始下一关
  45. */
  46. PlayNextLevel():void{
  47. this.AddAward();
  48. this.HideSelf();
  49. GameController.single.PlayNextLevel();
  50. }
  51. /**
  52. * 重玩
  53. */
  54. Replay():void{
  55. this.AddAward();
  56. this.HideSelf();
  57. GameController.single.Replay();
  58. }
  59. /**
  60. * 返回主界面
  61. */
  62. BackToMain():void{
  63. this.AddAward();
  64. SceneManager.single.Swicth("PrepareScene");
  65. GUIManager.single.Hide(UIConst.FIGHTING_UI);
  66. //关闭自身
  67. this.HideSelf();
  68. }
  69. /**
  70. * 获取奖励
  71. */
  72. private AddAward(value:number=1):void{
  73. if(this.isWin){
  74. GameModel.single.gold+=this.award*value;
  75. }
  76. }
  77. OnHide():void{
  78. }
  79. }