示例#1
0
        public void SetColor(GridPiece gridPiece, bool random)
        {
            IColored cPiece = gridPiece.GetComponent <IColored>();

            if (cPiece == null)
            {
                return;
            }

            int columnIndex = (GridMap.Count - 1).GetColumn(mGridYLength);
            int rowIndex    = (GridMap.Count - 1).GetRow(mGridYLength);

            if (random || (columnIndex == 0) || ((columnIndex % 2 != 0) && (rowIndex == 0)))
            {
                int cI = UnityEngine.Random.Range(0, mColors.Length);
                cPiece.ChangeColor(cI, mColors[cI]);
                return;
            }

            List <IndexGroup> groupHolder = SelectableTriangles(gridPiece);
            int randomColorIndex          = UnityEngine.Random.Range(0, mColors.Length);

            cPiece.ColorIndex = randomColorIndex;
            if (groupHolder.CheckColorCount(this, 1) == true)
            {
                for (int i = 0; i < mColors.Length - 1; i++)
                {
                    randomColorIndex++;
                    if (randomColorIndex >= mColors.Length)
                    {
                        randomColorIndex -= mColors.Length;
                    }
                    cPiece.ColorIndex = randomColorIndex;
                    if (groupHolder.CheckColorCount(this, 1) == false)
                    {
                        break;
                    }
                }
            }
            cPiece.ChangeColor(randomColorIndex, mColors[randomColorIndex]);
            return;
        }
示例#2
0
    public void GiveAColorToTheCreatedHexagonalPiece(GridPiece gridPiece, bool random)
    {
        IColored cPiece = gridPiece.GetComponent <IColored> ();

        if (cPiece == null)
        {
            return;
        }
        int stunIndex  = (GridMap.Count - 1).GetColumnOfIndex(gridYLength);
        int satırIndex = (GridMap.Count - 1).GetRowOfIndex(gridYLength);

        if (random || (stunIndex == 0) || ((stunIndex % 2 != 0) && (satırIndex == 0)))
        {
            int cI = Random.Range(0, colors.Length);
            cPiece.ChangeColor(cI, colors [cI]);
            return;
        }
        List <IndexGroup> groupHolder = SelectableTrianglesOfaGridPiece(gridPiece);
        int randomColorIndex          = Random.Range(0, colors.Length);

        cPiece.ColorIndexOfThisPiece = randomColorIndex;
        if (groupHolder.CheckForGroupElementsHaveAGivenCountOfDifferentColor(1) == true)
        {
            for (int i = 0; i < colors.Length - 1; i++)
            {
                randomColorIndex++;
                if (randomColorIndex >= colors.Length)
                {
                    randomColorIndex -= colors.Length;
                }
                cPiece.ColorIndexOfThisPiece = randomColorIndex;
                if (groupHolder.CheckForGroupElementsHaveAGivenCountOfDifferentColor(1) == false)
                {
                    break;
                }
            }
        }
        cPiece.ChangeColor(randomColorIndex, colors [randomColorIndex]);
        return;
    }