コード例 #1
0
ファイル: MazeWall.xaml.cs プロジェクト: danafeld/Maze_MVP
        /// <summary>
        /// color the maze
        /// </summary>
        /// <param name="mazewall2d">maze 2d</param>
        /// <param name="maze">maze 3d m</param>
        /// <param name="curr_layer">current layer</param>
        /// <param name="final_layer">final layer</param>
        /// <param name="s">name of maze</param>
        private void colorMazeWall(Grid mazewall2d, Maze maze, int curr_layer, int final_layer)
        {
            Maze2d maze2d = maze as Maze2d;

            for (int row = 0; row < maze2d.MX * 2 - 1; row++)
            {
                for (int column = 0; column < maze2d.MY * 2 - 1; column++)
                {
                    if (curr_layer == 0 && maze2d.getStartPosition().X == row && maze2d.getStartPosition().Y == column)
                    {
                        StartControl StartCell = new StartControl();
                        Grid.SetColumn(StartCell, column);
                        Grid.SetRow(StartCell, row);
                        mazewall2d.Children.Add(StartCell);
                    }

                    else
                    {
                        if (curr_layer == final_layer - 1 && maze2d.getGoalPosition().X == row && maze2d.getGoalPosition().Y == column)
                        {
                            EndControl EndCell = new EndControl();
                            Grid.SetColumn(EndCell, column);
                            Grid.SetRow(EndCell, row);
                            mazewall2d.Children.Add(EndCell);
                        }
                        else
                        {
                            if (maze2d.MAZE2d[row, column] == 1)
                            {
                                MazeCell1 CellWall = new MazeCell1();
                                Grid.SetColumn(CellWall, column);
                                Grid.SetRow(CellWall, row);
                                mazewall2d.Children.Add(CellWall);
                            }

                            else
                            {
                                GrassCell grassCell = new GrassCell();
                                Grid.SetColumn(grassCell, column);
                                Grid.SetRow(grassCell, row);
                                mazewall2d.Children.Add(grassCell);
                            }
                        }
                    }
                }
            }
            m_layerOfGrid[curr_layer] = mazewall2d;
        }
コード例 #2
0
        /// <summary>
        /// create the maze
        /// </summary>
        private void CreateTheMaze()
        {
            double PositionX = 0;
            double PositionY = 0;
            Maze2d maze2d    = m_maze.MAZE3dArray[cur_layer] as Maze2d;

            for (int row = 0; row < maze2d.MX * 2 - 1; row++)
            {
                PositionX = 0;
                for (int column = 0; column < maze2d.MY * 2 - 1; column++)
                {
                    if (cur_layer == 0 && maze2d.getStartPosition().X == row && maze2d.getStartPosition().Y == column)
                    {
                        StartControl s = new StartControl();
                        s.Width  = cellWidth;
                        s.Height = cellHeight;
                        Canvas.SetLeft(s, PositionX);
                        Canvas.SetTop(s, PositionY);
                        PanelDown.Children.Add(s);
                    }

                    else
                    {
                        if (cur_layer == goal_layer && maze2d.getGoalPosition().X == row && maze2d.getGoalPosition().Y == column)
                        {
                            EndControl EndCell = new EndControl();
                            EndCell.Width  = cellWidth;
                            EndCell.Height = cellHeight;
                            Canvas.SetLeft(EndCell, PositionX);
                            Canvas.SetTop(EndCell, PositionY);
                            PanelDown.Children.Add(EndCell);
                        }
                        else
                        {
                            if (maze2d.getGoalPosition().X == row && maze2d.getGoalPosition().Y == column)
                            {
                                ArrowControl arrow = new ArrowControl();
                                arrow.Width  = cellWidth;
                                arrow.Height = cellHeight;
                                Canvas.SetLeft(arrow, PositionX);
                                Canvas.SetTop(arrow, PositionY);
                                PanelDown.Children.Add(arrow);
                            }
                            else
                            {
                                if (maze2d.MAZE2d[row, column] == 1)
                                {
                                    MazeCell1 wall = new MazeCell1();
                                    wall.Width  = cellWidth;
                                    wall.Height = cellHeight;
                                    Canvas.SetLeft(wall, PositionX);
                                    Canvas.SetTop(wall, PositionY);
                                    PanelDown.Children.Add(wall);
                                }

                                else
                                {
                                    if (maze2d.MAZE2d[row, column] == 0)
                                    {
                                        GrassCell grass = new GrassCell();
                                        grass.Width  = cellWidth;
                                        grass.Height = cellHeight;
                                        Canvas.SetLeft(grass, PositionX);
                                        Canvas.SetTop(grass, PositionY);
                                        PanelDown.Children.Add(grass);
                                    }
                                }
                            }
                        }
                    }
                    PositionX += cellWidth;
                }
                PositionY += cellHeight;
            }
        }