示例#1
0
        /// <summary>
        /// Initiates a push or bounce involving this object
        /// </summary>
        /// <param name="moveableObject">The object that is potentially being moved</param>
        /// <param name="direction">The direction that the specified object is directing this object</param>
        public void PushOrBounce(IMovingItem moveableObject, Direction direction)
        {
            bool canCauseBounceBack            = this.Properties.Get(GameObjectProperties.Capability) == ObjectCapability.CanPushOrCauseBounceBack;
            var  moveableObjectMovementChecker = moveableObject.Properties.Get(GameObjectProperties.MovementChecker);
            var  ps = moveableObjectMovementChecker.CanBePushedOrBounced(moveableObject, this, direction, canCauseBounceBack);

            switch (ps)
            {
            case PushStatus.Yes:
            {
                moveableObject.Move(direction, MovementSpeed.Pushed);
                return;
            }

            case PushStatus.Bounce:
            {
                var reverseDirection = direction.Reversed();
                moveableObject.Move(reverseDirection, MovementSpeed.BounceBack);
                this.Move(reverseDirection, MovementSpeed.BounceBack);
                moveableObject.PlaySound(GameSound.BoulderBounces);
                return;
            }

            case PushStatus.No:
            {
                return;
            }

            default:
                throw new InvalidOperationException();
            }
        }
示例#2
0
        public PushStatus CanBePushedOrBounced(IMovingItem toBeMoved, IMovingItem byWhom, Direction direction, bool isBounceBackPossible)
        {
            // if this object is not moveable then the answer's no
            if (toBeMoved.Properties.Get(GameObjectProperties.Solidity) != ObjectSolidity.Moveable)
            {
                return(PushStatus.No);
            }

            // if the moving object cannot move other objects then the answer's no
            // the moving object cannot be a moveable object - moveable objects can't push other moveable objects
            if (!byWhom.Properties.Get(GameObjectProperties.Capability).CanMoveAnother() || byWhom.Properties.Get(GameObjectProperties.Solidity) == ObjectSolidity.Moveable)
            {
                return(PushStatus.No);
            }

            // check if this object can move in the specified direction
            if (CanMove(toBeMoved, direction, isBounceBackPossible))
            {
                return(PushStatus.Yes);
            }

            // if bounceback is not a possibility then the answer's no
            if (byWhom.Properties.Get(GameObjectProperties.Capability) != ObjectCapability.CanPushOrCauseBounceBack || !isBounceBackPossible)
            {
                return(PushStatus.No);
            }

            // this object will be able to bounceback only if the object that is pushing it can move backwards
            IMovementChecker mc = byWhom.Properties.Get(GameObjectProperties.MovementChecker);
            var willBounceBack  = mc.CanBePushedBackDueToBounceBack(byWhom, direction.Reversed());
            var result          = willBounceBack ? PushStatus.Bounce : PushStatus.No;

            return(result);
        }
示例#3
0
 public override void SteppedOnBy(IMovingItem movingItem)
 {
     if (movingItem is Player)
     {
         this.Mine._countdown = TimeSpan.Zero;
     }
 }
示例#4
0
        public static bool CanMoveInDirection(this IMovingItem gameObject, Direction direction)
        {
            IMovementChecker mc = gameObject.Properties.Get(GameObjectProperties.MovementChecker);
            var result          = mc.CanMoveForwards(gameObject, direction);

            return(result);
        }
示例#5
0
        private bool CanMoveTo(IMovingItem objectToCheck, Direction direction, TilePos proposedDestination, bool isBounceBackPossible)
        {
            var objectsOnTile = GlobalServices.GameState.GetItemsOnTile(proposedDestination);
            var result        = CanObjectOccupySameTile(objectToCheck, objectsOnTile, direction, isBounceBackPossible);

            return(result);
        }
示例#6
0
        protected virtual bool CanObjectOccupySameTile(IMovingItem gameObject, IGameObject objectAlreadyOnTile, Direction direction, bool isBounceBackPossible)
        {
            var solidity = objectAlreadyOnTile.Properties.Get(GameObjectProperties.Solidity);

            switch (solidity)
            {
            case ObjectSolidity.Stationary:
            case ObjectSolidity.Insubstantial:
                // neither of these will stop this object moving onto the same tile
                return(true);

            case ObjectSolidity.Impassable:
                // the target tile is already occupied and this object cannot move onto it
                return(false);

            case ObjectSolidity.Moveable:
            {
                // todo instead of using the same movementchecker, we need to use the movement checker of the boulder instead
                if (!(objectAlreadyOnTile is MovingItem moveableItem))
                {
                    // There shouldn't be any Moveable objects that are not MovingItems as that would be a contradiction
                    return(false);
                }
                var canMove = CanBePushedOrBounced(moveableItem, gameObject, direction, isBounceBackPossible);
                if (canMove == PushStatus.Yes || canMove == PushStatus.Bounce)
                {
                    return(true);
                }
                return(false);
            }

            default:
                throw new InvalidOperationException();
            }
        }
示例#7
0
 public override void SteppedOnBy(IMovingItem movingItem)
 {
     if (movingItem is Player)
     {
         this.Mine._mineState = new InactiveState(this.Mine);
     }
 }
 protected override bool CanObjectOccupySameTile(IMovingItem gameObject, IGameObject objectAlreadyOnTile, Direction direction, bool isBounceBackPossible)
 {
     if (objectAlreadyOnTile.Properties.Get(GameObjectProperties.DeadlyToTouch))
     {
         return(false);
     }
     return(base.CanObjectOccupySameTile(gameObject, objectAlreadyOnTile, direction, isBounceBackPossible));
 }
示例#9
0
 public bool CanBePushedBackDueToBounceBack(IMovingItem gameObject, Direction direction)
 {
     if (gameObject == null)
     {
         throw new ArgumentNullException(nameof(gameObject));
     }
     return(CanMove(gameObject, direction, false));
 }
示例#10
0
        /// <summary>
        /// Builds an interaction object from the two specified game objects
        /// </summary>
        /// <param name="updatedItem">An object that has just moved position</param>
        /// <param name="actedUponItem">An object whose position overlaps the first object</param>
        /// <returns>An instance of an interaction object</returns>
        private static IInteraction BuildInteraction(IMovingItem updatedItem, IGameObject actedUponItem)
        {
            var result = actedUponItem is IMovingItem secondMovingItem
                ? (IInteraction) new InteractionWithMovingItems(updatedItem, secondMovingItem)
                : new InteractionWithStaticItems(actedUponItem, updatedItem);

            return(result);
        }
示例#11
0
        /// <inheritdoc />
        public void UpdatePosition(IMovingItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            this._grid.UpdatePosition(item);
        }
示例#12
0
        public bool CanMoveForwards(IMovingItem source, Direction direction)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            bool canCauseBounceBack = source.Properties.Get(GameObjectProperties.Capability) == ObjectCapability.CanPushOrCauseBounceBack;
            var  result             = CanMove(source, direction, canCauseBounceBack);

            return(result);
        }
示例#13
0
        private bool CanObjectOccupySameTile(IMovingItem gameObject, IEnumerable <IGameObject> objectsOnTile, Direction direction, bool isBounceBackPossible)
        {
            foreach (var item in objectsOnTile)
            {
                if (!CanObjectOccupySameTile(gameObject, item, direction, isBounceBackPossible))
                {
                    return(false);
                }
            }

            return(true);
        }
        public InteractionWithStaticItems(IGameObject staticItem, IMovingItem movingItem)
        {
            if (staticItem == null)
            {
                throw new ArgumentNullException(nameof(staticItem));
            }

            if (staticItem is IMovingItem)
            {
                throw new ArgumentOutOfRangeException(nameof(staticItem));
            }

            this._staticItem = staticItem;

            this._movingItem = movingItem ?? throw new ArgumentNullException(nameof(movingItem));
        }
示例#15
0
        private bool CanMove(IMovingItem objectToCheck, Direction direction, bool isBounceBackPossible)
        {
            if (objectToCheck.MovementBoundary == null)
            {
                throw new InvalidOperationException("MovementBoundary is not set for " + objectToCheck + ".");
            }

            TilePos proposedDestination = objectToCheck.TilePosition.GetPositionAfterOneMove(direction);

            if (!objectToCheck.MovementBoundary.IsPositionWithinBoundary(proposedDestination))
            {
                return(false);
            }

            var result = CanMoveTo(objectToCheck, direction, proposedDestination, isBounceBackPossible);

            return(result);
        }
 public InteractionWithMovingItems([NotNull] IMovingItem primaryItem, [NotNull] IMovingItem secondaryItem)
 {
     this._primaryItem   = primaryItem ?? throw new ArgumentNullException(nameof(primaryItem));
     this._secondaryItem = secondaryItem ?? throw new ArgumentNullException(nameof(secondaryItem));
 }
示例#17
0
 public BoundaryCurrentRoom([NotNull] IMovingItem gameObject)
 {
     this._gameObject = gameObject ?? throw new ArgumentNullException(nameof(gameObject));
 }
示例#18
0
 public abstract void SteppedOnBy(IMovingItem movingItem);
示例#19
0
 public void SteppedOnBy(IMovingItem movingItem)
 {
     this._mineState.SteppedOnBy(movingItem);
 }
示例#20
0
 public override void SteppedOnBy(IMovingItem movingItem)
 {
     // nothing to do
 }
示例#21
0
 public override void SteppedOnBy(IMovingItem movingItem)
 {
     this.Mine._mineState = new FiredState(this.Mine);
 }
示例#22
0
        internal static bool IsAlive(this IMovingItem mi)
        {
            var result = mi.IsExtant;

            return(result);
        }
示例#23
0
 public IBoundMovement GetBoundedInRoom(IMovingItem gameObject)
 {
     return(new BoundaryCurrentRoom(gameObject));
 }
示例#24
0
 public void UpdatePosition(IMovingItem gameObject)
 {
     this._gameObjectCollection.UpdatePosition(gameObject);
 }
 public ItemWallCollision(IMovingItem item, in Rectangle collision)