Пример #1
0
        private void ModifySize(double temperature)
        {
            if (_random.NextDouble() > 0.5)
            {
                Width  += _random.Next(-1, 2);
                Height += _random.Next(-1, 2);

                if (Width < 5)
                {
                    Width = 5;
                }
                if (Height < 5)
                {
                    Height = 5;
                }
            }
            else
            {
                var xoff = _random.Next(-1, 2);
                var yoff = _random.Next(-1, 2);

                Width  += xoff;
                Height += yoff;

                if (Width < 5)
                {
                    Width = 5;
                }
                if (Height < 5)
                {
                    Height = 5;
                }

                var offset = new Vector2(xoff, yoff);
                var bounds = new Vector2(Width, Height);

                SourcePositions   = SourcePositions.SetItems(SourcePositions.Select((kvp) => new KeyValuePair <SourceStep, Vector2>(kvp.Key, VectorExtensions.Clamp(kvp.Value + offset, bounds))));
                SinkPositions     = SinkPositions.SetItems(SinkPositions.Select((kvp) => new KeyValuePair <SinkStep, Vector2>(kvp.Key, VectorExtensions.Clamp(kvp.Value + offset, bounds))));
                BuildingPositions = BuildingPositions.SetItems(BuildingPositions.Select((kvp) => new KeyValuePair <ProductionStep, Tuple <Vector2, BuildingRotation> >(kvp.Key, new Tuple <Vector2, BuildingRotation>(kvp.Value.Item1 + offset, kvp.Value.Item2))));
            }
        }