//shuffle jewels when no avalible move using fisher yates shuffler private void ShuffleJewels() { //go through the board and get all the jewels for (int i = 0; i < boardTiles.Count; i++) { boardJewels.Add(boardTiles[i].piece); } //shuffle the jewels using fisher yates System.Random random = new System.Random(); for (int j = 0; j < boardJewels.Count; j++) { int r = j + (int)(random.NextDouble() * (boardJewels.Count - j)); JewelPiece randJewel = boardJewels[r]; boardJewels[r] = boardJewels[j]; boardJewels[j] = randJewel; } //redistribute all the jewels for (int k = 0; k < boardTiles.Count; k++) { boardTiles[k].piece = boardJewels[k]; boardJewels[k].transform.position = boardTiles[k].transform.position; } }
private void CheckLeft(TileBehavior tileToCheck, JewelPiece match, List <TileBehavior> markedList) { if (tileToCheck.piece) { if (tileToCheck.piece.jewel == match.jewel) { markedList.Add(tileToCheck); if (tileToCheck.neighbours.xNegTile) { CheckLeft(tileToCheck.neighbours.xNegTile, match, markedList); } } } }
//exchange jewels public IEnumerator ExchangeJewels(TileBehavior first, TileBehavior second) { //board is doing things doingThings = true; //do the swap JewelPiece tempHold = second.piece; second.piece = first.piece; first.piece = tempHold; //do the tween first.piece.gameObject.transform.DOMove(first.transform.position, travelTime); second.piece.gameObject.transform.DOMove(second.transform.position, travelTime); //wait for tween to finish yield return(new WaitForSeconds(travelTime)); //check for completed move checkedTiles.Clear(); CheckBoardCompletedMove(); //if was complete clear tiles if (checkedTiles.Count > 0) { ClearJewels(); } //else was not swap back else { //do the swap tempHold = second.piece; second.piece = first.piece; first.piece = tempHold; //do the tween first.piece.gameObject.transform.DOMove(first.transform.position, travelTime); second.piece.gameObject.transform.DOMove(second.transform.position, travelTime); //wait for tween to finish yield return(new WaitForSeconds(travelTime)); //board not doing things doingThings = false; } }