Ejemplo n.º 1
0
    }     // Update

    private void UpdateTileVisuals(int _x, int _y, int _tileColour, bool _highlightRemovedTiles)
    {
        // If _highlightRemovedTiles is true then we add a 'removed tile' prefab for any spaces that are now empty
        // but weren't at the last time this was called. Otherwise, empty spaces have no prefab.

        int  index          = _x + _y * Constants.EditableWidth;
        int  prevColour     = m_visibleLayout.GetColour(_x, _y);
        bool tileHasChanged = (prevColour != _tileColour) ||        // contents of tile has changed
                              ((_tileColour == 0) && (_highlightRemovedTiles || (m_tiles[index] != null)));                               // tile remains empty but we're possibly toggling whether to highlight it or not

        if (tileHasChanged)
        {
            m_visibleLayout.SetColour(_x, _y, _tileColour);

            if (m_tiles[index] != null)
            {
                GameObject.Destroy(m_tiles[index].gameObject);
            }
            if ((_tileColour > 0) || (_highlightRemovedTiles && (prevColour != 0)))
            {
                GameObject prefab = (_tileColour > 0) ? m_tilePrefabs[_tileColour - 1] : m_removedTilePrefab;
                m_tiles[index]               = GameObject.Instantiate(prefab).transform;
                m_tiles[index].parent        = m_groundTiles[index];
                m_tiles[index].localPosition = Vector3.zero;
                m_tiles[index].localRotation = Quaternion.identity;
            }
            else
            {
                m_tiles[index] = null;
            }
        }
    }
Ejemplo n.º 2
0
    }     // SwitchMode

    private void UpdateMapVisuals(MapLayout _layout, bool _highlightRemovedTiles)
    {
        for (int y = 0; y < Constants.EditableHeight; ++y)
        {
            for (int x = 0; x < Constants.EditableWidth; ++x)
            {
                UpdateTileVisuals(x, y, _layout.GetColour(x, y), _highlightRemovedTiles);
            }
        }
    }     // UpdateMapVisuals
Ejemplo n.º 3
0
    public void ScoreLayout(MapLayout _layout, out float o_score, out float o_gameScore)
    {
        float totalScore     = 0.0f;
        float totalGameScore = 0.0f;

        // Score individual cells:
        for (int y = 0; y < Constants.EditableHeight; ++y)
        {
            for (int x = 0; x < Constants.EditableWidth; ++x)
            {
                // We reduce the score of tiles adjacent to bedrock as well as non-empty tiles; empty spaces
                // around the edge of the board are considered less valuable as they're less likely to contain
                // buried items.
                if (_layout.GetColour(x, y) == Constants.Colour_Empty)
                {
                    int emptyCardinalNeighbours = (_layout.GetColour(x + 1, y) == Constants.Colour_Empty ? 1 : 0)
                                                  + (_layout.GetColour(x - 1, y) == Constants.Colour_Empty ? 1 : 0)
                                                  + (_layout.GetColour(x, y + 1) == Constants.Colour_Empty ? 1 : 0)
                                                  + (_layout.GetColour(x, y - 1) == Constants.Colour_Empty ? 1 : 0);
                    int emptyDiagonalNeighbours = (_layout.GetColour(x + 1, y + 1) == Constants.Colour_Empty ? 1 : 0)
                                                  + (_layout.GetColour(x - 1, y + 1) == Constants.Colour_Empty ? 1 : 0)
                                                  + (_layout.GetColour(x + 1, y - 1) == Constants.Colour_Empty ? 1 : 0)
                                                  + (_layout.GetColour(x - 1, y - 1) == Constants.Colour_Empty ? 1 : 0);
                    float cellScore = m_settings.EmptyCellScore;
                    float malus     = m_settings.BlockedCardinalAdjacentMalus * 0.25f * (4 - emptyCardinalNeighbours)
                                      + m_settings.BlockedDiagonalAdjacentMalus * 0.25f * (4 - emptyDiagonalNeighbours);
                    cellScore = Mathf.Max(0.0f, cellScore - malus);

                    float cellGameScore = ActualGameSettings.EmptyCellScore;
                    float gameMalus     = ActualGameSettings.BlockedCardinalAdjacentMalus * 0.25f * (4 - emptyCardinalNeighbours)
                                          + ActualGameSettings.BlockedDiagonalAdjacentMalus * 0.25f * (4 - emptyDiagonalNeighbours);
                    cellGameScore = Mathf.Max(0.0f, cellGameScore - gameMalus);

                    totalScore     += cellScore;
                    totalGameScore += cellGameScore;
                }
            }
        }

        // Score regions:
        for (int r = 0; r < m_priorityRegions.Count; ++r)
        {
            PriorityRegion region     = m_priorityRegions[r];
            bool           obstructed = false;
            for (int y = region.YMin; (y <= region.YMax) && !obstructed; ++y)
            {
                for (int x = region.XMin; x <= region.XMax; ++x)
                {
                    if (_layout.GetColour(x, y) != Constants.Colour_Empty)
                    {
                        obstructed = true;
                        break;
                    }
                }         // for every x
            }             // for every y
            if (!obstructed)
            {
                totalScore     += region.IsMajor ? m_settings.MajorRegionScore : m_settings.MinorRegionScore;
                totalGameScore += region.IsMajor ? ActualGameSettings.MajorRegionScore : ActualGameSettings.MinorRegionScore;
            }
        }         // for every region

        o_score     = totalScore;
        o_gameScore = totalGameScore;
    }     // ScoreLayout