public void Draw() { Point currentAspectSize = AspectSize; if (currentAspectSize <= Point.Zero) { return; } if (currentAspectSize != lastAspectSize) { Bitmap = ResizeBitmap(Bitmap, currentAspectSize); } lastAspectSize = currentAspectSize; System.Drawing.Point PointZero = Point.Zero.ToPoint(); using Graphics graphics = Graphics.FromImage(Bitmap); graphics.Clear(Color.White); ILayer[] layers = Layers.ToArray().ToArray(); layers.Action( (i, layer) => { if (layer.Bitmap == null) { layer.Bitmap = new Bitmap(currentAspectSize.X, currentAspectSize.Y); } else if (new Point(layer.Bitmap.Size) != currentAspectSize) { layer.Bitmap = ResizeBitmap(layer.Bitmap, currentAspectSize); } layer.OnBeginDraw(); } ); int[] LayerHeights = layers.SelectMany(layer => layer.LayerHeights) .Distinct() .OrderBy(layerHeight => layerHeight) .ToArray(); LayerHeights.Action( (layerHeightIndex, layerHeight) => { ILayer[] layersWithinHeight = Layers.Where(layer => layer.LayerHeights.Contains(layerHeight)).ToArray(); layersWithinHeight.Action( (layerArrayIndex, layer) => { layer.OnBeginLayer(layerHeight); layer.MapObjects.ToArray().Action( (mapObjectArrayIndex, mapObject) => layer.OnDraw(layerHeight, mapObject) ); graphics.DrawImage(layer.Bitmap, PointZero); } ); } ); layers.Action((i, v) => v.OnEndDraw()); }
public PathFinderNode FindPath(Point Begin, Point End) { PathFinderNode[,] nodeGrid = new PathFinderNode[Map.Bounds.X, Map.Bounds.Y]; nodeGrid.Function((x, y, v) => new PathFinderNode(Map[new Point(x, y)])); Map.MapObjects.ToArray().Action( (i, mapObject) => { if (mapObject.IsWall) { nodeGrid[mapObject.Point.X, mapObject.Point.Y].Blocked = true; } } ); nodeGrid.Action( (x, y, node) => node.AdjacentNodes = node.MapTile.AdjacentTiles .Select(mapTile => nodeGrid[mapTile.Point.X, mapTile.Point.Y]) .Where(node => !node.Blocked) .ToArray() ); nodeGrid[Begin.X, Begin.Y].Opened = true; IEnumerable <PathFinderNode> openNodeQuery = nodeGrid.Cast <PathFinderNode>().Where(node => node.Opened && !node.Closed); PathFinderNode[] openNodes = openNodeQuery.ToArray(); PathFinderNode endNode = openNodes.FirstOrDefault(node => node.Point == End); while (openNodes.Length > 0) { openNodes.Action( (i, openNode) => { openNode.Closed = true; openNode.AdjacentNodes.Action( (i, adjacentNode) => { if (!adjacentNode.Opened && !adjacentNode.Closed) { adjacentNode.Opened = true; adjacentNode.PreviousNode = openNode; } } ); } ); if ((endNode = openNodes.FirstOrDefault(node => node.Point == End)) != null) { break; } openNodes = openNodeQuery.ToArray(); } if (endNode != null) { return(endNode.BackConnectToFirstNode()); } return(null); }
public void RemoveWayPoint(Point Point) { WayPoint[] wayPoints = WayPoints.Where(wayPoint => wayPoint.Point == Point).ToArray(); wayPoints.Action( (i, wayPoint) => { WayPoints.Remove(wayPoint); wayPoint.Disconnect(); if (wayPoint.PreviousWayPoint != null && wayPoint.NextWayPoint != null) { wayPoint.PreviousWayPoint.Connect(wayPoint.NextWayPoint); } wayPoint.PathLayer.RemoveObject(wayPoint.Path); } ); Map.TabMap.Draw(); }
static void Main() { int[] arr = { 1, 2, 3, 6, 9, 8, 4, 2, 1, 4, 6, 3 }; arr.Action(x => x - 1); for (int i = 0; i < arr.Length; i++) { Console.Write(arr[i] + " "); } Console.WriteLine(); Console.WriteLine(arr.Get_Sum()); Console.WriteLine(); Console.WriteLine(arr.Get_Average()); Console.WriteLine(); Console.WriteLine(arr.Get_Most_Common()); }
public void Draw() { Point currentAspectSize = AspectSize; if (currentAspectSize <= Point.Zero) { return; } if (currentAspectSize != LastAspectSize) { Bitmap = ResizeBitmap(Bitmap, currentAspectSize); } LastAspectSize = currentAspectSize; System.Drawing.Point PointZero = Point.Zero.ToPoint(); using Graphics graphics = Graphics.FromImage(Bitmap); graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; graphics.Clear(Color.White); ILayer[] layers = Layers.ToArray().ToArray(); layers.Action( (i, layer) => { if (layer.Bitmap == null) { layer.Bitmap = new Bitmap(currentAspectSize.X, currentAspectSize.Y); } else if (new Point(layer.Bitmap.Size) != currentAspectSize) { layer.Bitmap = ResizeBitmap(layer.Bitmap, currentAspectSize); } layer.OnBeginDraw(); } ); int[] LayerHeights = layers.SelectMany(layer => layer.LayerHeights) .Distinct() .OrderBy(layerHeight => layerHeight) .ToArray(); LayerHeights.Action( (layerHeightIndex, layerHeight) => { ILayer[] layersWithinHeight = Layers.Where(layer => !layer.SkipDraw && layer.LayerHeights.Contains(layerHeight)).ToArray(); layersWithinHeight.Action( (layerArrayIndex, layer) => { if (!layer.SkipDraw) { layer.OnBeginLayer(layerHeight); layer.MapObjects.Where(mapObject => mapObject.IsDrawable).ToArray().Action( (mapObjectArrayIndex, mapObject) => { if (!layer.SkipDraw) { layer.OnDraw(layerHeight, mapObject); } } ); ColorMatrix matrix = new ColorMatrix { Matrix33 = layer.Opacity.ContainsKey(layerHeight) ? layer.Opacity[layerHeight] : 1 }; ImageAttributes attributes = new ImageAttributes(); attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Rectangle rectangle = Point.Zero.ToRectangle(new Point(layer.Bitmap.Size)); graphics.DrawImage(layer.Bitmap, rectangle, 0f, 0f, rectangle.Width, rectangle.Height, GraphicsUnit.Pixel, attributes); } } ); } ); layers.Action((i, v) => v.OnEndDraw()); }