/// <summary> /// Displays the current state of the maze in view /// </summary> /// <param name="winMaze">WinMaze object</param> /// <param name="floor">Current floor to displays</param> private void printMaze(WinMaze winMaze, int floor) { CurrentMazeCanvas = new Canvas(); SecondaryMazeCanvas = new Canvas(); 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 (solExists) { solExists = false; winMaze = originalWinMaze; winMaze.clearSolution(); } else { originalWinMaze = winMaze; } MazeBoard mazeBoard = new MazeBoard(winMaze, winMaze.PosZ, winMaze.CellSize, 0); CurrentMazeCanvas.Children.Add(mazeBoard); Canvas.SetLeft(mazeBoard, 30); Canvas.SetTop(mazeBoard, 10); if ((winMaze.PosZ + 1) < winMaze.getMaze().MyHeight) // Upper level display { MazeBoard upMazeBoard = new MazeBoard(winMaze, floor, 10, 1); SecondaryMazeCanvas.Children.Add(upMazeBoard); Canvas.SetLeft(upMazeBoard, 0); Canvas.SetTop(upMazeBoard, 30); } if ((winMaze.PosZ - 1) >= 0) { MazeBoard downMazeBoard = new MazeBoard(winMaze, floor, 10, -1); // Lower level display SecondaryMazeCanvas.Children.Add(downMazeBoard); Canvas.SetLeft(downMazeBoard, 0); Canvas.SetTop(downMazeBoard, 200); } isMazeExists = true; staticMaze = winMaze; }
/// <summary> /// Move up in the maze command /// </summary> public void moveUp() { WinMaze maze = m_winMazesDictionary["maze"]; if ((maze.PosZ + 1) < maze.getMaze().MyHeight) { int isBrockAbove = maze.getMaze().getMazeByFloor(maze.PosZ + 1).getCell(maze.PosX, maze.PosY).BlockOrEmpty; if (isBrockAbove == 0) { maze.PosZ += 1; m_winMazesDictionary[maze.getName()] = maze; m_currentWinMaze = maze; printMaze(maze, maze.PosZ); } } }
/// <summary> /// Move forward in the maze command /// </summary> public void moveForward() { WinMaze maze = m_winMazesDictionary["maze"]; int[] currentCellWalls = maze.getMaze().getMazeByFloor(maze.PosZ).getCell(maze.PosX, maze.PosY).getWallsAroundCell(); if (maze.PosY + 1 < maze.getMaze().MyRows) { if (currentCellWalls[3] == 0) { maze.PosY += 1; m_winMazesDictionary[maze.getName()] = maze; m_currentWinMaze = maze; printMaze(maze, maze.PosZ); } } }
/// <summary> /// Save Maze - Creates a compression of the maze and /// saves the file on the disk with a given file path /// </summary> /// <param name="mazeName">Maze name</param> /// <param name="path">File Name</param> /// <returns>True if successful saving the maze</returns> public bool saveMaze(string mazeName, string filePath) { WinMaze winMaze = m_currentWinMaze; Maze3d currentMaze = winMaze.getMaze(); add3dMaze(mazeName, currentMaze); if (isSolutionExists) { m_solutionsDictionary[mazeName] = mCurrentSolution; } if (currentMaze == null) { return(false); } using (FileStream fileOutStream = new FileStream(filePath, FileMode.Create)) { using (Stream outStream = new MyCompressorStream(fileOutStream)) { outStream.Write(currentMaze.toByteArray(), 0, currentMaze.toByteArray().Length); outStream.Flush(); } } printMaze(winMaze, winMaze.PosZ); return(true); }
/// <summary> /// Move back in the maze command /// </summary> public void moveBack() { WinMaze maze = m_winMazesDictionary["maze"]; int[] currentCellWalls = maze.getMaze().getMazeByFloor(maze.PosZ).getCell(maze.PosX, maze.PosY).getWallsAroundCell(); if (maze.PosY - 1 >= 0) { int[] currentCellWallsBack = maze.getMaze().getMazeByFloor(maze.PosZ).getCell(maze.PosX, maze.PosY - 1).getWallsAroundCell(); if ((currentCellWalls[2] == 0) || (currentCellWallsBack[3] == 0)) { maze.PosY -= 1; m_winMazesDictionary[maze.getName()] = maze; m_currentWinMaze = maze; printMaze(maze, maze.PosZ); } } }
/// <summary> /// Move down in the maze command /// </summary> public void moveDown() { WinMaze maze = m_winMazesDictionary["maze"]; if (maze.PosZ - 1 >= 0) { int isBrockBelow = maze.getMaze().getMazeByFloor(maze.PosZ - 1).getCell(maze.PosX, maze.PosY).BlockOrEmpty; if (isBrockBelow == 0) { maze.PosZ -= 1; m_winMazesDictionary[maze.getName()] = maze; m_currentWinMaze = maze; printMaze(maze, maze.PosZ); } } }