Ejemplo n.º 1
0
        private IEnumerator ShuffleBoard()
        {
            yield return(new WaitForSeconds(0.5f));

            List <GameObject> newBoard           = new List <GameObject>();
            List <Vector2>    currentObstaclePos = new List <Vector2>();

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (dots[i, j] != null)
                    {
                        if (dots[i, j].tag == "Obstacle")
                        {
                            currentObstaclePos.Add(new Vector2(i, j));
                        }
                        else
                        {
                            newBoard.Add(dots[i, j]);
                        }
                    }
                }
            }

            bool canShuffle = true;

            yield return(new WaitForSeconds(0.5f));

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (!blankSpaces[i, j])
                    {
                        canShuffle = true;

                        for (int k = 0; k < currentObstaclePos.Count; k++)
                        {
                            if (i == currentObstaclePos[k].x && j == currentObstaclePos[k].y)
                            {
                                canShuffle = false;
                            }
                        }

                        if (canShuffle)
                        {
                            int pieceToUse   = Random.Range(0, newBoard.Count);
                            int maxIteration = 0;

                            while (MatchesAt(i, j, newBoard[pieceToUse]) && maxIteration < 100)
                            {
                                pieceToUse = Random.Range(0, newBoard.Count);

                                maxIteration++;
                                Debug.Log(maxIteration);
                            }
                            maxIteration = 0;

                            Dot piece = newBoard[pieceToUse].GetComponent <Dot>();

                            piece.column = i;
                            piece.row    = j;
                            dots[i, j]   = newBoard[pieceToUse];
                            newBoard.Remove(newBoard[pieceToUse]);
                        }
                    }
                }
            }

            if (IsDeadLocked())
            {
                ShuffleBoard();
            }
        }
Ejemplo n.º 2
0
    public void CheckNearDots_Normal()
    {
        Normal.Dot   dot         = this.gameObject.GetComponent <Normal.Dot>();
        Normal.Board normalBoard = board.GetComponent <Normal.Board>();

        if (dot != null)
        {
            if (count <= 0)
            {
                // 보드에서 장애물 갯수를 하나 줄이고
                normalBoard.obstacles.Dequeue();
                // 나의 매치 상태를 true로 -> 사라질때 처리를 Dot과 한꺼번에
                dot.isMatched = true;
            }

            if (dot.column - 1 > 0)
            {
                if (normalBoard.dots[dot.column - 1, dot.row] != null && normalBoard.dots[dot.column - 1, dot.row].GetComponent <Normal.Dot>() != null)
                {
                    if (normalBoard.dots[dot.column - 1, dot.row].GetComponent <Normal.Dot>().isMatched == true)
                    {
                        this.gameObject.GetComponent <SpriteRenderer>().color *= 0.6f;
                        count--;

                        return;
                    }
                }
            }
            if (dot.column + 1 < normalBoard.width)
            {
                if (normalBoard.dots[dot.column + 1, dot.row] != null && normalBoard.dots[dot.column + 1, dot.row].GetComponent <Normal.Dot>() != null)
                {
                    if (normalBoard.dots[dot.column + 1, dot.row].GetComponent <Normal.Dot>().isMatched == true)
                    {
                        this.gameObject.GetComponent <SpriteRenderer>().color *= 0.6f;
                        count--;

                        return;
                    }
                }
            }
            if (dot.row - 1 > 0)
            {
                if (normalBoard.dots[dot.column, dot.row - 1] != null && normalBoard.dots[dot.column, dot.row - 1].GetComponent <Normal.Dot>() != null)
                {
                    if (normalBoard.dots[dot.column, dot.row - 1].GetComponent <Normal.Dot>().isMatched == true)
                    {
                        this.gameObject.GetComponent <SpriteRenderer>().color *= 0.6f;
                        count--;

                        return;
                    }
                }
            }
            if (dot.row + 1 < normalBoard.height)
            {
                if (normalBoard.dots[dot.column, dot.row + 1] != null && normalBoard.dots[dot.column, dot.row + 1].GetComponent <Normal.Dot>() != null)
                {
                    if (normalBoard.dots[dot.column, dot.row + 1].GetComponent <Normal.Dot>().isMatched == true)
                    {
                        this.gameObject.GetComponent <SpriteRenderer>().color *= 0.6f;
                        count--;

                        return;
                    }
                }
            }
        }
    }
Ejemplo n.º 3
0
 void CheckToMakeBombs()
 {
     if (mFindMatches.currentMatches.Count == 4 || mFindMatches.currentMatches.Count == 7)
     {
         mFindMatches.CheckBombs();
     }
     if (mFindMatches.currentMatches.Count == 5 || mFindMatches.currentMatches.Count == 8)
     {
         if (ColumnOrRow())
         {
             if (currentDot != null)
             {
                 if (currentDot.isMatched)
                 {
                     if (!currentDot.isColorBomb)
                     {
                         currentDot.isMatched = false;
                         currentDot.MakeColorBomb();
                     }
                 }
                 else
                 {
                     if (currentDot.mOtherDot != null)
                     {
                         Dot otherDot = currentDot.mOtherDot.GetComponent <Dot>();
                         if (otherDot.isMatched)
                         {
                             if (!otherDot.isColorBomb)
                             {
                                 otherDot.isMatched = false;
                                 otherDot.MakeColorBomb();
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             if (currentDot != null)
             {
                 if (currentDot.isMatched)
                 {
                     if (!currentDot.isAdjacentBomb)
                     {
                         currentDot.isMatched = false;
                         currentDot.MakeAdjacentBomb();
                     }
                 }
                 else
                 {
                     if (currentDot.mOtherDot != null)
                     {
                         Dot otherDot = currentDot.mOtherDot.GetComponent <Dot>();
                         if (otherDot.isMatched)
                         {
                             if (!otherDot.isAdjacentBomb)
                             {
                                 otherDot.isMatched = false;
                                 otherDot.MakeAdjacentBomb();
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        private IEnumerator FindAllMatchesCo()
        {
            yield return(new WaitForSeconds(0.2f));

            for (int i = 0; i < mBorad.width; i++)
            {
                for (int j = 0; j < mBorad.height; j++)
                {
                    GameObject currentDot = mBorad.dots[i, j];

                    if (currentDot != null && currentDot.gameObject.tag != "Obstacle")
                    {
                        Dot currentDotDot = currentDot.GetComponent <Dot>();
                        if (i > 0 && i < mBorad.width - 1)
                        {
                            GameObject leftDot  = mBorad.dots[i - 1, j];
                            GameObject rightDot = mBorad.dots[i + 1, j];

                            if (leftDot != null && rightDot != null)
                            {
                                Dot leftDotDot  = leftDot.GetComponent <Dot>();
                                Dot rightDotDot = rightDot.GetComponent <Dot>();

                                if (leftDot.tag == currentDot.tag && rightDot.tag == currentDot.tag)
                                {
                                    currentMatches.Union(IsRowBomb(leftDotDot, currentDotDot, rightDotDot));

                                    currentMatches.Union(IsColumnBomb(leftDotDot, currentDotDot, rightDotDot));

                                    currentMatches.Union(IsAdjacentBomb(leftDotDot, currentDotDot, rightDotDot));

                                    GetNearbyPieces(leftDot, currentDot, rightDot);
                                }
                            }
                        }
                        if (j > 0 && j < mBorad.height - 1)
                        {
                            GameObject upDot   = mBorad.dots[i, j + 1];
                            GameObject downDot = mBorad.dots[i, j - 1];

                            if (upDot != null && downDot != null)
                            {
                                Dot upDotDot   = upDot.GetComponent <Dot>();
                                Dot downDotDot = downDot.GetComponent <Dot>();

                                if (upDot.tag == currentDot.tag && downDot.tag == currentDot.tag)
                                {
                                    currentMatches.Union(IsColumnBomb(upDotDot, currentDotDot, downDotDot));

                                    currentMatches.Union(IsRowBomb(upDotDot, currentDotDot, downDotDot));

                                    currentMatches.Union(IsAdjacentBomb(upDotDot, currentDotDot, downDotDot));

                                    GetNearbyPieces(upDot, currentDot, downDot);
                                }
                            }
                        }
                    }
                }
            }
        }