public bool SetTarget(CellLocation loc)
        {
            if (IsMoving)
            {
                //We are the bear rolling from the hill
                throw new InvalidOperationException("Unable to change direction while moving");
            }
            if (loc == CellLocation)
            {
                return(true);
            }
            Facing = GetDirection(CellLocation, loc);
            if (loc.X < 0 || loc.Y < 0)
            {
                return(false);
            }
            if (loc.X >= _field.Width || loc.Y >= _field.Height)
            {
                return(false);
            }
            if (!_field.Tiles[loc.X, loc.Y].IsPassable)
            {
                return(false);
            }

            if (
                _field.GameObjects.OfType <MovingGameObject>()
                .Any(t => t != this && (t.CellLocation == loc || t.TargetCellLocation == loc)))
            {
                return(false);
            }

            TargetCellLocation = loc;
            return(true);
        }
 Facing GetDirection(CellLocation current, CellLocation target)
 {
     if (target.X < current.X)
     {
         return(Facing.West);
     }
     if (target.X > current.X)
     {
         return(Facing.East);
     }
     if (target.Y < current.Y)
     {
         return(Facing.North);
     }
     return(Facing.South);
 }
 public CellLocation GetTileAtDirection(Facing facing)
 {
     if (facing == Facing.North)
     {
         return(CellLocation.WithY(CellLocation.Y - 1));
     }
     if (facing == Facing.South)
     {
         return(CellLocation.WithY(CellLocation.Y + 1));
     }
     if (facing == Facing.West)
     {
         return(CellLocation.WithX(CellLocation.X - 1));
     }
     return(CellLocation.WithX(CellLocation.X + 1));
 }
 public bool Equals(CellLocation other)
 {
     return(X == other.X && Y == other.Y);
 }
 protected MovingGameObject(GameField field, CellLocation location, Facing facing) : base(location.ToPoint())
 {
     _field       = field;
     Facing       = facing;
     CellLocation = TargetCellLocation = location;
 }
 public void SetLocation(CellLocation loc)
 {
     CellLocation = loc;
     Location     = loc.ToPoint();
 }