public Surroundings()
 {
     _left = null;
     _right = null;
     _up = null;
     _down = null;
 }
예제 #2
0
        private static void SwapLeftRight(MazeObject from, MazeObject to)
        {
            //link all the outer nodes looking at the two being swapped
            from.getSurroundings().GetUp().getSurroundings().setDown(to);
            from.getSurroundings().GetRight().getSurroundings().setLeft(to);
            from.getSurroundings().GetDown().getSurroundings().setUp(to);

            to.getSurroundings().GetUp().getSurroundings().setDown(from);
            to.getSurroundings().GetLeft().getSurroundings().setRight(from);
            to.getSurroundings().GetDown().getSurroundings().setUp(from);

            //link all the inner nodes of the two being swappeds
            from.getSurroundings().setLeft(to.getSurroundings().GetLeft());
            to.getSurroundings().setRight(from.getSurroundings().GetRight());

            MazeObject holder = from.getSurroundings().GetUp();
            from.getSurroundings().setUp(to.getSurroundings().GetUp());
            to.getSurroundings().setUp(holder);

            holder = from.getSurroundings().GetDown();
            from.getSurroundings().setDown(to.getSurroundings().GetDown());
            to.getSurroundings().setDown(holder);

            to.getSurroundings().setLeft(from);
            from.getSurroundings().setRight(to);
        }
예제 #3
0
        private static void SwapUpDown(MazeObject from, MazeObject to)
        {
            //link all the outer nodes looking at the two being swapped
            //Maze.GetInstance().Display();
            //Console.ReadKey();

            from.getSurroundings().GetLeft().getSurroundings().setRight( to );
            from.getSurroundings().GetUp().getSurroundings().setDown( to );
            from.getSurroundings().GetRight().getSurroundings().setLeft( to );

            to.getSurroundings().GetLeft().getSurroundings().setRight( from );
            to.getSurroundings().GetDown().getSurroundings().setUp( from ); // always blows here
            to.getSurroundings().GetRight().getSurroundings().setLeft( from );

            //link all the inner nodes of the two being swappeds
            from.getSurroundings().setDown( to.getSurroundings().GetDown() );
            to.getSurroundings().setUp( from.getSurroundings().GetUp() );

            MazeObject holder = from.getSurroundings().GetLeft();
            from.getSurroundings().setLeft( to.getSurroundings().GetLeft() );
            to.getSurroundings().setLeft( holder );

            holder = from.getSurroundings().GetRight();
            from.getSurroundings().setRight( to.getSurroundings().GetRight() );
            to.getSurroundings().setRight( holder );

            to.getSurroundings().setDown(from);
            from.getSurroundings().setUp(to);
        }
예제 #4
0
        public void GenerateNext()
        {
            _lastSize += _sizeIncreasePerMaze;
            MazeLevel++;

            _theMaze = _mazeGen.Generate(_lastSize);
        }
예제 #5
0
        public static void Move(EnumDirection dir, MazeObject movee)
        {
            switch (dir)
            {
                case EnumDirection.Up:
                    SwapUpDown(movee.getSurroundings().GetUp(), movee);
                    break;

                case EnumDirection.Down:
                    SwapUpDown(movee, movee.getSurroundings().GetDown());
                    break;

                case EnumDirection.Left:
                    SwapLeftRight(movee, movee.getSurroundings().GetLeft());
                    break;

                case EnumDirection.Right:
                    SwapLeftRight(movee.getSurroundings().GetRight(), movee);
                    break;

                default:
                    throw new UnauthorizedAccessException();

            }
        }
        public void display(MazeObject head)
        {
            MazeObject temp = head;
            int count = 0;
            while(temp.getSurroundings().getDown() != null)//for (int x = 0; x < maze.Length; x++)
            {

                int goDown = 0;

                while(goDown < count)
                {
                    temp = temp.getSurroundings().getDown();
                    goDown++;
                }

                if (temp == null)
                    break;

                while(temp != null)
                {
                    Console.Write(temp);

                    temp = temp.getSurroundings().getRight();
                }

                temp = head;
                Console.WriteLine();
                count++;
            }
        }
        public void Display(MazeObject maze)
        {
            //Should only do once per maze generation-----------------------

            int size = 0;

            MazeObject displayCol = maze;

            while (displayCol != null)
            {
                displayCol = displayCol.getSurroundings().GetRight();
                size++;
            }

            //can pick based off preference
            FitToFrame(size);
            //FitToPixel(size);

            //Should only do once per maze generation-----------------------

            displayCol = maze;

            int leftRightPosition = 0;
            int upDownPosition = 0;

            screen.Children.Clear();

            while (displayCol != null)
            {

                MazeObject displayRow = displayCol;
                while (displayRow != null)
                {
                    Rectangle mazeThing = new Rectangle();
                    screen.Children.Add(mazeThing);

                    mazeThing.Height = _pixelSize;
                    mazeThing.Width = _pixelSize;
                    mazeThing.Fill = displayRow.GetColor();

                    Canvas.SetLeft(mazeThing, leftRightPosition);
                    Canvas.SetTop(mazeThing, upDownPosition);

                    displayRow = displayRow.getSurroundings().GetRight();

                    leftRightPosition += _pixelSize;
                }

                displayCol = displayCol.getSurroundings().GetDown();
                upDownPosition += _pixelSize;
                leftRightPosition = 0;
            }
        }
예제 #8
0
        public bool move(EnumDirection dir)
        {
            switch (dir)
            {
                case EnumDirection.Right:
                    if (_surroundings.getRight().swappable())
                    {
                        MazeObject temp = _surroundings.getRight().getObject();
                        _surroundings.getRight().setObject(_occupiedBy);
                        _occupiedBy = temp;
                        return true;
                    }
                    return false;

                case EnumDirection.Left:
                    if (_surroundings.getLeft().swappable())
                    {
                        MazeObject temp = _surroundings.getLeft().getObject();
                        _surroundings.getLeft().setObject(_occupiedBy);
                        _occupiedBy = temp;
                        return true;
                    }
                    return false;

                case EnumDirection.Up:
                    if (_surroundings.getUp().swappable())
                    {
                        MazeObject temp = _surroundings.getUp().getObject();
                        _surroundings.getUp().setObject(_occupiedBy);
                        _occupiedBy = temp;
                        return true;
                    }
                    return false;

                case EnumDirection.Down:
                    if (_surroundings.getDown().swappable())
                    {
                        MazeObject temp = _surroundings.getDown().getObject();
                        _surroundings.getDown().setObject(_occupiedBy);
                        _occupiedBy = temp;
                        return true;
                    }
                    return false;

                default:
                    return false;

            }//end switch
        }
        public void Display(MazeObject head)
        {
            Console.Clear();
            MazeObject displayCol = head;

            while(displayCol != null)//for (int x = 0; x < maze.Length; x++)
            {

                MazeObject displayRow = displayCol;
                while (displayRow != null)
                {
                    Console.Write(displayRow);

                    displayRow = displayRow.getSurroundings().GetRight();
                }

                displayCol = displayCol.getSurroundings().GetDown();
                Console.WriteLine();
            }
        }
예제 #10
0
 //setters-------------------------------
 public void setLeft(MazeObject left)
 {
     _left = left;
 }
예제 #11
0
 public void setDown(MazeObject down)
 {
     _down = down;
 }
예제 #12
0
 public void Generate(int size)
 {
     _theMaze = _mazeGen.Generate(size);
     _lastSize = size;
 }
예제 #13
0
 public void generate(int size)
 {
     _theMaze = _mazeGen.generate(size);
 }
예제 #14
0
 public void setObject(MazeObject mo)
 {
     _occupiedBy = mo;
 }
예제 #15
0
 public MazeNodeObject(MazeObject mo)
 {
     _occupiedBy = mo;
     _surroundings = new Surroundings();
 }
예제 #16
0
 public void setRight(MazeObject right)
 {
     _right = right;
 }
예제 #17
0
 public void setUp(MazeObject up)
 {
     _up = up;
 }
        public void MazeObjectRefresh(MazeObject refresher)
        {
            Rectangle replacement = new Rectangle();
            replacement.Height = _pixelSize;
            replacement.Width = _pixelSize;
            replacement.Fill = refresher.GetColor();

            int left = refresher.GetPosition().GetX() * _pixelSize;
            int top = refresher.GetPosition().GetY() * _pixelSize;

            Canvas.SetLeft(replacement, left);
            Canvas.SetTop(replacement, top);

            foreach (Rectangle rec in screen.Children)
            {
                if (Canvas.GetLeft(rec) == left && Canvas.GetTop(rec) == top)
                {
                    screen.Children.Remove(rec);
                    screen.Children.Add(replacement);
                    break;
                }
            }
        }