Example #1
0
        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;
        }
Example #2
0
        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;
        }