public override void Attack(GameObject source, Vector3 contactPoint, float AttackArg1, float AttackArg2, float AttackArg3, float AttackArg4, Collider collider, GameObject effect, GameObject effect2)
    {
        //float explosionRadius, float explosionPower, float upwardForce, float explosionDirectDamge

        Collider[] colliders = Physics.OverlapSphere(contactPoint, AttackArg1);
        Debug.Log("Number of colliders " + colliders.Length);
        try{
            foreach (Collider hit in colliders)
            {
                IExplodable explodableObject = hit.GetComponent <IExplodable>();
                Debug.Log("Tag: " + hit.tag);
                if (explodableObject != null && !explodableObject.HasExploded())
                {
                    Debug.Log("explodable collider");

                    explodableObject.TakeExplosion(AttackArg2, contactPoint, AttackArg1, AttackArg3, AttackArg4);
                }
                else if (string.Compare(hit.tag, "Enemy") == 0)
                {
                    IExplodable explodableObject2 = hit.transform.parent.parent.parent.parent.GetComponent <IExplodable>();
                    if (explodableObject2 != null && !explodableObject2.HasExploded())
                    {
                        explodableObject2.TakeExplosion(AttackArg2, contactPoint, AttackArg1, AttackArg3, AttackArg4);
                    }
                }
            }
        }catch (NullReferenceException e) {}

        Destroy(Instantiate(effect.gameObject, source.transform.position, Quaternion.identity) as GameObject, 2f);
        //Destroy(source);
        source.SetActive(false);
    }
Example #2
0
 public void Explode()
 {
     Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, explosionRange);
     for (int i = 0; i < colliders.Length; i++)
     {
         IExplodable explodable = colliders[i].gameObject.GetComponent <IExplodable>();
         if (explodable != null)
         {
             try
             {
                 explodable.ActivateFromExplosion();
             }
             catch { }
         }
         CirclePlayer2D playerScript = colliders[i].gameObject.GetComponent <CirclePlayer2D>();
         if (playerScript != null)
         {
             try
             {
                 playerScript.JumpReaction((Vector2)transform.position);
             }
             catch { }
         }
     }
     AnimateExplosion();
 }
Example #3
0
 public GameState NextState(GameState state, Position position)
 {
     if (MoveLegal(state, position))
     {
         GameState newState = state.Copy(Width, Height);
         newState.Fields[FieldIndex(position.x, position.y)] = (FieldState)newState.CurrentPlayer;
         if (state.Fields[FieldIndex(position.x, position.y)] == FieldState.Hidden)
         {
             int hiddenCount = state.CountHiddenFields();
             int randValue   = rand.Next(0, hiddenCount);
             // TODO: Improve on this method
             IExplodable currentBomb = null;
             if (randValue < state.BigBombsRemaining)
             {
                 currentBomb = bigBomb;
                 newState.BigBombsRemaining--;
             }
             else if (randValue < state.BigBombsRemaining + state.PlusBombsRemaining)
             {
                 currentBomb = plusBomb;
                 newState.PlusBombsRemaining--;
             }
             if (currentBomb != null)
             {
                 foreach (var exploded in currentBomb.Explode(position, Width, Height))
                 {
                     newState.Fields[FieldIndex(exploded.x, exploded.y)] = newState.Fields[FieldIndex(exploded.x, exploded.y)] != FieldState.Hidden ? FieldState.None : FieldState.Hidden;
                 }
             }
         }
         newState.CurrentPlayer = newState.CurrentPlayer == PlayerType.Noughts ? PlayerType.Crosses : PlayerType.Noughts;
         return(newState);
     }
     throw new IllegalMoveException();
 }
Example #4
0
 /// <summary>
 /// Create a command object.
 /// </summary>
 /// <param name="agent">The agent whos data will be passed to explosion spawned instances and then remove from the map.</param>
 /// <param name="explodable">The explodable object that will be exploded. Usually, set to the agent if it implements the interface.</param>
 /// <returns></returns>
 public static ICommand Create(IAgent agent, IExplodable explodable)
 {
     return(new ExplodeAgent
     {
         agent = agent,
         explodable = explodable
     });
 }
Example #5
0
        public void TestIsFatherBomb()
        {
            IMineFactory mineCreator  = new MineCreator();
            IExplodable  fatherBomb   = mineCreator.CreateMine(MinePower.Five); // Should return 'Father Bomb'
            bool         isFatherBomb = fatherBomb is FatherBomb;

            Assert.IsTrue(isFatherBomb);
        }
Example #6
0
        public void TestIsLandMine()
        {
            IMineFactory mineCreator = new MineCreator();
            IExplodable  landMine    = mineCreator.CreateMine(MinePower.Two); // Should return 'Land Mine'
            bool         isLandMine  = landMine is LandMine;

            Assert.IsTrue(isLandMine);
        }
Example #7
0
        public void TestIsNavelMine()
        {
            IMineFactory mineCreator = new MineCreator();
            IExplodable  navelMine   = mineCreator.CreateMine(MinePower.Three); // Should return 'Navel Mine'
            bool         isNavelMine = navelMine is NavelMine;

            Assert.IsTrue(isNavelMine);
        }
Example #8
0
 public void Explode(IExplodable Target)
 {
     if (Target is Order == false)
     {
         throw new ArgumentException();
     }
     this.Order = Target as Order;
     ExplodeContent();
 }
Example #9
0
        public void CreateMineShouldReturnProperMines()
        {
            IMineFactory mineCreator      = new MineCreator();
            IExplodable  lumpetByCreator  = mineCreator.CreateMine(MinePower.One);  // Should return 'Lumpet Mine'
            IExplodable  nuclearByCreator = mineCreator.CreateMine(MinePower.Four); // Should return 'Nuclear Mine';
            bool         isLumpet         = lumpetByCreator is LimpetMine;
            bool         isNuclear        = nuclearByCreator is NuclearMine;

            Assert.IsTrue(isLumpet && isNuclear);
        }
Example #10
0
    //collider is switched to a trigger upon explosion
    void OnTriggerEnter2D(Collider2D col)
    {
        //if any IExplodables are caught in the blast radius, call their Explode methods
        IExplodable explodable = col.GetComponent(typeof(IExplodable)) as IExplodable;

        if (explodable != null)
        {
            explodable.Explode();
        }
    }
Example #11
0
 public void Explode(IExplodable Target)
 {
     if(Target is Order == false)
     {
         throw new ArgumentException();
     }
     this.Order = Target as Order;
     ExplodeContent();
   
 }
Example #12
0
        public void Explode(IExplodable Target)
        {
            if (Target is Element == false)
            {
                throw new ArgumentException();
            }
            this.Target = Target as Element;

            ExplodeContent();
            GetContent();
        }
Example #13
0
    //collider starts off as solid
    void OnCollisionEnter2D(Collision2D col)
    {
        //if the grenade collides with something explodable, start exploding
        IExplodable explodable = col.gameObject.GetComponent(typeof(IExplodable)) as IExplodable;

        if (explodable != null)
        {
            Explode();
            explodable.Explode();
        }
    }
Example #14
0
    public static void CreateExplosion(Vector3 pos, float explosionRadius, float damage, TeamTypes explosionBy)
    {
        Collider[] cols = Physics.OverlapSphere(pos, explosionRadius);

        foreach (Collider col in cols)
        {
            IExplodable explodable = col.GetComponent <IExplodable>();
            if (explodable != null)
            {
                explodable.OnExpload(pos, explosionRadius, damage);
            }
        }
    }
Example #15
0
        public void Explode(IExplodable Target)
        {
            if(Target is Element == false)
            {
                throw new ArgumentException();
            }
            this.Target = Target as Element;

            ExplodeContent();
            GetContent();
          

        }
Example #16
0
        private void collidePixelByRange(IExplodable i_Collidable)
        {
            Color[] sourcePixels = getPixelsData(i_Collidable);

            for (int y = m_IntersectionRectangle.Top; y < m_IntersectionRectangle.Bottom; y++)
            {
                for (int x = m_IntersectionRectangle.Left; x < m_IntersectionRectangle.Right; x++)
                {
                    if (!isTransparent(m_Collidable.Pixels, x, y, m_Collidable.Bounds) &&
                        !isTransparent(sourcePixels, x, y, i_Collidable.Bounds))
                    {
                        m_IntersectionPoints.Add(new Point(x, y));
                    }
                }
            }

            transpaerntIntersectionPoints(i_Collidable.ExplosionRange);
        }
Example #17
0
        /// <summary>
        /// Creates a mine based on the given MinePower.
        /// </summary>
        /// <param name="power">Accepts MinePower enumeration.</param>
        /// <returns>Returns an instance of the IMine interface for the current mine power.</returns>
        public override IExplodable CreateMine(MinePower power)
        {
            IExplodable mineToReturn = null;

            if (this.createdMines.ContainsKey(power))
            {
                mineToReturn = this.createdMines[power];
            }
            else
            {
                switch (power)
                {
                case MinePower.One:
                    mineToReturn = new LimpetMine();
                    break;

                case MinePower.Two:
                    mineToReturn = new LandMine();
                    break;

                case MinePower.Three:
                    mineToReturn = new NavelMine();
                    break;

                case MinePower.Four:
                    mineToReturn = new NuclearMine();
                    break;

                case MinePower.Five:
                    mineToReturn = new FatherBomb();
                    break;

                default:
                    throw new ArgumentException(string.Format("Mine with power: {0}, does not exists YET!", power));
                }

                this.createdMines.Add(power, mineToReturn);
            }

            return(mineToReturn);
        }
    void OnCollisionEnter(Collision collision)
    {
        Vector3 explosionPoint;

        if (string.Compare(collision.collider.tag, "Wall") != 0)
        {
            IDamageable damageableObject = collision.collider.GetComponent <IDamageable>();

            explosionPoint = collision.GetContact(0).point;

            Collider[] colliders = Physics.OverlapSphere(explosionPoint, 5f);
            Debug.Log("Number of colliders " + colliders.Length);
            try{
                foreach (Collider hit in colliders)
                {
                    IExplodable explodableObject = hit.GetComponent <IExplodable>();
                    Debug.Log("Tag: " + hit.tag);
                    if (explodableObject != null && !explodableObject.HasExploded())
                    {
                        Debug.Log("explodable collider");

                        explodableObject.TakeExplosion(400f, explosionPoint, 8f, 10f, 10f);
                    }
                    else if (string.Compare(hit.tag, "Enemy") == 0)
                    {
                        IExplodable explodableObject2 = hit.transform.parent.parent.parent.parent.GetComponent <IExplodable>();
                        if (explodableObject2 != null && !explodableObject2.HasExploded())
                        {
                            explodableObject2.TakeExplosion(400f, explosionPoint, 8f, 10f, 10f);
                        }
                    }
                }
            }catch (NullReferenceException e) {}

            Destroy(Instantiate(explosionEffect.gameObject, transform.position, Quaternion.identity) as GameObject, 2f);
            Destroy(gameObject);
        }
    }
Example #19
0
 public void SetMine(IExplodable mine)
 {
     this.currentMine = mine;
 }
Example #20
0
 public ExplosionManager(GameField gameField)
 {
     currentMine     = null;
     currentPosition = null;
     this.gameField  = gameField;
 }
Example #21
0
 public void CreateMineWithInvaludPowerShouldThrowExeption()
 {
     IMineFactory mineCreator     = new MineCreator();
     IExplodable  lumpetByCreator = mineCreator.CreateMine(new MinePower());   // Hack the mine system
 }
Example #22
0
 public static void Remove(IExplodable explodable)
 {
     Explodables.Remove(explodable);
 }
Example #23
0
 public static void Add(IExplodable explodable)
 {
     Explodables.Add(explodable);
 }