예제 #1
0
        public static Path RenderWall(this MazeData mazeData, int x, int y, DirectionType directionType, Color color)
        {
            var horizontal = (directionType == DirectionType.North || directionType == DirectionType.South) ? true : false;

            switch (directionType)
            {
            case DirectionType.North:
                return(new Path()
                {
                    Stroke = new SolidColorBrush(color),
                    StrokeThickness = mazeData.WallWidth,
                    Data = new LineGeometry()
                    {
                        StartPoint = mazeData.GetNorthEastPoint(x, y),
                        EndPoint = mazeData.GetNorthWestPoint(x, y),
                    },
                });

            case DirectionType.South:
                return(new Path()
                {
                    Stroke = new SolidColorBrush(color),
                    StrokeThickness = mazeData.WallWidth,
                    Data = new LineGeometry()
                    {
                        StartPoint = mazeData.GetSouthEastPoint(x, y),
                        EndPoint = mazeData.GetSouthWestPoint(x, y),
                    },
                });

            case DirectionType.West:
                return(new Path()
                {
                    Stroke = new SolidColorBrush(color),
                    StrokeThickness = mazeData.WallWidth,
                    Data = new LineGeometry()
                    {
                        StartPoint = mazeData.GetNorthWestPoint(x, y),
                        EndPoint = mazeData.GetSouthWestPoint(x, y),
                    },
                });

            case DirectionType.East:
                return(new Path()
                {
                    Stroke = new SolidColorBrush(color),
                    StrokeThickness = mazeData.WallWidth,
                    Data = new LineGeometry()
                    {
                        StartPoint = mazeData.GetNorthEastPoint(x, y),
                        EndPoint = mazeData.GetSouthEastPoint(x, y),
                    },
                });
            }
            return(null);
        }
예제 #2
0
 public static Path RenderCell(this MazeData mazeData, int x, int y, Color color)
 {
     return(new Path()
     {
         Fill = new SolidColorBrush(color),
         Data = new RectangleGeometry(new System.Windows.Rect()
         {
             X = x * mazeData.CellWidth,
             Y = (mazeData.NumOfVerticalCell - y - 1) * mazeData.CellWidth,
             Width = mazeData.CellWidth,
             Height = mazeData.CellWidth,
         }),
     });
 }
예제 #3
0
        public static Maze LoadFromMazeData(MazeData mazeData)
        {
            var wallMaze = new Maze(mazeData.NumOfHorizontalCell, mazeData.NumOfVerticalCell);

            for (var y = 0; y < mazeData.NumOfVerticalCell; ++y)
            {
                for (var x = 0; x < mazeData.NumOfHorizontalCell; ++x)
                {
                    if (mazeData.At(x, y).East)
                    {
                        wallMaze.At(x, y, DirectionType.East).Exist = true;
                    }
                    if (mazeData.At(x, y).West)
                    {
                        wallMaze.At(x, y, DirectionType.West).Exist = true;
                    }
                    if (mazeData.At(x, y).North)
                    {
                        wallMaze.At(x, y, DirectionType.North).Exist = true;
                    }
                    if (mazeData.At(x, y).South)
                    {
                        wallMaze.At(x, y, DirectionType.South).Exist = true;
                    }
                    if (mazeData.At(x, y).IsStart)
                    {
                        wallMaze.Start = mazeData.At(x, y);
                    }
                    if (mazeData.At(x, y).IsGoal)
                    {
                        wallMaze.Goals.Add(mazeData.At(x, y));
                    }
                }
            }

            return(wallMaze);
        }
예제 #4
0
 public static Point GetSouthWestPoint(this MazeData data, int x, int y)
 => new Point
 {
     X = x * data.CellWidth, Y = (data.NumOfVerticalCell - y) * data.CellWidth
 };
예제 #5
0
 public static Point GetNorthEastPoint(this MazeData data, int x, int y)
 => new Point
 {
     X = (x + 1) * data.CellWidth, Y = (data.NumOfVerticalCell - y - 1) * data.CellWidth
 };
예제 #6
0
 public static Point GetWestPoint(this MazeData data, int x, int y)
 => new Point
 {
     X = x * data.CellWidth, Y = (data.NumOfVerticalCell - y - 1) * data.CellWidth + (data.CellWidth / 2)
 };
예제 #7
0
        public static Canvas Render(this MazeData mazeData)
        {
            var canvas = new Canvas
            {
                Width  = mazeData.NumOfHorizontalCell * mazeData.CellWidth,
                Height = mazeData.NumOfVerticalCell * mazeData.CellWidth,
            };

            // 土台
            var basePath = new Path()
            {
                Fill = new SolidColorBrush(Colors.DarkSlateGray),
                Data = new RectangleGeometry(new Rect()
                {
                    X      = 0.0,
                    Y      = 0.0,
                    Width  = mazeData.NumOfHorizontalCell * mazeData.CellWidth,
                    Height = mazeData.NumOfVerticalCell * mazeData.CellWidth,
                }),
                Width  = mazeData.NumOfHorizontalCell * mazeData.CellWidth,
                Height = mazeData.NumOfVerticalCell * mazeData.CellWidth,
            };

            canvas.Children.Add(basePath);

            // スタート
            var start = mazeData.RenderCell(mazeData.Start.Pos.X, mazeData.Start.Pos.Y, Colors.DeepPink);

            canvas.Children.Add(start);

            // ゴール
            foreach (var goal in mazeData.Goals)
            {
                var g = mazeData.RenderCell(goal.Pos.X, goal.Pos.Y, Colors.Blue);
                canvas.Children.Add(g);
            }

            // 壁
            for (int y = 0; y < mazeData.NumOfVerticalCell; ++y)
            {
                for (int x = 0; x < mazeData.NumOfHorizontalCell; ++x)
                {
                    if (mazeData.At(x, y).North)
                    {
                        var north = mazeData.RenderWall(x, y, DirectionType.North, Colors.Red);
                        canvas.Children.Add(north);
                    }
                    if (mazeData.At(x, y).East)
                    {
                        var east = mazeData.RenderWall(x, y, DirectionType.East, Colors.Red);
                        canvas.Children.Add(east);
                    }
                    if (mazeData.At(x, y).South)
                    {
                        var south = mazeData.RenderWall(x, y, DirectionType.South, Colors.Red);
                        canvas.Children.Add(south);
                    }
                    if (mazeData.At(x, y).West)
                    {
                        var west = mazeData.RenderWall(x, y, DirectionType.West, Colors.Red);
                        canvas.Children.Add(west);
                    }
                }
            }

            return(canvas);
        }