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


C# Range.Random方法代码示例

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


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

示例1: RenderConnection

        private void RenderConnection()
        {
            foreach (var room in Graph.Rooms)
            {
                var xRange = new Range(room.Width * 1 / 4, room.Width * 3 / 4);
                var yRange = new Range(room.Height * 1 / 4, room.Height * 3 / 4);
                var pt = new Point(room.Pos.X + xRange.Random(Rand), room.Pos.Y + yRange.Random(Rand));

                foreach (var edge in room.Edges)
                {
                    var direction = edge.Linkage.Direction;
                    var randOffset = edge.Linkage.Offset + edge.Linkage.Offset % 3;

                    if (edge.RoomA != room)
                        direction = direction.Reverse();
                    else if (edge.RoomB is BossRoom)
                    {
                        RenderBossEdge(edge.RoomA, edge.RoomB, direction, randOffset);
                    }
                    else if (edge.RoomA is BossRoom)
                    {
                        RenderBossEdge(edge.RoomB, edge.RoomA, direction.Reverse(), randOffset);
                    }

                    if (room is BossRoom)
                        continue;

                    Point pos;
                    switch (direction)
                    {
                        case Direction.North:
                            pos = new Point(randOffset, room.Pos.Y);
                            break;

                        case Direction.South:
                            pos = new Point(randOffset, room.Pos.Y + room.Height);
                            break;

                        case Direction.West:
                            pos = new Point(room.Pos.X, randOffset);
                            break;

                        case Direction.East:
                            pos = new Point(room.Pos.X + room.Width, randOffset);
                            break;

                        default:
                            throw new ArgumentException();
                    }
                    RenderLavaGround(pos, pt);
                }

                if (room is StartRoom)
                    RenderLavaGround(((StartRoom)room).portalPos, pt);
            }
        }
开发者ID:OryxAwakening,项目名称:Fabiano_Swagger_of_Doom,代码行数:56,代码来源:Overlay.cs

示例2: Randomize

		////////////////////////////////////////////////////////////////////////////////
		/// <summary> </summary>

		public bool Randomize (Range sensors, Range angle, Range orient, Range range, bool constrain)
		{
			int amount = sensors.Random();
			if (amount <= 0 || amount > 1000)
				return false;

			int viewX1 = 0;
			int viewY1 = 0;
			int viewX2 = (int) ActualWidth;
			int viewY2 = (int) ActualHeight;

			if (constrain)
			{
				var parent = (ScrollViewer) Parent;

				viewX1 = (int) parent.ContentHorizontalOffset;
				viewY1 = (int) parent.ContentVerticalOffset;
				viewX2 = (int) parent.ActualWidth  + viewX1;
				viewY2 = (int) parent.ActualHeight + viewY1;
			}

			for (int i = 0; i < amount; ++i)
			{
				float x = mRandom.Next (viewX1 + 5, viewX2 - 5);
				float y = mRandom.Next (viewY1 + 5, viewY2 - 5);

				float a = angle.Random();
				float r = range.Random();
				float o = orient.Random();

				if (a < 0 || r < 0 || o < 0 || r > 1000)
					return false;

				AddSensor (new Sensor (x, y, a, r, o));
			}

			return true;
		}
开发者ID:dkrutsko,项目名称:Sensor-Simulator,代码行数:41,代码来源:GraphCanvas.cs


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