消除背景地形邊框填充演算法
阿新 • • 發佈:2018-12-09
資源圖如下:
在做消除遊戲時遇到了以上的地形顯示需求,自己根據演算法實現了下,方便以後可能用到直接貼上了,因為當時用的程式碼時node.ts,因此為了不與引擎掛鉤,這裡只貼上演算法程式碼
當前程式碼所在類部分成員:
lastMovingTargetPathMapItem:當前物件是否是地形的最後一格
toDirection:地形方向(相對於下一個格子來說)
this.logic.viewPool.XXX(函式):這種形式可理解為cocos中的sprite
this.row:當前行
this.col:當前列
this.leftView.spriteFrame:精靈幀
isMovePath(函式):判斷當前物件(根據行和列鎖定)是否在地形中的格子
isMapItemLink:判斷當前兩個位置的格子是否是連通的(之間沒有障礙)
isLastMovePathEnd:判斷當前物件是否是最後一格
nextMovingTargetPathMapItem:當前格子物件的下一個格子
//左邊 private initLeftView() { if (!this.lastMovingTargetPathMapItem && this.toDirection === Direction.LeftToRight) { return; } if (!this.leftView) { this.leftView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingBorder); this.leftView.rotation = 90; cc.log('left row = ', this.row, 'col = ', this.col); if (this.isMovePath(this.row, this.col - 1) && this.isMapItemLink(this.row, this.col - 1, this.row, this.col)) { return; } if (this.isMovePath(this.row - 1, this.col)) { // 先判斷上方) if (this.isMapItemLink(this.row, this.col, this.row - 1, this.col)) { if (this.isMovePath(this.row - 1, this.col - 1) && this.isMapItemLink(this.row - 1, this.col, this.row - 1, this.col - 1)) { if (this.isMovePath(this.row + 1, this.col)) { if (this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { if (this.isMovePath(this.row + 1, this.col - 1) && this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col - 1)) { this.leftView.spriteFrame = `game/MovingTargetPath_6`; } else { this.leftView.spriteFrame = `game/MovingTargetPath_3`; this.leftView.flippedX = true; } } else { this.leftView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.leftView.spriteFrame = `game/MovingTargetPath_3`; this.leftView.flippedX = true; } else { this.leftView.spriteFrame = `game/MovingTargetPath_6`; } } } else { // 上方直行 判斷下方 if (this.isMovePath(this.row + 1, this.col)) { if (this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { if (this.isMovePath(this.row + 1, this.col - 1) && this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col - 1)) { this.leftView.spriteFrame = `game/MovingTargetPath_3`; } else { this.leftView.spriteFrame = `game/MovingTargetPath_4`; } } else { this.leftView.spriteFrame = `game/MovingTargetPath_3`; } } else { if (!this.lastMovingTargetPathMapItem) { this.leftView.spriteFrame = `game/MovingTargetPath_4`; } else { this.leftView.spriteFrame = `game/MovingTargetPath_3`; } } } } else { // 上方有值但不通,繼續判斷下方 if (this.isMovePath(this.row + 1, this.col)) { if (this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { if (this.isMovePath(this.row + 1, this.col - 1) && this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col - 1)) { this.leftView.spriteFrame = `game/MovingTargetPath_6`; } else { this.leftView.spriteFrame = `game/MovingTargetPath_3`; this.leftView.flippedX = true; } } else { this.leftView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.leftView.spriteFrame = `game/MovingTargetPath_3`; this.leftView.flippedX = true; } else { this.leftView.spriteFrame = `game/MovingTargetPath_6`; } } } } else { if (this.isMovePath(this.row + 1, this.col)) { if (this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { if (this.isMovePath(this.row + 1, this.col - 1) && this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col - 1)) { if (!this.lastMovingTargetPathMapItem) { this.leftView.spriteFrame = `game/MovingTargetPath_3`; } else { this.leftView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.leftView.spriteFrame = `game/MovingTargetPath_4`; } else { this.leftView.spriteFrame = `game/MovingTargetPath_3`; this.leftView.flippedX = true; } } } else { if (!this.lastMovingTargetPathMapItem) { this.leftView.spriteFrame = `game/MovingTargetPath_3`; } else { this.leftView.spriteFrame = `game/MovingTargetPath_6`; } } } else { this.leftView.spriteFrame = `game/MovingTargetPath_6`; } } if (this.isLastMovePathEnd(this.row, this.col - 1)) { if (this.isMovePath(this.row - 1, this.col) && this.isMapItemLink(this.row, this.col, this.row - 1, this.col) && this.isMovePath(this.row - 1, this.col - 1) && this.isMapItemLink(this.row - 1, this.col, this.row - 1, this.col - 1) && this.isMapItemLink(this.row, this.col - 1, this.row - 1, this.col - 1)) { this.leftHalfCornerView = this.logic.viewPool.getView(this.row, this.col - 1, ViewIndexMap.movingCorner); this.leftHalfCornerView.spriteFrame = `game/MovingTargetPath_7`; this.leftHalfCornerView.rotation = -90; this.leftHalfCornerView.offsetX = 4; this.leftHalfCornerView.offsetY = 2; } else if (this.isMovePath(this.row + 1, this.col) && this.isMapItemLink(this.row, this.col, this.row + 1, this.col) && this.isMovePath(this.row + 1, this.col - 1) && this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col - 1) && this.isMapItemLink(this.row, this.col - 1, this.row + 1, this.col - 1)) { this.leftHalfCornerView = this.logic.viewPool.getView(this.row, this.col - 1, ViewIndexMap.movingCorner); this.leftHalfCornerView.spriteFrame = `game/MovingTargetPath_7`; this.leftHalfCornerView.flippedY = true; this.leftHalfCornerView.rotation = 90; this.leftHalfCornerView.offsetX = 4; this.leftHalfCornerView.offsetY = -2; } } } } //右邊 private initRightView() { if (!this.lastMovingTargetPathMapItem && this.toDirection === Direction.RightToLeft) { return; } if (!this.rightView) { this.rightView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingBorder); this.rightView.rotation = -90; cc.log('right row = ', this.row, 'col = ', this.col); if (this.isMovePath(this.row, this.col + 1) && this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { return; } if (this.isMovePath(this.row - 1, this.col)) { // 先判斷上方 if (this.isMapItemLink(this.row, this.col, this.row - 1, this.col)) { if (this.isMovePath(this.row - 1, this.col + 1) && this.isMapItemLink(this.row - 1, this.col, this.row - 1, this.col + 1)) { if (this.isMovePath(this.row + 1, this.col)) { if (this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { if (this.isMovePath(this.row + 1, this.col + 1) && this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col + 1)) { this.rightView.spriteFrame = `game/MovingTargetPath_6`; } else { this.rightView.spriteFrame = `game/MovingTargetPath_3`; } } else { this.rightView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.rightView.spriteFrame = `game/MovingTargetPath_3`; } else { this.rightView.spriteFrame = `game/MovingTargetPath_6`; } } } else { // 上方直行 判斷下方 if (this.isMovePath(this.row + 1, this.col)) { if (this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { if (this.isMovePath(this.row + 1, this.col + 1) && this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col + 1)) { this.rightView.spriteFrame = `game/MovingTargetPath_3`; this.rightView.flippedX = true; } else { this.rightView.spriteFrame = `game/MovingTargetPath_4`; } } else { this.rightView.spriteFrame = `game/MovingTargetPath_3`; this.rightView.flippedX = true; } } else { if (!this.lastMovingTargetPathMapItem) { this.rightView.spriteFrame = `game/MovingTargetPath_4`; } else { this.rightView.spriteFrame = `game/MovingTargetPath_3`; this.rightView.flippedX = true; } } } } else { // 上方有值但不通,繼續判斷下方 if (this.isMovePath(this.row + 1, this.col)) { if (this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { if (this.isMovePath(this.row + 1, this.col + 1) && this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col + 1)) { this.rightView.spriteFrame = `game/MovingTargetPath_6`; } else { this.rightView.spriteFrame = `game/MovingTargetPath_3`; } } else { this.rightView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.rightView.spriteFrame = `game/MovingTargetPath_3`; } else { this.rightView.spriteFrame = `game/MovingTargetPath_6`; } } } } else { if (this.isMovePath(this.row + 1, this.col)) { if (this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { if (this.isMovePath(this.row + 1, this.col + 1) && this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col + 1)) { if (!this.lastMovingTargetPathMapItem) { this.rightView.spriteFrame = `game/MovingTargetPath_3`; this.rightView.flippedX = true; } else { this.rightView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.rightView.spriteFrame = `game/MovingTargetPath_4`; } else { this.rightView.spriteFrame = `game/MovingTargetPath_3`; } } } else { if (!this.lastMovingTargetPathMapItem) { this.rightView.spriteFrame = `game/MovingTargetPath_3`; this.rightView.flippedX = true; } else { this.rightView.spriteFrame = `game/MovingTargetPath_6`; } } } else { this.rightView.spriteFrame = `game/MovingTargetPath_6`; } } if (this.isMovePath(this.row + 1, this.col) && this.isMovePath(this.row + 1, this.col + 1)) { if (this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { if (this.isMapItemLink(this.row, this.col + 1, this.row + 1, this.col + 1)) { if (this.isLastMovePathEnd(this.row, this.col + 1)) { this.rightHalfCornerView = this.logic.viewPool.getView(this.row, this.col + 1, ViewIndexMap.movingBorder); this.rightHalfCornerView.spriteFrame = `game/MovingTargetPath_7`; this.rightHalfCornerView.rotation = 90; this.rightHalfCornerView.offsetX = -4; this.rightHalfCornerView.offsetY = -2; } else { this.rightHalfCornerView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingCorner); this.rightHalfCornerView.spriteFrame = `game/MovingTargetPath_1`; this.rightHalfCornerView.rotation = 90; this.rightHalfCornerView.flippedY = true; this.rightHalfCornerView.offsetX = 4; } } } } } if (this.isMovePath(this.row - 1, this.col) && this.isMovePath(this.row - 1, this.col + 1)) { if (this.isMapItemLink(this.row - 1, this.col, this.row - 1, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row - 1, this.col)) { if (this.isMapItemLink(this.row, this.col + 1, this.row - 1, this.col + 1)) { if (this.isMapItemLink(this.row, this.col + 1, this.row - 1, this.col + 1)) { if (this.isLastMovePathEnd(this.row, this.col + 1)) { this.rightHalfCornerView = this.logic.viewPool.getView(this.row, this.col + 1, ViewIndexMap.movingCorner); this.rightHalfCornerView.spriteFrame = `game/MovingTargetPath_7`; this.rightHalfCornerView.rotation = 90; this.rightHalfCornerView.offsetX = -4; this.rightHalfCornerView.flippedX = true; this.rightHalfCornerView.offsetY = 2; } else { this.rightHalfCornerView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingCorner); this.rightHalfCornerView.spriteFrame = `game/MovingTargetPath_1`; this.rightHalfCornerView.rotation = -90; this.rightHalfCornerView.offsetX = 4; } } } } } } } }
//上方 private initTopView() { if (!this.lastMovingTargetPathMapItem && this.toDirection === Direction.TopToBottom) { return; } if (!this.topView) { this.topView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingBorder); this.topView.rotation = 180; cc.log('left row = ', this.row, 'col = ', this.col); if (this.isMovePath(this.row - 1, this.col) && (this.isMapItemLink(this.row, this.col, this.row - 1, this.col))) { return; } if (this.isMovePath(this.row, this.col - 1)) {// 先判斷左邊棋子 if (this.isMapItemLink(this.row, this.col, this.row, this.col - 1)) { if (this.isMovePath(this.row - 1, this.col - 1) && this.isMapItemLink(this.row, this.col - 1, this.row - 1, this.col - 1)) { if (this.isMovePath(this.row, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { if (this.isMovePath(this.row - 1, this.col + 1) && this.isMapItemLink(this.row, this.col + 1, this.row - 1, this.col + 1)) { this.topView.spriteFrame = `game/MovingTargetPath_6`; } else { this.topView.spriteFrame = `game/MovingTargetPath_3`; } } else { this.topView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.topView.spriteFrame = `game/MovingTargetPath_3`; } else { this.topView.spriteFrame = `game/MovingTargetPath_6`; } } } else {// 左邊直行 判斷右邊 if (this.isMovePath(this.row, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { if (this.isMovePath(this.row - 1, this.col + 1) && this.isMapItemLink(this.row, this.col + 1, this.row - 1, this.col + 1)) { this.topView.spriteFrame = `game/MovingTargetPath_3`; this.topView.flippedX = true; } else { this.topView.spriteFrame = `game/MovingTargetPath_4`; } } else { this.topView.spriteFrame = `game/MovingTargetPath_3`; this.topView.flippedX = true; } } else { if (!this.lastMovingTargetPathMapItem) { this.topView.spriteFrame = `game/MovingTargetPath_4`; } else { this.topView.spriteFrame = `game/MovingTargetPath_3`; this.topView.flippedX = true; } } } } else {// 左邊有值但不通,繼續判斷右邊 if (this.isMovePath(this.row, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { if (this.isMovePath(this.row - 1, this.col + 1) && this.isMapItemLink(this.row, this.col + 1, this.row - 1, this.col + 1)) { this.topView.spriteFrame = `game/MovingTargetPath_6`; } else { this.topView.spriteFrame = `game/MovingTargetPath_3`; } } else { this.topView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.topView.spriteFrame = `game/MovingTargetPath_3`; } else { this.topView.spriteFrame = `game/MovingTargetPath_6`; } } } } else {// 左邊無棋子 if (this.isMovePath(this.row, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { if (this.isMovePath(this.row - 1, this.col + 1) && this.isMapItemLink(this.row, this.col + 1, this.row - 1, this.col + 1)) { if (!this.lastMovingTargetPathMapItem) { this.topView.spriteFrame = `game/MovingTargetPath_3`; } else { this.topView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.topView.spriteFrame = `game/MovingTargetPath_4`; } else { this.topView.spriteFrame = `game/MovingTargetPath_3`; } } } else { if (!this.lastMovingTargetPathMapItem) { this.topView.spriteFrame = `game/MovingTargetPath_3`; this.topView.flippedX = true; } else { this.topView.spriteFrame = `game/MovingTargetPath_6`; } } } else { this.topView.spriteFrame = `game/MovingTargetPath_6`; } } if (this.isLastMovePathEnd(this.row - 1, this.col)) { if (this.isMovePath(this.row, this.col - 1) && this.isMapItemLink(this.row, this.col, this.row, this.col - 1) && this.isMovePath(this.row - 1, this.col - 1) && this.isMapItemLink(this.row, this.col - 1, this.row - 1, this.col - 1) && this.isMapItemLink(this.row - 1, this.col, this.row - 1, this.col - 1)) { this.topHalfCornerView = this.logic.viewPool.getView(this.row - 1, this.col, ViewIndexMap.movingCorner); this.topHalfCornerView.spriteFrame = `game/MovingTargetPath_7`; this.topHalfCornerView.flippedX = true; this.topHalfCornerView.offsetX = -2; this.topHalfCornerView.offsetY = -4; } else if (this.isMovePath(this.row, this.col + 1) && this.isMapItemLink(this.row, this.col, this.row, this.col + 1) && this.isMovePath(this.row - 1, this.col + 1) && this.isMapItemLink(this.row, this.col + 1, this.row - 1, this.col + 1) && this.isMapItemLink(this.row - 1, this.col, this.row - 1, this.col + 1)) { this.topHalfCornerView = this.logic.viewPool.getView(this.row - 1, this.col, ViewIndexMap.movingCorner); this.topHalfCornerView.spriteFrame = `game/MovingTargetPath_7`; this.topHalfCornerView.offsetX = 2; this.topHalfCornerView.offsetY = -4; } } } } //底部 private initBottomView() { if (!this.lastMovingTargetPathMapItem && this.toDirection === Direction.BottomToTop) { return; } if (!this.bottomView) { this.bottomView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingBorder); if (this.isMovePath(this.row + 1, this.col) && this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) { return; } if (this.isMovePath(this.row, this.col - 1)) {// 先判斷左邊棋子 if (this.isMapItemLink(this.row, this.col, this.row, this.col - 1)) { if (this.isMovePath(this.row + 1, this.col - 1) && this.isMapItemLink(this.row, this.col - 1, this.row + 1, this.col - 1)) { if (this.isMovePath(this.row, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { if (this.isMovePath(this.row + 1, this.col + 1) && this.isMapItemLink(this.row, this.col + 1, this.row + 1, this.col + 1)) { this.bottomView.spriteFrame = `game/MovingTargetPath_6`; } else { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; this.bottomView.flippedX = true; } } else { this.bottomView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; this.bottomView.flippedX = true; } else { this.bottomView.spriteFrame = `game/MovingTargetPath_6`; } } } else {// 左邊直行 判斷右邊 if (this.isMovePath(this.row, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { if (this.isMovePath(this.row + 1, this.col + 1) && this.isMapItemLink(this.row, this.col + 1, this.row + 1, this.col + 1)) { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; } else { this.bottomView.spriteFrame = `game/MovingTargetPath_4`; } } else { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; } } else { if (!this.lastMovingTargetPathMapItem) { this.bottomView.spriteFrame = `game/MovingTargetPath_4`; } else { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; } } } } else {// 左邊有值但不通,繼續判斷右邊 if (this.isMovePath(this.row, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { if (this.isMovePath(this.row + 1, this.col + 1) && this.isMapItemLink(this.row, this.col + 1, this.row + 1, this.col + 1)) { this.bottomView.spriteFrame = `game/MovingTargetPath_6`; } else { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; this.bottomView.flippedX = true; } } else { this.bottomView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; this.bottomView.flippedX = true; } else { this.bottomView.spriteFrame = `game/MovingTargetPath_6`; } } } } else {// 左邊無棋子 if (this.isMovePath(this.row, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { if (this.isMovePath(this.row + 1, this.col + 1) && this.isMapItemLink(this.row, this.col + 1, this.row + 1, this.col + 1)) { if (!this.lastMovingTargetPathMapItem) { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; } else { this.bottomView.spriteFrame = `game/MovingTargetPath_6`; } } else { if (!this.lastMovingTargetPathMapItem) { this.bottomView.spriteFrame = `game/MovingTargetPath_4`; } else { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; this.bottomView.flippedX = true; } } } else { if (!this.lastMovingTargetPathMapItem) { this.bottomView.spriteFrame = `game/MovingTargetPath_3`; } else { this.bottomView.spriteFrame = `game/MovingTargetPath_6`; } } } else { this.bottomView.spriteFrame = `game/MovingTargetPath_6`; } } // 單獨放置 if (this.isMovePath(this.row, this.col + 1) && this.isMovePath(this.row + 1, this.col + 1)) { if (this.isMapItemLink(this.row, this.col + 1, this.row + 1, this.col + 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) { if (this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col + 1)) { if (this.isLastMovePathEnd(this.row + 1, this.col)) { this.bottomHalfCornerView = this.logic.viewPool.getView(this.row + 1, this.col, ViewIndexMap.movingCorner); this.bottomHalfCornerView.spriteFrame = `game/MovingTargetPath_7`; this.bottomHalfCornerView.flippedY = true; this.bottomHalfCornerView.offsetX = 2; this.bottomHalfCornerView.offsetY = 4; } else { this.bottomHalfCornerView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingCorner); this.bottomHalfCornerView.spriteFrame = `game/MovingTargetPath_1`; this.bottomHalfCornerView.offsetY = -4; } } } } } if (this.isMovePath(this.row, this.col - 1) && this.isMovePath(this.row + 1, this.col - 1)) { if (this.isMapItemLink(this.row, this.col - 1, this.row + 1, this.col - 1)) { if (this.isMapItemLink(this.row, this.col, this.row, this.col - 1)) { if (this.isMapItemLink(this.row + 1, this.col, this.row + 1, this.col - 1)) { if (this.isLastMovePathEnd(this.row + 1, this.col)) { this.bottomHalfCornerView = this.logic.viewPool.getView(this.row + 1, this.col, ViewIndexMap.movingCorner); this.bottomHalfCornerView.spriteFrame = `game/MovingTargetPath_7`; this.bottomHalfCornerView.rotation = 180; this.bottomHalfCornerView.offsetX = -2; this.bottomHalfCornerView.offsetY = 4; } else { this.bottomHalfCornerView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingCorner); this.bottomHalfCornerView.spriteFrame = `game/MovingTargetPath_1`; this.bottomHalfCornerView.flippedX = true; this.bottomHalfCornerView.offsetY = -4; } } } } } } }
private initLeftTopView() {
if (!this.leftTopView) {
let cornerFunc = () => {
if (this.lastMovingTargetPathMapItem) {
this.leftTopView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingBorder);
this.leftTopView.spriteFrame = `game/MovingTargetPath_2`;
this.leftTopView.rotation = 180;
}
};
if (this.isMovePath(this.row, this.col - 1)) {
if (!this.isMapItemLink(this.row, this.col, this.row, this.col - 1)) {
if (!this.isMovePath(this.row - 1, this.col)) {
cornerFunc();
} else {
if (!this.isMapItemLink(this.row, this.col, this.row - 1, this.col)) {
cornerFunc();
}
}
} else {
if (this.isMovePath(this.row - 1, this.col) && this.isMapItemLink(this.row, this.col, this.row - 1, this.col)
&& (!this.isMovePath(this.row - 1, this.col - 1) || (this.isMovePath(this.row - 1, this.col - 1)
&& !this.isMapItemLink(this.row - 1, this.col - 1, this.row - 1, this.col)))
&& !this.isMapItemLink(this.row - 1, this.col - 1, this.row, this.col - 1)) {
this.leftTopView = this.logic.viewPool.getView(this.row - 1, this.col - 1, ViewIndexMap.movingBorder);
this.leftTopView.spriteFrame = `game/MovingTargetPath_5`;
this.leftTopView.rotation = 90;
this.leftTopView.offsetX = 4;
this.leftTopView.offsetY = -4;
}
}
} else {
if (!this.isMovePath(this.row - 1, this.col) ||
(this.isMovePath(this.row - 1, this.col) && !this.isMapItemLink(this.row, this.col, this.row - 1, this.col))) {
cornerFunc();
}
}
if (this.isMovePath(this.row - 1, this.col) && this.isMovePath(this.row, this.col - 1)) {
if (this.isMapItemLink(this.row, this.col, this.row - 1, this.col)
&& this.isMapItemLink(this.row, this.col, this.row, this.col - 1)
&& this.isMapItemLink(this.row - 1, this.col, this.row - 1, this.col - 1)
&& this.isMapItemLink(this.row, this.col - 1, this.row - 1, this.col - 1)) {
this.leftTopView = this.logic.viewPool.getView(this.row - 1, this.col - 1, ViewIndexMap.movingBorder);
this.leftTopView.spriteFrame = `game/MovingTargetPath_5`;
this.leftTopView.rotation = 90;
this.leftTopView.offsetX = 4;
this.leftTopView.offsetY = -4;
}
}
}
}
private initRightTopView() {
if (!this.rightTopView) {
let cornerFunc = () => {
if (this.lastMovingTargetPathMapItem) {
this.rightTopView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingBorder);
this.rightTopView.spriteFrame = `game/MovingTargetPath_2`;
this.rightTopView.rotation = -90;
}
};
if (this.isMovePath(this.row, this.col + 1)) {
if (!this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) {
if (!this.isMovePath(this.row - 1, this.col)) {
cornerFunc();
} else {
if (!this.isMapItemLink(this.row, this.col, this.row - 1, this.col)) {
cornerFunc();
}
}
} else {
if (this.isMovePath(this.row - 1, this.col) && this.isMapItemLink(this.row, this.col, this.row - 1, this.col)
&& (!this.isMovePath(this.row - 1, this.col + 1) || (this.isMovePath(this.row - 1, this.col + 1)
&& !this.isMapItemLink(this.row - 1, this.col + 1, this.row - 1, this.col)))
&& !this.isMapItemLink(this.row - 1, this.col + 1, this.row, this.col + 1)) {
this.rightTopView = this.logic.viewPool.getView(this.row - 1, this.col + 1, ViewIndexMap.movingBorder);
this.rightTopView.spriteFrame = `game/MovingTargetPath_5`;
this.rightTopView.rotation = 180;
this.rightTopView.offsetX = -4;
this.rightTopView.offsetY = -4;
}
}
} else {
if (!this.isMovePath(this.row - 1, this.col) ||
(this.isMovePath(this.row - 1, this.col) && !this.isMapItemLink(this.row, this.col, this.row - 1, this.col))) {
cornerFunc();
}
}
if (this.isMovePath(this.row, this.col + 1) && this.isMovePath(this.row - 1, this.col)) {
if (this.isMapItemLink(this.row, this.col, this.row - 1, this.col)
&& this.isMapItemLink(this.row, this.col, this.row, this.col + 1)
&& !this.isMapItemLink(this.row - 1, this.col, this.row - 1, this.col + 1)
&& !this.isMapItemLink(this.row, this.col + 1, this.row - 1, this.col + 1)) {
this.rightTopView = this.logic.viewPool.getView(this.row - 1, this.col + 1, ViewIndexMap.movingBorder);
this.rightTopView.spriteFrame = `game/MovingTargetPath_5`;
this.rightTopView.rotation = 180;
this.rightTopView.offsetX = -4;
this.rightTopView.offsetY = -4;
} else if (!this.isMapItemLink(this.row, this.col, this.row - 1, this.col)
&& !this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) {
cornerFunc();
}
}
}
}
private initLeftBottomView() {
if (!this.leftBottomView) {
let cornerFunc = () => {
if (this.lastMovingTargetPathMapItem) {
this.leftBottomView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingBorder);
this.leftBottomView.spriteFrame = `game/MovingTargetPath_2`;
this.leftBottomView.rotation = 90;
}
};
if (this.isMovePath(this.row, this.col - 1)) {
if (!this.isMapItemLink(this.row, this.col, this.row, this.col - 1)) {
if (!this.isMovePath(this.row + 1, this.col)) {
cornerFunc();
} else {
if (!this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) {
cornerFunc();
}
}
} else {
if (this.isMovePath(this.row + 1, this.col) && this.isMapItemLink(this.row, this.col, this.row + 1, this.col)
&& (!this.isMovePath(this.row + 1, this.col - 1) || (this.isMovePath(this.row + 1, this.col - 1)
&& !this.isMapItemLink(this.row + 1, this.col - 1, this.row + 1, this.col)))
&& !this.isMapItemLink(this.row + 1, this.col - 1, this.row, this.col - 1)) {
this.leftBottomView = this.logic.viewPool.getView(this.row + 1, this.col - 1, ViewIndexMap.movingBorder);
this.leftBottomView.spriteFrame = `game/MovingTargetPath_5`;
this.leftBottomView.offsetX = 4;
this.leftBottomView.offsetY = 4;
}
}
} else {
if (!this.isMovePath(this.row + 1, this.col) ||
(this.isMovePath(this.row + 1, this.col) && !this.isMapItemLink(this.row, this.col, this.row + 1, this.col))) {
cornerFunc();
}
}
if (this.isMovePath(this.row + 1, this.col) && this.isMovePath(this.row, this.col - 1)
&& !this.isMovePath(this.row + 1, this.col - 1) && this.isMapItemLink(this.row, this.col, this.row, this.col - 1)
&& this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) {
this.leftBottomView = this.logic.viewPool.getView(this.row + 1, this.col - 1, ViewIndexMap.movingBorder);
this.leftBottomView.spriteFrame = `game/MovingTargetPath_5`;
this.leftBottomView.offsetX = 4;
this.leftBottomView.offsetY = 4;
}
}
}
private initRightBottomView() {
if (!this.rightBottomView) {
let cornerFunc = () => {
if (this.lastMovingTargetPathMapItem) {
this.rightBottomView = this.logic.viewPool.getView(this.row, this.col, ViewIndexMap.movingBorder);
this.rightBottomView.spriteFrame = `game/MovingTargetPath_2`;
}
};
if (this.isMovePath(this.row, this.col + 1)) {
if (!this.isMapItemLink(this.row, this.col, this.row, this.col + 1)) {
if (!this.isMovePath(this.row + 1, this.col)) {
cornerFunc();
} else {
if (!this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) {
cornerFunc();
}
}
} else {
if (this.isMovePath(this.row + 1, this.col) && this.isMapItemLink(this.row, this.col, this.row + 1, this.col)
&& (!this.isMovePath(this.row + 1, this.col + 1) || (this.isMovePath(this.row + 1, this.col + 1)
&& !this.isMapItemLink(this.row + 1, this.col + 1, this.row + 1, this.col)))
&& !this.isMapItemLink(this.row + 1, this.col + 1, this.row, this.col + 1)) {
this.rightBottomView = this.logic.viewPool.getView(this.row + 1, this.col + 1, ViewIndexMap.movingBorder);
this.rightBottomView.spriteFrame = `game/MovingTargetPath_5`;
this.rightBottomView.rotation = -90;
this.rightBottomView.offsetX = -4;
this.rightBottomView.offsetY = 4;
}
}
} else {
if (!this.isMovePath(this.row + 1, this.col) ||
(this.isMovePath(this.row + 1, this.col) && !this.isMapItemLink(this.row, this.col, this.row + 1, this.col))) {
cornerFunc();
}
}
if (this.isMovePath(this.row + 1, this.col) && this.isMovePath(this.row, this.col + 1)
&& !this.isMovePath(this.row + 1, this.col + 1) && this.isMapItemLink(this.row, this.col, this.row, this.col + 1)
&& this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) {
this.rightBottomView = this.logic.viewPool.getView(this.row + 1, this.col + 1, ViewIndexMap.movingBorder);
this.rightBottomView.spriteFrame = `game/MovingTargetPath_5`;
this.rightBottomView.rotation = -90;
this.rightBottomView.offsetX = -4;
this.rightBottomView.offsetY = 4;
} else if (!this.isMovePath(this.row, this.col + 1) && this.isMovePath(this.row + 1, this.col)
&& !this.isMapItemLink(this.row, this.col, this.row + 1, this.col)) {
cornerFunc();
}
}
}
依次便利每一種情況,著重還是演算法部分,uI顯示及放置可忽略