public InteractionWithMovingItems(World world, MovingItem movingItem1, MovingItem movingItem2)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (movingItem1 == null)
                throw new ArgumentNullException("movingItem1");
            if (movingItem2 == null)
                throw new ArgumentNullException("movingItem2");

            this._world = world;
            this._movingItem1 = movingItem1;
            this._movingItem2 = movingItem2;
        }
        public ShotAndMovingItemInteraction(World world, Shot shot, MovingItem movingItem)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (shot == null)
                throw new ArgumentNullException("shot");
            if (movingItem == null)
                throw new ArgumentNullException("movingItem");

            this._world = world;
            this._shot = shot;
            this._movingItem = movingItem;
        }
        public MovingItemAndStaticItemInteraction(World world, MovingItem movingItem, StaticItem staticItem)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (movingItem == null)
                throw new ArgumentNullException("movingItem");
            if (staticItem == null)
                throw new ArgumentNullException("staticItem");

            if (movingItem is Shot)
                throw new ArgumentOutOfRangeException("movingItem");
            if (staticItem is MovingItem)
                throw new ArgumentOutOfRangeException("staticItem");

            this._world = world;
            this._movingItem = movingItem;
            this._staticItem = staticItem;
        }
        private static bool InteractionInvolvingShot(World world, Shot shot, MovingItem movingItem)
        {
            if (movingItem is Player)
                {
                movingItem.ReduceEnergy(shot.Energy);
                if (movingItem.IsAlive())
                    world.Game.SoundPlayer.Play(GameSound.PlayerInjured);
                world.ConvertShotToBang(shot);
                return true;
                }

            var monster = movingItem as Monster.Monster;
            if (monster != null)
                {
                var result = ShotHitsMonster(world, shot, monster);
                return result;
                }

            var items = new[] { shot, movingItem };
            var explosion = items.OfType<Explosion>().FirstOrDefault();
            if (explosion != null)
                {
                var otherItem = items.Single(item => item != explosion);
                if (otherItem is Shot)
                    {
                    shot.ReduceEnergy(explosion.Energy);
                    return true;
                    }
                }

            var standardShot1 = shot as StandardShot;
            var standardShot2 = movingItem as StandardShot;
            if (standardShot1 != null && standardShot2 != null)
                {
                var result = ShotHitsShot(world, standardShot1, standardShot2);
                return result;
                }

            return false;
        }
        public MovingItemAndMovingItemInteraction(World world, MovingItem movingItem1, MovingItem movingItem2)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (movingItem1 == null)
                throw new ArgumentNullException("movingItem1");
            if (movingItem2 == null)
                throw new ArgumentNullException("movingItem2");
            if (movingItem1 is Shot)
                throw new ArgumentOutOfRangeException("movingItem1");
            if (movingItem2 is Shot)
                throw new ArgumentOutOfRangeException("movingItem2");

            this._world = world;
            var items = new[] {movingItem1, movingItem2};
            this._player = items.OfType<Player>().SingleOrDefault();
            this._boulder = items.OfType<Boulder>().SingleOrDefault();
            this._mine = items.OfType<Mine>().SingleOrDefault();
            this._monster1 = items.OfType<Monster.Monster>().FirstOrDefault();
            this._monster2 = items.OfType<Monster.Monster>().Skip(1).FirstOrDefault();

            this._moveableObject = items.FirstOrDefault(item => item.Solidity == ObjectSolidity.Moveable);
            this._insubstantialObject = items.FirstOrDefault(item => item.Solidity == ObjectSolidity.Insubstantial);
        }
示例#6
0
 public void SteppedOnBy(MovingItem movingItem)
 {
     this._mineState.SteppedOnBy(movingItem);
 }
示例#7
0
 public override void SteppedOnBy(MovingItem movingItem)
 {
     this.Mine._mineState = new FiredState(this.Mine);
 }
示例#8
0
 public abstract void SteppedOnBy(MovingItem movingItem);
示例#9
0
 public override void SteppedOnBy(MovingItem movingItem)
 {
     if (movingItem is Player)
         this.Mine._countdown = TimeSpan.Zero;
 }
示例#10
0
 public override void SteppedOnBy(MovingItem movingItem)
 {
     // nothing to do
 }
示例#11
0
 public override void SteppedOnBy(MovingItem movingItem)
 {
     if (movingItem is Player)
         this.Mine._mineState = new InactiveState(this.Mine);
 }
示例#12
0
        /// <summary>
        /// Used to begin a push or bounce action by the player
        /// </summary>
        /// <param name="byWhom">The game object that is acting on the boulder</param>
        /// <param name="direction">Which direction the specified game object is directing the boulder</param>
        public void PushOrBounce(MovingItem byWhom, Direction direction)
        {
            var ps = CanBePushedOrBounced(byWhom, direction, true);
            switch (ps)
                {
                case PushStatus.No:
                    return;

                case PushStatus.Yes:
                    {
                    System.Diagnostics.Trace.WriteLine(string.Format("{0} is pushing {1}", byWhom.GetType().Name, this.GetType().Name));
                    this.Move(direction, this.StandardSpeed);
                    return;
                    }

                case PushStatus.Bounce:
                    {
                    System.Diagnostics.Trace.WriteLine(string.Format("{0} is bouncing {1}", byWhom.GetType().Name, this.GetType().Name));
                    var reverseDirection = direction.Reversed();
                    this.Move(reverseDirection, this.BounceBackSpeed);
                    byWhom.Move(reverseDirection, this.BounceBackSpeed);
                    this.World.Game.SoundPlayer.Play(GameSound.BoulderBounces);
                    return;
                    }

                default:
                    throw new InvalidOperationException();
                }
        }
示例#13
0
        private PushStatus CanBePushedOrBounced(MovingItem byWhom, Direction direction, bool isBounceBackPossible)
        {
            if (this.Solidity != ObjectSolidity.Moveable)
                return PushStatus.No;

            bool isPushable = byWhom.Capability == ObjectCapability.CanPushOthers || byWhom.Capability == ObjectCapability.CanPushOrCauseBounceBack;
            if (!isPushable)
                return PushStatus.No;

            // first check if the object can be pushed
            if (this.CanMoveInDirection(direction, isBounceBackPossible))
                return PushStatus.Yes;

            // is bounce back possible?
            if (byWhom.Capability != ObjectCapability.CanPushOrCauseBounceBack || !isBounceBackPossible)
                return PushStatus.No;

            var result = byWhom.CanMoveInDirection(direction.Reversed(), false) ? PushStatus.Bounce : PushStatus.No;
            return result;
        }
        private bool PushOrBounceObject(MovingItem moveableObject, MovingItem movingObject)
        {
            // test whether moveable object can be pushed or bounced
            if (moveableObject.Direction == Direction.None && movingObject.Direction != Direction.None)
                {
                Vector2 currentDifference = movingObject.Position - moveableObject.Position;
                float currentDistanceApart = Math.Abs(currentDifference.Length());
                if (currentDistanceApart < 40)
                    {
                    Vector2 positionWithMovement = movingObject.Position + movingObject.Direction.ToVector();
                    Vector2 potentialDifference = positionWithMovement - moveableObject.Position;
                    float potentialDistanceApart = Math.Abs(potentialDifference.Length());
                    if (potentialDistanceApart < currentDistanceApart)
                        {
                        moveableObject.PushOrBounce(movingObject, movingObject.Direction);
                        var standardShot = movingObject as StandardShot;
                        if (standardShot != null)
                            this._world.ConvertShotToBang(standardShot);
                        return true;
                        }
                    }
                }

            // test whether the moveable object crushing the insubstantial object
            if (moveableObject.Direction != Direction.None && moveableObject.Direction != movingObject.Direction)
                {
                var insubstantialObjectPosition = movingObject.Direction == Direction.None ? movingObject.Position : movingObject.MovingTowards;
                var insubtantialObjectTile = TilePos.TilePosFromPosition(insubstantialObjectPosition);
                var moveableObjectTile = TilePos.TilePosFromPosition(moveableObject.MovingTowards);
                if (insubtantialObjectTile == moveableObjectTile)
                    {
                    var energy = movingObject.InstantlyExpire();
                    this._world.AddBang(movingObject.Position, BangType.Long);
                    if (movingObject is Monster.Monster)
                        {
                        this._world.Game.SoundPlayer.Play(GameSound.MonsterDies);
                        if (!(movingObject is DeathCube))
                            {
                            var score = ((energy >> 1) + 1)*20;
                            this._world.IncreaseScore(score);
                            }
                        }
                    return true;
                    }
                }
            return false;
        }