Spaces:
Build error
Build error
File size: 1,476 Bytes
670a607 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/*
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 = (this.board.height / 2), rowCnt = this.board.height; tileY < rowCnt; tileY++) {
for (var tileX = 0, colCnt = this.board.width; tileX < colCnt; tileX++) {
tileA.x = tileX;
tileA.y = tileY;
for (var dir = 0, dirCnt = directions.length; dir < dirCnt; dir++) {
tileB = this.board.getNeighborTileXY(tileA, dir);
// 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; |