public bool canMove(Directions direction) { MatrixItem nextItemLocation = getNextLocation(direction); if (nextItemLocation == null) { return(false); } MazeItem nextItem = nextItemLocation.occupant; if (nextItem is null) { Console.WriteLine("NextCell is empty"); return(true); } if (!(nextItem is isMovable)) { return(false); } isMovable nextMoveableItem = (isMovable)nextItem; return(nextMoveableItem.canMove(direction)); }
public void Move(Directions direction) { if (!canMove(direction)) { return; } MatrixItem nextLocation = getNextLocation(direction); if (nextLocation.occupant is isMovable) { isMovable nextItem = (isMovable)nextLocation.occupant; nextItem.Move(direction); } location.occupant = null; location = nextLocation; location.occupant = this; }
public void Move(Directions direc) { // int move = random.Next(1,4); int move = 1; Directions direction = Directions.Right; switch (move) { case 1: direction = Directions.Left; break; case 2: direction = Directions.Right; break; case 3: direction = Directions.Up; break; case 4: direction = Directions.Down; break; } MatrixItem nextLocation = getNextLocation(direction); if (!(nextLocation.occupant is isMovable && nextLocation.occupant != null)) { return; } else if (nextLocation.occupant is isMovable) { isMovable nextItem = (isMovable)nextLocation.occupant; nextItem.Move(direction); } location.occupant = null; location = nextLocation; location.occupant = this; }