UNPKG

phaser4-rex-plugins

Version:
59 lines (48 loc) 1.76 kB
/* 1. Test if there has any matched line after chess swapping */ import RefreshSymbolCache from '../match/RefreshSymbolCache.js'; import AnyMatch from '../match/AnyMatch.js'; var PreTest = function () { var match = this.match; var directions = this.board.grid.halfDirections; var tileB; RefreshSymbolCache.call(this); // only refresh symbol cache once for (var tileY = 0, rowCnt = this.board.height; tileY < rowCnt; tileY++) { for (var tileX = 0, colCnt = this.board.width; tileX < colCnt; tileX++) { if (!this.isAtActivateArea(tileX, tileY)) { continue; } tileA.x = tileX; tileA.y = tileY; for (var dir = 0, dirCnt = directions.length; dir < dirCnt; dir++) { tileB = this.board.getNeighborTileXY(tileA, dir); // In prepare rows if (!this.isAtActivateArea(tileB.x, tileB.y)) { continue; } // Swap symbol SwapSymbols(match, tileA, tileB); // Any match? this.preTestResult = AnyMatch.call(this, 3); // Swap symbol back SwapSymbols(match, tileA, tileB); if (this.preTestResult) { return true; } } } } return false; } var SwapSymbols = function (match, tileA, tileB) { var symbolA = match.getSymbol(tileA.x, tileA.y); var symbolB = match.getSymbol(tileB.x, tileB.y); match.setSymbol(tileA.x, tileA.y, symbolB); match.setSymbol(tileB.x, tileB.y, symbolA); }; var tileA = { x: 0, y: 0 }; export default PreTest;