bool CheckMatch(ShapesManager.CheckResult leftResult, ShapesManager.CheckResult rightResult) { bool isMatchL = leftResult.IsMatch(); bool isMatchR = rightResult.IsMatch(); return(isMatchL || isMatchR); }
void FireSwipeEvent(GameObject shapeObject, Constants.SwipeDirection swipeDirection) { Vector2 vec = shapesManager.GetRowColFromGameObject(shapeObject.transform.parent.gameObject); if (vec.x == -10f) { Debug.LogError("Destroy Something is Seriously wrong "); //GameObject.Destroy(shapeObject.transform.parent.gameObject); return; } int row = (int)vec.x; int col = (int)vec.y; // ask shape manager if can attemp to swap // this is dependent on if there is an edge or untouchable terrain bool validMove = shapesManager.IsValidMove(row, col, swipeDirection); if (validMove) { SoundManager.PlaySound("short_whoosh"); Shape shape = shapesManager.GetShape(row, col); Vector3 position = shapesManager.GetPositionOfBackgroundPiece(row, col); // get the other shape Vector2 nextRowCol = Constants.GetNextRowCol(swipeDirection, row, col); Shape nextShape = shapesManager.GetShape((int)nextRowCol.x, (int)nextRowCol.y); Vector3 nextPosition = shapesManager.GetPositionOfBackgroundPiece((int)nextRowCol.x, (int)nextRowCol.y); StartCoroutine( shape.AnimatePosition(nextPosition, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => { //CheckMatch(row, col, (int)nextRowCol.x, (int)nextRowCol.y); //CheckWholeBoard(); int nRow = (int)nextRowCol.x; int nCol = (int)nextRowCol.y; bool successfulSwap = shapesManager.SwapPieces(row, col, nRow, nCol); ShapesManager.CheckResult leftResult = shapesManager.CheckMatch(row, col); ShapesManager.CheckResult rightResult = shapesManager.CheckMatch(nRow, nCol); bool isMatch = CheckMatch(leftResult, rightResult); if (successfulSwap && !isMatch) { // also make a function SoundManager.PlaySound("button-29"); Constants.SwipeDirection oppositeDirection = Constants.GetOppositeDirection(currentSwipeDirection); Shape currentShape = shapesManager.GetShape(row, col); Shape nextShape1 = shapesManager.GetShape(nRow, nCol); Vector3 currentPosition = shapesManager.GetPositionOfBackgroundPiece(row, col); Vector3 nextPosition1 = shapesManager.GetPositionOfBackgroundPiece(nRow, nCol); StartCoroutine( currentShape.AnimatePosition(nextPosition, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => { shapesManager.SwapPieces(row, col, nRow, nCol); blockEvent = false; }) ); StartCoroutine( nextShape1.AnimatePosition(currentPosition, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => { Debug.Log("DAH"); }) ); } else { this.currentMoves--; UIManager.UpdateMoveValue(this.currentMoves, this.maxMoves); CheckWholeBoard(); } }) ); StartCoroutine( nextShape.AnimatePosition(position, Constants.DEFAULT_SWAP_ANIMATION_DURATION, () => { }) ); } }
void CheckWholeBoard() { Transform pieces = GameObject.Find("Pieces").transform; int childCount = pieces.childCount; for (int i = 0; i < childCount; i++) { Transform child = pieces.GetChild(i); Vector2 vec = shapesManager.GetRowColFromGameObject(child.gameObject); if (vec.x == 10f) { Debug.LogError("F**K"); } } var shapes = shapesManager.shapes; for (int row = 0; row < shapes.GetLength(0); row++) { for (int col = 0; col < shapes.GetLength(1); col++) { Shape shape = shapesManager.GetShape(row, col); Vector3 position = shapesManager.GetPositionOfBackgroundPiece(row, col); //shape.transform.position = position; } } List <Vector2> shapePositions = new List <Vector2>(); for (int row = 0; row < shapes.GetLength(0); row++) { for (int col = 0; col < shapes.GetLength(1); col++) { Debug.Log("Check whole board: " + row + " col: " + col); ShapesManager.CheckResult result = shapesManager.CheckMatch(row, col); if (result.IsMatch()) { Debug.Log("successfulSwap && isMatch"); SoundManager.PlaySound("match"); List <Vector2> tmpShapePositions = new List <Vector2>(); if (result.IsHorizontalMatch()) { tmpShapePositions = result.horizontalList; } if (result.IsVerticalMatch()) { tmpShapePositions = result.verticalList; } if (result.IsVerticalMatch() && result.IsHorizontalMatch()) { tmpShapePositions = result.GetMatchSet(); } foreach (var shape in tmpShapePositions) { if (!shapePositions.Contains(shape)) { shapePositions.Add(shape); } } } } } Disappear_Driver(shapePositions); if (shapePositions.Count == 0) { if (currentMoves == 0) { Debug.LogError("End the Match"); UIManager.Toggle(); } } else { //update score score += shapePositions.Count * Constants.NORMAL_SHAPE_VALUE; // TODO get shape value here UIManager.UpdateScoreValue(score); // multiple by amount per piece } return; }