Пример #1
0
 /// <summary>
 /// checks if player got to goal point
 /// </summary>
 private void checkIfSolved()
 {
     if (m_x == m_mazeToPlayOn.getGoalPosition().Axis[0] && m_y == m_mazeToPlayOn.getGoalPosition().Axis[1] &&
         m_layer == m_mazeToPlayOn.getGoalPosition().Axis[2])
     {
         Video vid = new Video();
         vid.Show();
     }
 }
Пример #2
0
        /// <summary>
        /// get goal state (the end of the maze)
        /// </summary>
        /// <returns>The goal state</returns>
        public Astate getGoalState()
        {
            Position goal = maze.getGoalPosition();
            Astate   ans  = new MazeState(null, goal);

            return(ans);
        }
Пример #3
0
        private static void testMyCompressorStream()
        {
            Console.WriteLine("*******  testMyCompressorStream  *******\n");
            int[]          size3D          = { 3, 6, 7 }; // (z,y,x)
            IMazeGenerator mazeGenerator3d = new MyMaze3dGenerator();
            Maze3d         maze            = (Maze3d)mazeGenerator3d.generate(size3D);

            // save the maze to a file – compressed
            using (FileStream fileOutStream = new FileStream(@"D:\1.maze.txt", FileMode.Create))
            {
                using (Stream outStream = new MyCompressorStream(fileOutStream))
                {
                    outStream.Write(maze.toByteArray(), 0, maze.toByteArray().Length);
                    outStream.Flush();
                }
            }
            byte[] mazeBytes;
            using (FileStream fileInStream = new FileStream(@"D:\1.maze.txt", FileMode.Open))
            {
                using (Stream inStream = new MyCompressorStream(fileInStream))
                {
                    mazeBytes = new byte[maze.toByteArray().Length];
                    inStream.Read(mazeBytes, 0, mazeBytes.Length);
                }
            }
            Maze3d loadedMaze = new Maze3d(mazeBytes);

            Console.WriteLine("The original maze : ");
            maze.print();
            maze.getStartPosition().print();
            maze.getGoalPosition().print();

            Console.WriteLine("The decompress maze : ");
            loadedMaze.print();
            loadedMaze.getStartPosition().print();
            loadedMaze.getGoalPosition().print();
            Console.WriteLine(loadedMaze.Equals(maze));
        }
Пример #4
0
        /// <summary>
        /// draws the maze board
        /// </summary>
        /// <param name="maze">maze data</param>
        /// <param name="x">maze start position x axis</param>
        /// <param name="y">maze start position y axis</param>
        /// <param name="layer">current layer</param>
        /// <param name="solutionOn">flag solution</param>
        /// <param name="sol">maze's solution</param>
        private void DrawMaze(Maze3d maze, int x, int y, int layer, bool solutionOn, Solution sol)
        {
            try
            {
                int[,] board = maze.TwoDMazes[layer].Board;
                double boardWidth  = board.GetLength(0);
                double boardHeight = board.GetLength(1);

                for (int i = 0; i < board.GetLength(0); i++)
                {
                    for (int j = 0; j < board.GetLength(1); j++)
                    {
                        if (board[i, j] == 1)
                        {
                            Wall wall = new Wall(this.Width / boardWidth, this.Height / boardHeight);
                            mazeBoard.Children.Add(wall);
                            Canvas.SetLeft(wall, (this.Width / boardWidth) * j);
                            Canvas.SetTop(wall, (this.Height / boardHeight) * i);
                        }
                    }
                }
                //add solution
                if (solutionOn)
                {
                    //ArrayList solsInFloor = new ArrayList();
                    ArrayList sols = sol.GetSolutionPath();
                    foreach (AState state in sols)
                    {
                        object sToComp;
                        if (sols.IndexOf(state) < sols.Count - 1)
                        {
                            sToComp = sols[sols.IndexOf(state) + 1];
                        }
                        else
                        {
                            sToComp = sols[sols.IndexOf(state)];
                        }

                        if (((Maze3dState)state).State.Axis[2] == layer)
                        {
                            Path path = new Path((this.Width / boardWidth), (this.Height / boardHeight));
                            mazeBoard.Children.Add(path);
                            if (((Maze3dState)sToComp).State.Axis[2] == ((Maze3dState)state).State.Axis[2] + 1)
                            {
                                path.path_name.Fill = new SolidColorBrush(System.Windows.Media.Colors.Blue);
                            }
                            else if (((Maze3dState)sToComp).State.Axis[2] == ((Maze3dState)state).State.Axis[2] - 1)
                            {
                                path.path_name.Fill = new SolidColorBrush(System.Windows.Media.Colors.Brown);
                            }
                            else
                            {
                                path.path_name.Fill = new SolidColorBrush(System.Windows.Media.Colors.Green);
                            }
                            Canvas.SetLeft(path, (this.Width / boardWidth) * ((Maze3dState)state).State.Axis[0]);
                            Canvas.SetTop(path, (this.Height / boardHeight) * ((Maze3dState)state).State.Axis[1]);
                        }
                    }
                }
                Cat cat = new Cat((this.Width / boardWidth), (this.Height / boardHeight));
                cat.rec_name.Fill = new ImageBrush(new BitmapImage(
                                                       new Uri("Sersi.jpg", UriKind.Relative)));
                mazeBoard.Children.Add(cat);
                Canvas.SetLeft(cat, (this.Width / boardWidth) * x);
                Canvas.SetTop(cat, (this.Height / boardHeight) * y);

                //add exit pic
                if (layer == maze.getGoalPosition().Axis[2])
                {
                    Exit exit = new Exit((this.Width / boardWidth), (this.Height / boardHeight));
                    exit.exit_name.Fill = new ImageBrush(new BitmapImage(
                                                             new Uri("Exit.jpg", UriKind.Relative)));
                    mazeBoard.Children.Add(exit);
                    Canvas.SetLeft(exit, (this.Width / boardWidth) * maze.getGoalPosition().Axis[0]);
                    Canvas.SetTop(exit, (this.Height / boardHeight) * maze.getGoalPosition().Axis[1]);
                }
            }
            catch (Exception)
            {
            }
        }