Exemple #1
0
    public override void Execute()
    {
        _floodWaterTilesCommand = new FloodWaterTilesCommand();
        _floodWaterTilesCommand.Execute();

        _floodClusterCommands = new Stack <FloodClusterCommand>();
        _pumpWaterCommands    = new Stack <PumpWaterClusterCommand>();
        List <WaterCluster> clustersToFlood = new List <WaterCluster>();

        // Flooding may change the clusters list
        // Thus, we can't do it in this foreach, because we use its enumerator
        foreach (WaterCluster cluster in WaterClusterManager.Instance.clusters)
        {
            cluster.RecountFloodLevel();

            PumpWaterClusterCommand pumpCommand = new PumpWaterClusterCommand(cluster);
            pumpCommand.Execute();
            _pumpWaterCommands.Push(pumpCommand);

            if (cluster.FloodLevel >= WaterClusterManager.floodThreshold)
            {
                clustersToFlood.Add(cluster);
            }
        }
        foreach (WaterCluster cluster in clustersToFlood)
        {
            FloodClusterCommand floodClusterCommand = new FloodClusterCommand(cluster);
            floodClusterCommand.Execute();
            _floodClusterCommands.Push(floodClusterCommand);
        }
        _recreateClustersCommand = new CreateClustersCommand();
        _recreateClustersCommand.Execute();
    }
    public override void Execute()
    {
        WaterClusterManager.Instance.ClearPossibleFloodTiles();
        FloodWaterTilesCommand temporaryFloodCommand = new FloodWaterTilesCommand();

        temporaryFloodCommand.Execute();
        foreach (WaterCluster cluster in WaterClusterManager.Instance.clusters)
        {
            cluster.RecountFloodLevel();
            if (cluster.FloodLevel >= WaterClusterManager.floodThreshold)
            {
                int neighboursToFlood = cluster.FloodLevel / WaterClusterManager.floodThreshold;
                for (int i = 0; i < neighboursToFlood; i++)
                {
                    WaterClusterManager.Instance.RegisterRandomFloodableTile(cluster);
                }
            }
        }
        temporaryFloodCommand.Undo();
    }