示例#1
0
        /// <summary>
        /// Adds new container to the storage
        /// </summary>
        /// <param name="container">Container to add</param>
        /// <returns>True if everything is ok, false if container.Cost lower or equals ContainerCost</returns>
        public bool AddContainer(Container container)
        {
            container.DamageCoefficient = Random.NextDouble() / 2;
            container.Id = _containerId;

            if (container.Cost <= ContainerCost)
            {
                return(false);
            }

            _containerId++;
            if (ContainersCount != Containers.Length)
            {
                for (var i = 0; i < Containers.Length; i++)
                {
                    if (Containers[i] != null)
                    {
                        continue;
                    }

                    Containers[i] = container;
                    ContainersCount++;

                    return(true);
                }
            }

            var minId = Containers.Min(x => x.Id);

            for (var i = 0; i < Containers.Length; i++)
            {
                if (Containers[i].Id != minId)
                {
                    continue;
                }

                Containers[i] = container;
                ContainersCount++;

                break;
            }

            return(true);
        }