GameController.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import GameModel from "../Model/GameModel";
  2. import Toast from '../Utils/Toast';
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. grid: {
  7. default: null,
  8. type: cc.Node
  9. },
  10. audioButton: {
  11. default: null,
  12. type: cc.Node
  13. },
  14. audioSource: {
  15. type: cc.AudioSource
  16. }
  17. },
  18. // use this for initialization
  19. onLoad: function () {
  20. let audioButton = this.node.parent.getChildByName('audioButton')
  21. audioButton.on('click', this.callback, this)
  22. this.gameModel = new GameModel();
  23. this.gameModel.init(4);
  24. var gridScript = this.grid.getComponent("GridView");
  25. gridScript.setController(this);
  26. gridScript.initWithCellModels(this.gameModel.getCells());
  27. this.audioSource = cc.find('Canvas/GameScene')._components[1].audio;
  28. },
  29. callback: function () {
  30. let state = this.audioSource._state;
  31. state === 1 ? this.audioSource.pause() : this.audioSource.play()
  32. Toast(state === 1 ? '关闭背景音乐🎵' : '打开背景音乐🎵' )
  33. },
  34. selectCell: function (pos) {
  35. return this.gameModel.selectCell(pos);
  36. },
  37. cleanCmd: function () {
  38. this.gameModel.cleanCmd();
  39. }
  40. });