当前位置: 首页>>代码示例>>C#>>正文


C# Container.GetNonShippedContainerList方法代码示例

本文整理汇总了C#中System.ComponentModel.Container.GetNonShippedContainerList方法的典型用法代码示例。如果您正苦于以下问题:C# Container.GetNonShippedContainerList方法的具体用法?C# Container.GetNonShippedContainerList怎么用?C# Container.GetNonShippedContainerList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ComponentModel.Container的用法示例。


在下文中一共展示了Container.GetNonShippedContainerList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnGenerate_Click

        //Generate the correct mapping
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            //Check if ship and destination is selected otherwise stop
            if(cbTypeShip.SelectedIndex == -1 ||  cbDestination.SelectedIndex == -1)
            {
                return;
            }

            Container container = new Container();

            //Get select freighter and destination from combobox
            freighter = freighters[cbTypeShip.SelectedIndex];
            destination = destinations[cbDestination.SelectedIndex];

            //Clear incase of multiple runs
            availableContainers.Clear();
            placedContainers.Clear();

            //Get all available containers
            availableContainers = container.GetNonShippedContainerList();

            //Get the max amount of spots on a ship
            int totalSpots = freighter.maxHeight * freighter.containerRows * freighter.containersEachRow;

            //Get the max amount of power supply on a ship
            int availablePowerSupply = freighter.powerSupply;

            //Sort the containers so the chilled containers are first
            availableContainers = availableContainers.OrderByDescending(o => o.containerType.chilled).ThenBy(o => o.containerType.chilled).ThenBy(o => o.weight).ToList();

            //Remember count value
            int countX = 1;
            int countY = 1;
            int countZ = 1;
            int y;
            int x;
            int z;
            bool excists;

            //For every container in available containers
            foreach(Container con in availableContainers)
            {
                countZ = 1;

                //Continue to check
                while(true)
                {
                    //If all spots have been filled close
                    if (placedContainers.Count == totalSpots)
                            break;

                    //If a container is valuable make sure it can never be placed on the sides
                    if (con.containerType.valuable == 1 && countX == freighter.containerRows)
                    {
                        countX = 2;
                        if (countY == freighter.containersEachRow)
                        {
                            countZ++;
                            countY = 0;
                        }
                        countY++;

                        Container priority = new Container();
                        priority.positionX = countX;
                        priority.positionY = countY;
                        priority.positionZ = countZ + 1;
                        prioritys.Add(priority);
                    }

                    //If there is a priority position fill that one first otherwise normal position
                    if (con.containerType.valuable == 0 && con.containerType.valuable == 0 && prioritys.Count > 0)
                    {
                        y = prioritys[0].positionY;
                        x = prioritys[0].positionX;
                        z = prioritys[0].positionZ;

                        prioritys.RemoveAt(0);
                    }
                    else
                    {
                        y = countY;
                        x = countX;
                        z = countZ;
                    }

                    //Check if the given container position is valid
                    excists = CheckIfPositionIsValid(x, y, z);

                    //if its valid add the container to to the placed list
                    if (!excists)
                    {
                        con.positionX = x;
                        con.positionY = y;
                        con.positionZ = z;
                        placedContainers.Add(con);

                        if (con.containerType.chilled == 1)
                        availablePowerSupply--;

//.........这里部分代码省略.........
开发者ID:BSpartan,项目名称:Container-Shipping-Company,代码行数:101,代码来源:mappingForm.cs


注:本文中的System.ComponentModel.Container.GetNonShippedContainerList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。