Beispiel #1
0
        private void CreateStacksOfType(Types.ContainerType containerType)
        {
            //Gets all the containers of a specific type
            List <Container> containersOfType = _toBeStackedContainers.FindAll(c => c.Type == containerType);

            foreach (var container in containersOfType)
            {
                bool containerIsAdded = false;
                //...and tries to place it in a stack...
                for (int i = 0; i < _containerStacks.Count && !containerIsAdded; i++)
                {
                    if (_containerStacks[i].StackContainer(container))
                    {
                        containerIsAdded = true;
                    }
                    //If it can't be placed onto any stack, create a new stack
                    else if (i == _containerStacks.Count - 1)
                    {
                        ContainerStack newStack = new ContainerStack(container);
                        _containerStacks.Add(newStack);
                        containerIsAdded = true;
                    }
                }
            }
        }
        private void buttonStack_Click(object sender, RoutedEventArgs e)
        {
            var button     = sender as Button;
            int stackIndex = (int)button.Tag;

            var parent      = button.Parent as ListBox;
            int parentIndex = (int)parent.Tag;

            ContainerStack selectedStack         = Ship.ColumnGrid[parentIndex].ContainerStacks[stackIndex];
            string         contentsSelectedStack = selectedStack.GetContentsAsString();

            MessageBox.Show(contentsSelectedStack);
        }
Beispiel #3
0
        public void AddStack(ContainerStack containerStack)
        {
            //Checks max rows dont get exceeded
            if (ContainerStacks.Count - 1 >= MaxRows)
            {
                throw new Exception("Max stacks reached");
            }

            //Sets the column to precious
            if (containerStack.IsPrecious == true)
            {
                ContainsPrecious = true;
            }

            //Adds the stack to the column and adds its weight
            ContainerStacks.Add(containerStack);
            TotalWeight += containerStack.GetTotalWeight();
        }
Beispiel #4
0
        public List <ContainerStack> StackContainers(List <Container> containers)
        {
            //Init list
            _containerStacks = new List <ContainerStack>();

            //Order toBeStackedContainers
            _toBeStackedContainers = containers;
            OrderContainersByWeight();
            //Inital stack
            ContainerStack initialStack = new ContainerStack(_toBeStackedContainers[0]);

            _containerStacks.Add(initialStack);

            //Remove intial container
            _toBeStackedContainers.Remove(_toBeStackedContainers[0]);

            CreateStacks();
            return(_containerStacks);
        }