private bool IsMergeExist(int index) { AdjacentPiece adj = GetAdjacentPiece(index); bool isPrevEquals = adj.Prev != null && adj.Prev.Value.Equals(_pieceController.Value); bool isNextEquals = adj.Next != null && adj.Next.Value.Equals(_pieceController.Value); return(isNextEquals || isPrevEquals); }
void setAdjacentPiece(AdjacentPiece whichPiece, Piece piece) { switch (whichPiece) { case AdjacentPiece.Above: above = piece; break; case AdjacentPiece.Below: below = piece; break; case AdjacentPiece.LeftTop: lefttop = piece; break; case AdjacentPiece.LeftBottom: leftbottom = piece; break; case AdjacentPiece.RightTop: righttop = piece; break; case AdjacentPiece.RightBottom: rightbottom = piece; break; } }
private IEnumerator IterateMerge(int index) { AdjacentPiece adj = GetAdjacentPiece(index); bool isPrevEquals = adj.Prev != null && adj.Prev.Value.Equals(_pieceController.Value); bool isNextEquals = adj.Next != null && adj.Next.Value.Equals(_pieceController.Value); if (isPrevEquals && isNextEquals) { int rnd = Randomize(); PieceController randomAdj = rnd == 0 ? adj.Next : adj.Prev; if (Randomize() == 1) { yield return(_pieceController.StartRotate(randomAdj.RotationZ)); GivePieceToPool(_pieceController); UpdatePieceValue(randomAdj); _pieceController = randomAdj; _pieces[index] = null; _lastIndex = rnd == 0 ? GetNextIndex(index) : GetPrevIndex(index); } else { yield return(randomAdj.StartRotate(_pieceController.RotationZ)); int i = rnd == 0 ? GetNextIndex(index) : GetPrevIndex(index); GivePieceToPool(randomAdj); UpdatePieceValue(_pieceController); _pieces[i] = null; _lastIndex = index; } yield break; } if (isPrevEquals) { int prev = GetPrevIndex(index); if (Randomize() == 1) { yield return(_pieceController.StartRotate(adj.Prev.RotationZ)); UpdatePieceValue(adj.Prev); GivePieceToPool(_pieceController); _pieceController = adj.Prev; _pieces[index] = null; _lastIndex = prev; } else { yield return(adj.Prev.StartRotate(_pieceController.RotationZ)); UpdatePieceValue(_pieceController); GivePieceToPool(adj.Prev); _pieces[prev] = null; _lastIndex = index; } } else if (isNextEquals) { int next = GetNextIndex(index); if (Randomize() == 1) { yield return(_pieceController.StartRotate(adj.Next.RotationZ)); UpdatePieceValue(adj.Next); GivePieceToPool(_pieceController); _pieceController = adj.Next; _pieces[index] = null; _lastIndex = next; } else { yield return(adj.Next.StartRotate(_pieceController.RotationZ)); UpdatePieceValue(_pieceController); GivePieceToPool(adj.Next); _pieces[next] = null; _lastIndex = index; } } }
Piece adjacentPieces(AdjacentPiece piece) { switch (piece) { case AdjacentPiece.Above: return above; case AdjacentPiece.Below: return below; case AdjacentPiece.LeftTop: return lefttop; case AdjacentPiece.LeftBottom: return leftbottom; case AdjacentPiece.RightTop: return righttop; case AdjacentPiece.RightBottom: return rightbottom; default: return null; } }