コード例 #1
0
        void changeCellOwner(int cellIndex)
        {
            int currentTerritory = tgs.cells [cellIndex].territoryIndex;
            // Looks for a neighbour territory
            List <Cell> neighbours = tgs.CellGetNeighbours(cellIndex);

            for (int k = 0; k < neighbours.Count; k++)
            {
                if (neighbours [k].territoryIndex != currentTerritory)
                {
                    currentTerritory = neighbours [k].territoryIndex;
                    break;
                }
            }

            if (tgs.CellGetTerritoryIndex(cellIndex) != currentTerritory)
            {
                tgs.CellSetTerritory(cellIndex, currentTerritory);
            }
            else
            {
                // get cells on the frontier
                tgs.TerritoryGetFrontierCells(currentTerritory, ref cellIndices);
                tgs.CellFlash(cellIndices, Color.white, 2f);
            }
        }
コード例 #2
0
        void CheckMatchingCells(int cellIndex, int buttonIndex)
        {
            if (cellIndex < 0)
            {
                return;
            }

            Texture2D selectedFruit = grid.CellGetTexture(cellIndex);

            if (selectedFruit == null)
            {
                return;                 // empty cell
            }
            // Checks all directions until all matches are selected and no pending cells remains
            List <int> matches = new List <int> ();

            matches.Add(cellIndex);
            List <int> pending = new List <int> ();

            pending.Add(cellIndex);

            while (pending.Count > 0)
            {
                // extract one fruit from the queue
                int p = pending [0];
                pending.RemoveAt(0);
                // check all 4 directions of that cell for new matches
                int row = grid.CellGetRow(p);
                int col = grid.CellGetColumn(p);
                for (int k = 0; k < directions.Length; k++)
                {
                    int row1 = row + directions [k] [0];
                    int col1 = col + directions [k] [1];
                    if (row1 >= 0 && row1 < grid.rowCount && col1 >= 0 && col1 < grid.columnCount)
                    {
                        int       i   = grid.CellGetIndex(row1, col1);
                        Texture2D tex = grid.CellGetTexture(i);
                        if (tex == selectedFruit && !matches.Contains(i))
                        {
                            matches.Add(i);
                            pending.Add(i);
                        }
                    }
                }
            }

            // If there're 3 or more matches remove them
            if (matches.Count >= 3)
            {
                matches.ForEach((int matchingIndex) => {
                    // Remove fruit
                    grid.CellSetTexture(matchingIndex, null);
                    // Produce a nice effect for matching cells
                    grid.CellFlash(matchingIndex, Color.black, Color.yellow, 0.25f);
                });
                StartCoroutine(MakeFruitsFall());
            }
        }
コード例 #3
0
        void ShowRange(bool useLineOfSight = false)
        {
            List <int> neighbours = tgs.CellGetNeighbours(tgs.cellHighlightedIndex, 6, CELLS_ALL_NAVIGATABLE);

            if (neighbours != null)
            {
                if (useLineOfSight)
                {
                    tgs.CellTestLineOfSight(tgs.cellHighlightedIndex, neighbours, CELLS_ALL_NAVIGATABLE);
                }
                tgs.CellFlash(neighbours, Color.yellow, 1f);
            }
        }