Exemple #1
0
    private void GetDestructionPrediction()
    {
        _destructionPrediction.Clear();
        for (int i = 0; i < _dragTiles.Count; i++)
        {
            Vector3 pos     = _dragTiles[i].transform.position;
            Vector3 linePos = new Vector3(pos.x, pos.y, -0.5f);
            _line.SetPosition(i, linePos);
            _destructionPrediction.Add(_dragTiles[i].GetComponent <HexTile>());
        }

        float   boosterCount  = 0;
        int     boosterType   = 0;
        HexTile sampleBooster = null;

        for (int i = 0; i < _destructionPrediction.Count; i++)
        {
            _destructionPrediction[i].GetComponent <HexTile>().selected = true;

            if (_destructionPrediction[i].GetComponent <BoosterThreeHexTile>())
            {
                boosterCount++;
                if (boosterType < 3)
                {
                    boosterType   = 3;
                    sampleBooster = _destructionPrediction[i];
                }
            }
            else if (_destructionPrediction[i].GetComponent <BoosterTwoHexTile>())
            {
                boosterCount++;
                if (boosterType < 2)
                {
                    boosterType   = 2;
                    sampleBooster = _destructionPrediction[i];
                }
            }
            else if (_destructionPrediction[i].GetComponent <BoosterOneHexTile>())
            {
                boosterCount++;
                if (boosterType < 1)
                {
                    boosterType   = 1;
                    sampleBooster = _destructionPrediction[i];
                }
            }
        }
        int last = _destructionPrediction.Count - 1;

        if (boosterType == 3)
        {
            sampleBooster.gameObject.GetComponent <BoosterThreeHexTile>().PredictExplosion(_gameboard.GetComponent <HexGrid>(), boosterCount, _destructionPrediction[last].xy);
        }
        if (boosterType == 2)
        {
            sampleBooster.gameObject.GetComponent <BoosterTwoHexTile>().PredictExplosion(_gameboard.GetComponent <HexGrid>(), boosterCount, _destructionPrediction[last].xy);
        }
        if (boosterType == 1)
        {
            sampleBooster.gameObject.GetComponent <BoosterOneHexTile>().PredictExplosion(_gameboard.GetComponent <HexGrid>(), boosterCount, _destructionPrediction[last].xy);
        }

        bool affectedTilesChanged = true;
        int  tries = 30;
        bool abort = false;

        for (int i = 0; i < tries; i++)
        {
            if (!abort)
            {
                List <HexTile> affectedTiles = _gridController.AllSelectedTilesAsHexTile();
                affectedTilesChanged = IterateCollateral(affectedTiles, affectedTiles.Count);
                if (!affectedTilesChanged)
                {
                    abort = true;
                }
            }
        }

        RootController.Instance.GetMyPlayerEntity().HandleSelectionData(_gridController.AllSelectedTilesAsHexTile());
    }