// function to backtrack the swipe chain static void backTrackSelection(JSFBoard board) { // ==== BACK TRACK SWIPE CODE ==== if (swipeChain.Contains(board)) { int index = swipeChain.IndexOf(board); for (int x = 0; x <= swipeChain.Count - 1 - index; x++) { JSFRelay.onSwipeRemoved(swipeChain[swipeChain.Count - 1 - x].piece, false); } swipeChain.RemoveRange(index, swipeChain.Count - index); removeSwipeVisuals(index); JSFRelay.onSwipeBackTracked(board.piece, false); // relay call if (swipeChain.Count == 0) { isSwiping = false; swipeStart(board); // add back this board with its call criterias } else { rainbowSwipe = true; // in case we have changed color before this... revert to this color swipeCall(board); // add back this board with its call criterias } } }
public JSFGamePiece(JSFPieceDefinition newPd, JSFBoard newMaster, int type, Vector3 newPosition) { pd = newPd; master = newMaster; slotNum = type; position = newPosition; }
// randomly assign a special to this board void randomSpecialABoard() { JSFBoard selected = getRandomBoard(); // play audio visuals if (gm.audioScript.convertingSpecialFx.Length > 0) { gm.audioScript.convertingSpecialFx[Random.Range(0, gm.audioScript.convertingSpecialFx.Length - 1)].play(); } gm.animScript.doAnim(JSFanimType.CONVERTSPEC, selected.arrayRef[0], selected.arrayRef[1]); // get the gameobject reference GameObject pm = gm.pieceManager; switch (Random.Range(0, 3)) { case 0: selected.convertToSpecialNoDestroy(pm.GetComponent <JSFHorizontalPiece>(), selected.piece.slotNum); // convert to H-type break; case 1: selected.convertToSpecialNoDestroy(pm.GetComponent <JSFVerticalPiece>(), selected.piece.slotNum); // convert to V-type break; case 2: selected.convertToSpecialNoDestroy(pm.GetComponent <JSFBombPiece>(), selected.piece.slotNum); // convert to T-type break; } }
int[] getExitPath(JSFBoard board) { int[] newRef = new int[] { board.arrayRef[0], board.arrayRef[1] }; // make a copy of the array position // compensate for gravity switch (gm.currentGravity) { case JSFGravity.LEFT: newRef[0] = newRef[0] - 1; break; case JSFGravity.RIGHT: newRef[0] = newRef[0] + 1; break; case JSFGravity.DOWN: newRef[1] = newRef[1] - 1; break; case JSFGravity.UP: newRef[1] = newRef[1] + 1; break; } return(newRef); }
static void addSwipeLine(int x, int y) { if (vm.swipeLineObj == null) { Debug.LogError("Warning : No swipe line object. Check JSFVisualManager."); return; // no object defined } if (swipeChain.Count < 2) { return; // not enough to create a line between two objects yet } GameObject obj; if (gm.usingPoolManager) // POOLMANAGER CODE { obj = PoolManager.Pools[JSFUtils.miscPoolName].Spawn(vm.swipeLineObj.transform).gameObject; } else // NON-POOLMANAGER CODE { obj = GameObject.Instantiate(vm.swipeLineObj) as GameObject; } JSFBoard board = swipeChain[swipeChain.Count - 2]; // get the previous swipe entry JSFUtils.creatSwipeLine(obj, gm.getBoardPosition(x, y), board.position, -19.99f); swipeLineChain.Add(obj); }
public GameObject defaultPanel; // for visuals - the default panel at the back public JSFBoardPanel(JSFPanelDefinition newDefinition, int strength, JSFBoard myMaster) { master = myMaster; // set the master script // set the type - DO NOT USE setType() as we do not want to initPanels()~! pnd = newDefinition; durability = strength; }
// function to add to the swipe chain static void swipeAdd(JSFBoard board) { isSwiping = true; // swiping is active // ==== SWIPE CHAIN CODE ==== swipeChain.Add(board); addVisualChain(board.arrayRef[0], board.arrayRef[1]); JSFRelay.onSwipeAdded(board.piece, false); // relay call }
// function to get the GamePiece reference of previous added swipe chain using index and num of index previous public static JSFGamePiece getPrevChainedFromHere(JSFBoard refIndex, int num) { int newIndex = swipeChain.IndexOf(refIndex) - num; if (newIndex >= 0 && newIndex < swipeChain.Count) // if index not out of bounds... { return(swipeChain[newIndex].piece); // return the index.. } return(null); // out of bounds, return null }
// function to check for swipe legality (can users swipe?) static bool isLegalSwipe(JSFBoard board) { if (gm.moveOnlyAfterSettle) // move only after settle? { if (!gm.checkedPossibleMove) { return(false); // not ready to move } } return(gm.canMove && gm.gameState == JSFGameState.GameActive && gm.isLegalSwipe(board)); // meets criteria? }
// neighbouring function to get all boards in this specific direction public List <JSFBoard> getAllBoardInDirection(JSFBoardDirection bd) { List <JSFBoard> list = new List <JSFBoard>(); JSFBoard chain = boardEnumToReference(bd); while (chain != null) // recursively add the boards in the specified direction { list.Add(chain); chain = chain.boardEnumToReference(bd); } return(list); // returns the list of boards in the direction }
// neighbouring function to get a board in this specific direction and distance public JSFBoard getBoardFromDirection(JSFBoardDirection bd, int distance) { JSFBoard target = boardEnumToReference(bd); // initial for (int x = 1; x < distance; x++) // recursively find the board in the specified direction { if (target == null) { break; // no board here... do not continue... } target = target.boardEnumToReference(bd); } return(target); }
public static void swipeCall(JSFBoard board) { // check backtracking? if (swipeChain.Contains(board)) // check if we are backtracking the current selection { hasPowerMerge = false; // resets any powerMerge status rainbowSwipe = false; // resets the any swipe status limitedSwipe = false; // resets the limit of swipe backTrackSelection(board); // default proceeds with back tracking... return; // do not continue further... backtracked } // check legality of swipe if (!isSwiping || limitedSwipe || !isLegalSwipe(board)) { return; // not legal... do not continue } // check distance requirements int distance = gm.boardRadiusDistance(board, lastSwipeChainBoard); if (distance < board.pd.minSwipeDistance(board.piece) || distance > board.pd.maxSwipeDistance(board.piece)) { return; // not within distance... do not proceed with swipe... } // check for powerMerge... foreach (JSFBoard checkBoard in swipeChain) { if (checkBoard.pd.powerMerge(swipeChain, board.piece, checkBoard.piece, board.arrayRef, true) || board.pd.powerMerge(swipeChain, checkBoard.piece, board.piece, board.arrayRef, true)) // powerMerge? { rainbowSwipe = false; // resets the any swipe status swipeAdd(board); // add to chain hasPowerMerge = true; return; // added as powerMerge... } } // does the pieceDefinition allow to add to swipe chain? if (board.pd.addToSwipeChain(board.piece, swipeColor, false) || // normal add to swipe OR (rainbowSwipe && !board.pd.isSpecial)) // check for rainbow OR { if (rainbowSwipe && !board.pd.isSpecial) { swipeColor = board.piece.slotNum; // change to this color if it was from rainbowSwipe } rainbowSwipe = false; // resets the any swipe status swipeAdd(board); // add to chain } }
// called by Board during GameManager game-start phase // different from Start() as that is unity start, not neccessarily the game is set-up yet public override void onGameStart(JSFBoard board) { for (int x = 0; x < board.gm.boardWidth; x++) { for (int y = 0; y < board.gm.boardHeight; y++) { if (board.gm.board[x, y].panel.pnd is JSFPortalB) // find the exit pair { if (board.gm.board[x, y].panel.durability == board.panel.durability) // matching exit pair { boardA.Add(board); // save the entry pair reference boardB.Add(board.gm.board[x, y]); // save the exit pair reference } } } } }
public static void swipeStart(JSFBoard board) { if (isSwiping) { validateSwipe(); // prevent refresh bug hack } if (!isLegalSwipe(board)) { return; // not a legal swipe... do not proceed with swiping } if (board.pd.useAsFirstSwipe(board.piece, false)) // check if pieceDefinition allows to swipe start { isSwiping = true; swipeAdd(board); } }
// function to set the neighbour of this board public void initNeighbourReferences() { // board position in x & y reference int x = arrayRef[0]; int y = arrayRef[1]; // null the references first top = bottom = left = right = topLeft = topRight = bottomLeft = bottomRight = null; if (y + 1 < gm.boardHeight) { top = gm.board[x, y + 1]; // top reference allNeighbourBoards.Add(top); // add to the neighbourlist } if (y - 1 >= 0) { bottom = gm.board[x, y - 1]; // bottom reference allNeighbourBoards.Add(bottom); // add to the neighbourlist } if (gm.boardType == JSFBoardType.Square) // exclusive to square types only { if (x + 1 < gm.boardWidth) { right = gm.board[x + 1, y]; // right reference allNeighbourBoards.Add(right); // add to the neighbourlist } if (x - 1 >= 0) { left = gm.board[x - 1, y]; // left reference allNeighbourBoards.Add(left); // add to the neighbourlist } } if (gm.boardType == JSFBoardType.Square && gm.squareSplashMode == JSFsquareMode.Box9x9Type) // exclusive to square 9x9 mode only { if (y - 1 >= 0 && x + 1 < gm.boardWidth) { bottomRight = gm.board[x + 1, y - 1]; // bottomRight reference allNeighbourBoards.Add(bottomRight); // add to the neighbourlist } if (y - 1 >= 0 && x - 1 >= 0) { bottomLeft = gm.board[x - 1, y - 1]; // bottomRight reference allNeighbourBoards.Add(bottomLeft); // add to the neighbourlist } if (y + 1 < gm.boardHeight && x + 1 < gm.boardWidth) { topRight = gm.board[x + 1, y + 1]; // bottomRight reference allNeighbourBoards.Add(topRight); // add to the neighbourlist } if (y + 1 < gm.boardHeight && x - 1 >= 0) { topLeft = gm.board[x - 1, y + 1]; // bottomRight reference allNeighbourBoards.Add(topLeft); // add to the neighbourlist } } if (gm.boardType == JSFBoardType.Hexagon) // exclusive to Hexagon mode only { int refY = y; // initial value of y if (x % 2 == 1) // hex correction only { refY = y - 1; // compensate for hex squiggly line } if (refY >= 0 && refY < gm.boardHeight && x + 1 < gm.boardWidth) { bottomRight = gm.board[x + 1, refY]; // bottomRight reference allNeighbourBoards.Add(bottomRight); // add to the neighbourlist } if (refY >= 0 && refY < gm.boardHeight && x - 1 >= 0) { bottomLeft = gm.board[x - 1, refY]; // bottomRight reference allNeighbourBoards.Add(bottomLeft); // add to the neighbourlist } if (refY + 1 >= 0 && (refY + 1) < gm.boardHeight && x + 1 < gm.boardWidth) { topRight = gm.board[x + 1, refY + 1]; // bottomRight reference allNeighbourBoards.Add(topRight); // add to the neighbourlist } if (refY + 1 >= 0 && (refY + 1) < gm.boardHeight && x - 1 >= 0) { topLeft = gm.board[x - 1, refY + 1]; // bottomRight reference allNeighbourBoards.Add(topLeft); // add to the neighbourlist } } }
// called by GameManager when board stabilize and gets a suggestion public virtual void onBoardStabilize(JSFBoard board) { // do nothing... }
// // Virtual functions that users can override // or leave it as default behaviours // // called by Board during GameManager game-start phase // different from Start() as that is unity start, not neccessarily the game is set-up yet public virtual void onGameStart(JSFBoard board) { // do nothing.... }
// Optional piece splash function when a piece is destroyed public virtual void splashDamage(JSFBoard board) { // do nothing... }
// called by GameManager when player makes the next move public override void onPlayerMove(JSFBoard board) { // default do nothing... // your own code here if you need }
// called by GameManager when player makes the next move public virtual void onPlayerMove(JSFBoard board) { // do nothing... }
// called by GameManager when board stabilize and gets a suggestion public override void onBoardStabilize(JSFBoard board) { // default do nothing... // your own code here if you need // think of this as something like "on the next turn"... }
// called by Board during GameManager game-start phase // different from Start() as that is unity start, not neccessarily the game is set-up yet public override void onGameStart(JSFBoard board) { // nothing... }
// Optional piece splash function when a piece is destroyed public override void splashDamage(JSFBoard board) { // default do nothing... // your own code here if you need // splash when a match is formed... }