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); }
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); }
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 maze) { //Should only do once per maze generation----------------------- this.Title = "Maze Level: " + (Maze.GetInstance().MazeLevel + 1); 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; } }