Beispiel #1
0
        private void LineOfSight_Click(object sender, RoutedEventArgs e)
        {
            DrawSurface.Children.Clear();

            Layout layout = new Layout(Orientation.Pointy,
                new Point(DrawSurface.ActualWidth / 20, DrawSurface.ActualWidth / 20),
                new Point(DrawSurface.ActualWidth / 2, DrawSurface.ActualHeight / 2)
            );

            List<Hex> blocked = new List<Hex>();
            blocked.Add(Hex.FromOffsetY(1, 1));
            blocked.Add(Hex.FromOffsetY(-1, -1));
            foreach (Hex hex in blocked)
            {
                PointCollection points = new PointCollection();
                Point[] corners = layout.Corners(hex);
                foreach (Point p in corners)
                {
                    points.Add(new Point(p.X, p.Y));
                }
                Polygon polygon = new Polygon();
                polygon.Points = points;
                polygon.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                polygon.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                polygon.StrokeThickness = 1;
                DrawSurface.Children.Add(polygon);
            }

            List<Hex> range = Hex.Zero.Range(5);
            List<Hex> hexes = new List<Hex>();
            foreach (Hex hex in range)
            {
                if (Hex.Zero.LineOfSight(hex, blocked)) hexes.Add(hex);
            }

            byte color = 0;
            foreach (Hex hex in hexes)
            {
                color += 20;
                PointCollection points = new PointCollection();
                Point[] corners = layout.Corners(hex);
                foreach (Point p in corners)
                {
                    points.Add(new Point(p.X, p.Y));
                }
                Polygon polygon = new Polygon();
                polygon.Points = points;
                polygon.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                polygon.Fill = new SolidColorBrush(Color.FromRgb(color, 100, 0));
                polygon.StrokeThickness = 1;
                DrawSurface.Children.Add(polygon);
            }
        }
Beispiel #2
0
        private void Line_Click(object sender, RoutedEventArgs e)
        {
            DrawSurface.Children.Clear();

            Layout layout = new Layout(Orientation.Pointy,
                new Point(DrawSurface.ActualWidth / 20, DrawSurface.ActualWidth / 20),
                new Point(DrawSurface.ActualWidth / 2, DrawSurface.ActualHeight / 2)
            );

            List<Hex> hexes = Hex.FromOffsetY(-2, -3).LineTo(Hex.FromOffsetY(3, 2));
            byte color = 0;
            foreach (Hex hex in hexes)
            {
                color += 20;
                PointCollection points = new PointCollection();
                Point[] corners = layout.Corners(hex);
                foreach (Point p in corners)
                {
                    points.Add(new Point(p.X, p.Y));
                }
                Polygon polygon = new Polygon();
                polygon.Points = points;
                polygon.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                polygon.Fill = new SolidColorBrush(Color.FromRgb(color, 100, 0));
                polygon.StrokeThickness = 1;
                DrawSurface.Children.Add(polygon);
            }
        }