コード例 #1
0
ファイル: GameGrid.cs プロジェクト: hanoelleb/ThreeInARow
    IEnumerator NoMatchCoroutine(int currIndex, int upIndex)
    {
        canClick = false;
        current  = null;
        checking = false;

        Gem currGem = gameGrid[currIndex].getGem();
        Gem upGem   = gameGrid[upIndex].getGem();

        Transform currGemTrans = gameGrid[currIndex].getGemTransform();
        Transform upGemTrans   = gameGrid[upIndex].getGemTransform();

        //yield on a new YieldInstruction that waits for 5 seconds.
        yield return(new WaitForSeconds(0.5f));

        currGemTrans.parent = gameGrid[upIndex].gameObject.transform;
        upGemTrans.parent   = gameGrid[currIndex].gameObject.transform;

        gameGrid[upIndex].setGem(currGem);
        gameGrid[currIndex].setGem(upGem);

        noMatch.Play();

        canClick = true;
        checking = true;
    }
コード例 #2
0
ファイル: GameGrid.cs プロジェクト: hanoelleb/ThreeInARow
    public void setCurrent(gameTile update)
    {
        if (current != null)
        {
            int currIndex = current.getIndex();
            int upIndex   = update.getIndex();

            bool isAdjacent = false;

            if ((upIndex == currIndex + 1 && upIndex % GRIDSIZE != 0) ||              //to right
                (upIndex == currIndex - 1 && upIndex % GRIDSIZE != 5) ||              //to left
                (upIndex == currIndex - GRIDSIZE || upIndex == currIndex + GRIDSIZE)) //top or bottom
            {
                isAdjacent = true;
                current.setSelected(false);
                current = null;
            }

            if (!isAdjacent)
            {
                current.setSelected(false);
                current = update;
                current.setSelected(true);
            }
            else
            {
                Gem currGem = gameGrid[currIndex].getGem();
                Gem upGem   = gameGrid[upIndex].getGem();

                Transform currGemTrans = gameGrid[currIndex].getGemTransform();
                Transform upGemTrans   = gameGrid[upIndex].getGemTransform();

                currGemTrans.parent = gameGrid[upIndex].gameObject.transform;
                upGemTrans.parent   = gameGrid[currIndex].gameObject.transform;

                gemSwap.Play();

                gameGrid[upIndex].setGem(currGem);
                gameGrid[currIndex].setGem(upGem);

                HashSet <int> matches = checkBoard(false);
                if (matches.Count == 0)
                {
                    StartCoroutine(NoMatchCoroutine(currIndex, upIndex));
                }
                else
                {
                    StartCoroutine(MoveDownCoroutine());
                }
            }
        }
        else
        {
            current = update;
            current.setSelected(true);
        }
    }
コード例 #3
0
ファイル: GameGrid.cs プロジェクト: hanoelleb/ThreeInARow
    bool checkAnyMoves()
    {
        bool noMoves = false;

        gameTile[] checkGrid = new gameTile[36];

        //CHECK HORIZONTAL SWAPS
        Array.Copy(gameGrid, 0, checkGrid, 0, checkGrid.Length);
        for (int i = 35; i >= 0; i--)
        {
            if (i % GRIDSIZE >= 5)
            {
                continue;
            }

            gameTile temp = checkGrid[i];
            checkGrid[i]     = checkGrid[i + 1];
            checkGrid[i + 1] = temp;

            //only need to check this row if swapping horizontally
            int  rowNum   = getRowNum(i);
            bool horiMove = checkHori(rowNum, checkGrid);
            if (horiMove)
            {
                return(true);
            }

            //for i column
            bool vertMove = checkVert(i % 6, checkGrid);

            //for i+1 column
            bool vertMove2 = checkVert((i + 1) % 6, checkGrid);

            if (vertMove || vertMove2)
            {
                return(true);
            }

            //SWAP BACK AFTER
            gameTile temp2 = checkGrid[i];
            checkGrid[i]     = checkGrid[i + 1];
            checkGrid[i + 1] = temp2;
        }

        //CHECK VERTICAL SWAPS
        Array.Copy(gameGrid, 0, checkGrid, 0, checkGrid.Length);
        for (int i = 35; i >= 0; i--)
        {
            if (i > 29)
            {
                continue;
            }

            gameTile temp = checkGrid[i];
            checkGrid[i]            = checkGrid[i + GRIDSIZE];
            checkGrid[i + GRIDSIZE] = temp;

            //only need to check this column if swapping vertically
            bool vertMove = checkVert(i % 6, checkGrid);

            if (vertMove)
            {
                return(true);
            }

            int rowNum = getRowNum(i);

            if (i % GRIDSIZE < 5)
            {
                bool horiMove = checkHori(rowNum, checkGrid);
                if (rowNum < 30)
                {
                    bool horiMove2 = checkHori(rowNum + 6, checkGrid);
                    if (horiMove || horiMove2)
                    {
                        return(true);
                    }
                }
                if (horiMove)
                {
                    return(true);
                }
            }

            //SWAP BACK AFTER
            gameTile temp2 = checkGrid[i];
            checkGrid[i]            = checkGrid[i + GRIDSIZE];
            checkGrid[i + GRIDSIZE] = temp2;
        }

        return(noMoves);
    }