Example #1
0
        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);
        }
Example #2
0
 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);
 }
Example #3
0
 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));
 }
Example #4
0
 public Tank(GameField field, CellLocation location, Facing facing, double speed) : base(field, location, facing)
 {
     _speed = speed;
 }
Example #5
0
 public bool Equals(CellLocation other)
 {
     return(X == other.X && Y == other.Y);
 }
Example #6
0
 public Player(GameField field, CellLocation location, Facing facing) : base(field, location, facing)
 {
 }
Example #7
0
 protected MovingGameObject(GameField field, CellLocation location, Facing facing) : base(location.ToPoint())
 {
     _field       = field;
     Facing       = facing;
     CellLocation = TargetCellLocation = location;
 }
Example #8
0
 public void SetLocation(CellLocation loc)
 {
     CellLocation = loc;
     Location     = loc.ToPoint();
 }