コード例 #1
0
 public void ChangeTokenTypes()
 {
     if (tokens.Count == 4)
     {
         SwapPuzzleTokenController changedToken = tokens[1];
         foreach (SwapPuzzleTokenController con in tokens)
         {
             if (con.token.wasMoved)
             {
                 changedToken = con;
                 break;
             }
         }
         changedToken.type = TokenType.SPECIAL4;
         changedToken.hasJustChangedType = true;
         changedToken.token.wasMoved     = false;
     }
     else if (tokens.Count >= 5)
     {
         SwapPuzzleTokenController changedToken = tokens[0];
         foreach (SwapPuzzleTokenController con in tokens)
         {
             if (con.token.wasMoved)
             {
                 changedToken = con;
                 break;
             }
         }
         changedToken.type = TokenType.SPECIAL5;
         changedToken.hasJustChangedType = true;
         changedToken.token.wasMoved     = false;
     }
 }
コード例 #2
0
 public void Select(SwapPuzzleTokenController swapped)
 {
     if (selectedToken != null && swapped.token.IsNextTo(selectedToken.token))
     {
         SwapTokens(selectedToken, swapped);
     }
     else
     {
         selectedToken = swapped;
     }
 }
コード例 #3
0
    public void SwapTokens(SwapPuzzleTokenController cont1, SwapPuzzleTokenController cont2)
    {
        cont1.token.previousGridPosition = cont1.token.gridPosition;
        cont2.token.previousGridPosition = cont2.token.gridPosition;

        grid.SetTokenInGrid(cont1.token, cont2.token.previousGridPosition);
        grid.SetTokenInGrid(cont2.token, cont1.token.previousGridPosition);

        grid.UpdateTokenPosition(cont1.token, Settings.main.tokens.swapTime);
        grid.UpdateTokenPosition(cont2.token, Settings.main.tokens.swapTime);

        hasJustSwapped = true;
    }
コード例 #4
0
    public void SwapTokensBySwipe(SwapPuzzleTokenController token, Vector2Int direction)
    {
        if (direction.sqrMagnitude != 1)
        {
            return;
        }
        Vector2Int otherPos = token.token.gridPosition + direction;

        if (otherPos.x < 0 || otherPos.x >= grid.gridSize.x ||
            otherPos.y < 0 || otherPos.y >= grid.gridSize.y)
        {
            return;
        }

        SwapPuzzleTokenController otherToken = grid.tokens[otherPos.y, otherPos.x].GetComponent <SwapPuzzleTokenController>();

        SwapTokens(token, otherToken);
    }
コード例 #5
0
    public TokenChain FindMatches(SwapPuzzleTokenController cont, bool mustAddToChain = false)
    {
        TokenChain chain   = new TokenChain();
        bool       isAdded = !mustAddToChain;

        Vector2Int[] directions = new Vector2Int[] {
            Vector2Int.right, Vector2Int.up, Vector2Int.left, Vector2Int.down
        };

        foreach (Vector2Int dir in directions)
        {
            Vector2Int nearPos = cont.token.gridPosition + dir;
            if (grid.IsInsideGrid(nearPos))
            {
                var near = grid.tokens[nearPos.y, nearPos.x].GetComponent <SwapPuzzleTokenController>();
                // check nearest token
                if (!near.isChecking && near.token.elementId == cont.token.elementId)
                {
                    Vector2Int furtherPos = nearPos + dir;
                    Vector2Int backPos    = cont.token.gridPosition - dir;

                    if (grid.IsInsideGrid(furtherPos))
                    {
                        var further = grid.tokens[furtherPos.y, furtherPos.x].GetComponent <SwapPuzzleTokenController>();
                        if (further.token.elementId == cont.token.elementId)
                        {
                            if (!isAdded)
                            {
                                isAdded = true;
                                chain.Add(cont);
                            }

                            cont.isMatched    = true;
                            near.isMatched    = true;
                            further.isMatched = true;

                            bool checkNear = false, checkFurther = false;
                            if (!near.isChecking)
                            {
                                chain.Add(near);
                                near.isChecking = true;
                                checkNear       = true;
                            }

                            if (!further.isChecking)
                            {
                                chain.Add(further);
                                further.isChecking = true;
                                checkFurther       = true;
                            }

                            if (checkNear)
                            {
                                chain.Add(FindMatches(near));
                            }

                            if (checkFurther)
                            {
                                chain.Add(FindMatches(further));
                            }
                        }
                    }

                    if (grid.IsInsideGrid(backPos))
                    {
                        var back = grid.tokens[backPos.y, backPos.x].GetComponent <SwapPuzzleTokenController>();
                        if (back.token.elementId == cont.token.elementId)
                        {
                            if (!isAdded)
                            {
                                isAdded = true;
                                chain.Add(cont);
                            }

                            cont.isMatched = true;
                            near.isMatched = true;
                            back.isMatched = true;

                            bool checkNear = false, checkBack = false;
                            if (!near.isChecking)
                            {
                                chain.Add(near);
                                near.isChecking = true;
                                checkNear       = true;
                            }

                            if (!back.isChecking)
                            {
                                chain.Add(back);
                                back.isChecking = true;
                                checkBack       = true;
                            }

                            if (checkNear)
                            {
                                chain.Add(FindMatches(near));
                            }

                            if (checkBack)
                            {
                                chain.Add(FindMatches(back));
                            }
                        }
                    }
                }
            }
        }
        return(chain);
    }
コード例 #6
0
 public void Add(SwapPuzzleTokenController token)
 {
     tokens.Add(token);
 }