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


C# Orientation.Equals方法代码示例

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


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

示例1: setShip

        /// <summary>
        /// Sets the chosen ship based on the button selected, if the ship cannot legally be placed on chosen button, an error message is shown
        /// </summary>
        /// <param name="ship">The ship to be placed</param>
        /// <param name="index">The index of the button chosen in the button field</param>
        /// <param name="orientation">The orientation of the ship to be placed</param>
        /// <param name="isRandomized">Whether or not the player chose to randomize the ship placement</param>
        public bool setShip(Ship ship, int index, Orientation orientation, bool isRandomized = false, bool isComputerPlacement = false)
        {
            int size = ship.size;
            int[] chosenButtonIndexes = new int[size];

            // Orientation is horizontal
            if (orientation.Equals(Orientation.HORIZONTAL))
            {
                // If placed in two rows
                if (((index + (size - 1)) % 10 < size - 1))
                {
                    int counter = 0;
                    int reverseCounter = 1;

                    while ((index + counter) % 10 > 1)
                    {
                        chosenButtonIndexes[counter] = index + counter;
                        counter++;
                    }
                    for (int i = counter; i < size; i++)
                    {
                        chosenButtonIndexes[i] = index - reverseCounter;
                        reverseCounter++;
                    }
                }
                // If placed in one row
                else
                {
                    for (int i = 0; i < size; i++)
                    {
                        chosenButtonIndexes[i] = index + i;
                    }
                }
            }
            // Orientation is vertical
            else
            {
                // If placed in two columns
                if (index + (size * 10) > 100)
                {
                    int counter = 0;
                    int reverseCounter = 10;

                    while ((index / 10 + counter) % 100 < 10)
                    {
                        chosenButtonIndexes[counter] = index + counter * 10;
                        counter++;
                    }
                    for (int i = counter; i < size; i++)
                    {
                        chosenButtonIndexes[i] = index - reverseCounter;
                        reverseCounter += 10;
                    }
                }
                // If placed in one column
                else
                {
                    for (int i = 0; i < size; i++)
                    {
                        chosenButtonIndexes[i] = index + (i * 10);
                    }
                }
            }

            bool isValidPlacement = true;

            // Invalid placement check
            for (int i = 0; i < size; i++)
            {
                if (buttons[chosenButtonIndexes[i]].Tag != null)
                {
                    isValidPlacement = false;
                }
            }

            if (isValidPlacement)
            {
                // Sort array
                Array.Sort(chosenButtonIndexes);

                // Update ship
                ship.orientation = orientation;
                ship.location = new List<int>(chosenButtonIndexes);
                ship.placed = true;

                if (!isComputerPlacement)
                {
                    ship.item.IsEnabled = false;
                }

                // Set image
                // For some reason, if not done twice and ship is vertical, the image displayed is smaller than intended
                setImage(chosenButtonIndexes[0], ship, isComputerPlacement);
//.........这里部分代码省略.........
开发者ID:jeegnathebug,项目名称:BattleShip,代码行数:101,代码来源:Common.cs


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