12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import GameModel from "../Model/GameModel";
- import Toast from '../Utils/Toast';
- cc.Class({
- extends: cc.Component,
- properties: {
- grid: {
- default: null,
- type: cc.Node
- },
- audioButton: {
- default: null,
- type: cc.Node
- },
- audioSource: {
- type: cc.AudioSource
- }
- },
- // use this for initialization
- onLoad: function () {
- let audioButton = this.node.parent.getChildByName('audioButton')
- audioButton.on('click', this.callback, this)
- this.gameModel = new GameModel();
- this.gameModel.init(4);
- var gridScript = this.grid.getComponent("GridView");
- gridScript.setController(this);
- gridScript.initWithCellModels(this.gameModel.getCells());
- this.audioSource = cc.find('Canvas/GameScene')._components[1].audio;
- },
- callback: function () {
- let state = this.audioSource._state;
- state === 1 ? this.audioSource.pause() : this.audioSource.play()
- Toast(state === 1 ? '关闭背景音乐🎵' : '打开背景音乐🎵' )
- },
- selectCell: function (pos) {
- return this.gameModel.selectCell(pos);
- },
- cleanCmd: function () {
- this.gameModel.cleanCmd();
- }
- });
|