public void printMaze(WinMaze winMaze, int floor) { if ((winMaze.PosZ == 0) && (winMaze.PosX == (winMaze.getMaze().MyColumns - 1)) && (winMaze.PosY == (winMaze.getMaze().MyRows - 1)) && !mFinished) { mFinished = true; FinishWindow finishWindow = new FinishWindow(); finishWindow.Show(); } staticMaze = winMaze; if (solutionExists) { solutionExists = false; winMaze = originalWinMaze; winMaze.clearSolution(); } else { originalWinMaze = winMaze; } MazeBoard mazeBoard = new MazeBoard(winMaze, winMaze.PosZ, winMaze.CellSize, 0); cnvs_main.Children.Clear(); cnvs_main.Children.Add(mazeBoard); Canvas.SetLeft(mazeBoard, 30); Canvas.SetTop(mazeBoard, 10); cnvs_second.Children.Clear(); if ((winMaze.PosZ + 1) < winMaze.getMaze().MyHeight) { MazeBoard upMazeBoard = new MazeBoard(winMaze, floor, 10, 1); cnvs_second.Children.Add(upMazeBoard); Canvas.SetLeft(upMazeBoard, 0); Canvas.SetTop(upMazeBoard, 30); } if ((winMaze.PosZ - 1) >= 0) { MazeBoard downMazeBoard = new MazeBoard(winMaze, floor, 10, -1); cnvs_second.Children.Add(downMazeBoard); Canvas.SetLeft(downMazeBoard, 0); Canvas.SetTop(downMazeBoard, 200); } mazeExists = true; staticMaze = winMaze; Debug.WriteLine("exiting printmaze"); }
/// <summary> /// Creates the maze & displays it on the screen /// </summary> /// <param name="maze">Current WinMaze</param> /// <param name="floor">Current floor</param> /// <param name="mazeCellSize">Size of the cells</param> private void CreateMaze(WinMaze maze, int floor, int mazeCellSize) { MazeCell mazeCell; Cell cell3d; Dictionary <int, int[, ]> solutionDictByLevel = new Dictionary <int, int[, ]>(); if (maze.isSolutionExists()) { solutionDictByLevel = maze.solutionCoordinatesByLevel(); } for (int row = 0; row < maze.getMaze().MyRows; row++) { for (int column = 0; column < maze.getMaze().MyColumns; column++) { cell3d = maze.getMaze().getMazeByFloor(floor).getCell(column, row); int[] cellWalls = cell3d.getWallsAroundCell(); int isSpecial = 0; if (1 == cell3d.BlockOrEmpty) { isSpecial = 1; } if (maze.isSolutionExists()) // mark the solution { if (solutionDictByLevel[floor][column, row] == 1) { isSpecial = 5; } } if (column == maze.getMaze().MyColumns - 1) { cellWalls[1] = 1; } if (row == maze.getMaze().MyRows - 1) { cellWalls[3] = 1; } if ((column == maze.getMaze().MyColumns - 1) && (row == maze.getMaze().MyRows - 1) && (floor == 0)) { cellWalls[1] = 0; isSpecial = 4; } if ((column == 0) && (row == 0) && (floor == maze.getMaze().MyHeight - 1)) { cellWalls[0] = 0; isSpecial = 3; } int currX = maze.PosX; int currY = maze.PosY; if ((column == currX) && (row == currY)) { isSpecial = 2; } if (column + 1 < maze.getMaze().MyColumns) { Cell cell3dright = maze.getMaze().getMazeByFloor(floor).getCell(column + 1, row); int[] cellWallsright = cell3dright.getWallsAroundCell(); if ((cellWallsright[0] == 0) || (cellWalls[1] == 0)) { cellWalls[1] = 0; } } if (row + 1 < maze.getMaze().MyRows) { Cell cell3dforward = maze.getMaze().getMazeByFloor(floor).getCell(column, row + 1); int[] cellWallsforward = cell3dforward.getWallsAroundCell(); if ((cellWallsforward[2] == 0) || (cellWalls[3] == 0)) { cellWalls[3] = 0; } } if (isSpecial == 1) { cellWalls[0] = 1; cellWalls[1] = 1; cellWalls[2] = 1; cellWalls[3] = 1; cellWalls[4] = 1; cellWalls[5] = 1; } if (column == 0) { cellWalls[0] = 1; } if (row == 0) { cellWalls[2] = 1; } mazeCell = new MazeCell(mazeCellSize, isSpecial, cellWalls[0] == 1, cellWalls[1] == 1, cellWalls[2] == 1, cellWalls[3] == 1, column == 0, row == 0); mazeBoard.Children.Add(mazeCell); Canvas.SetLeft(mazeCell, mazeCellSize * column); Canvas.SetTop(mazeCell, mazeCellSize * row); } } }