Exemple #1
0
        /// <summary>
        /// Load Maze - Loads a maze to the memory with a given file path
        /// from the user.
        /// </summary>
        /// <param name="path">Directory path</param>
        /// <param name="mazeName">Name of the maze</param>
        public void loadMaze(string path, string mazeName)
        {
            int numberOfBytes;

            byte[]      compressionArray = new byte[100];
            List <byte> compressedList   = new List <byte>();

            using (FileStream fileInStream = new FileStream(path, FileMode.Open))
            {
                using (Stream compressor = new MyCompressorStream(fileInStream))
                {
                    while ((numberOfBytes = compressor.Read(compressionArray, 0, 100)) != 0)
                    {
                        for (int i = 0; i < numberOfBytes; i++)
                        {
                            compressedList.Add(compressionArray[i]);
                        }
                    }
                }
            }
            Maze3d loadedMaze = new Maze3d(compressedList.ToArray());

            add3dMaze(mazeName, loadedMaze);
            WinMaze winMaze = new WinMaze(loadedMaze, "maze", 50);

            //if (!winMaze.isSolutionExists())
            //    isSolutionExists = false;
            m_currentWinMaze = winMaze;
            m_winMazesDictionary.Remove("maze");
            m_winMazesDictionary["maze"] = winMaze;
            m_instructions.Clear();
            m_instructions.Add("display");
            m_instructions.Add("maze");
        }
Exemple #2
0
        /// <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)
        {
            //MessageBox.Show("save: " + mazeName);
            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();
                }
            }
            return(true);
        }
Exemple #3
0
        private void threadGenerateMaze(int[] mazeDimentions, string mazeName, int cellSize)
        {
            IMazeGenerator maze3dGenerator = new MyMaze3dGenerator();

            m_stoppingList.Add(maze3dGenerator);
            Maze3d  currentMaze = (Maze3d)maze3dGenerator.generate(mazeDimentions);
            WinMaze winMaze     = new WinMaze(currentMaze, mazeName, cellSize);

            m_winMazesDictionary[mazeName] = winMaze;
            m_currentWinMaze = winMaze;
            m_stoppingList.Remove(maze3dGenerator);
            m_solutionsDictionary.Remove("maze");
            add3dMaze("maze", currentMaze);
            isSolutionExists = false;
            saveMazeDictionary();
        }
Exemple #4
0
 /// <summary>
 /// Move up in the maze command
 /// </summary>
 /// <param name="maze">WinMaze current maze</param>
 public void moveUp(WinMaze maze)
 {
     m_instructions.Clear();
     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;
             m_instructions.Add("display");
             m_instructions.Add("maze");
             ModelChanged();
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// Move down in the maze command
 /// </summary>
 /// <param name="maze">WinMaze current maze</param>
 public void moveDown(WinMaze maze)
 {
     m_instructions.Clear();
     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;
             m_instructions.Add("display");
             m_instructions.Add("maze");
             ModelChanged();
         }
     }
 }
Exemple #6
0
 /// <summary>
 /// Move forward in the maze command
 /// </summary>
 /// <param name="maze">WinMaze current maze</param>
 public void moveForward(WinMaze maze)
 {
     m_instructions.Clear();
     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;
             m_instructions.Add("display");
             m_instructions.Add("maze");
             ModelChanged();
         }
     }
 }
Exemple #7
0
 /// <summary>
 /// Move back in the maze command
 /// </summary>
 /// <param name="maze">WinMaze current maze</param>
 public void moveBack(WinMaze maze)
 {
     m_instructions.Clear();
     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;
             m_instructions.Add("display");
             m_instructions.Add("maze");
             ModelChanged();
         }
     }
 }