예제 #1
0
        /// <summary>
        /// Private helper method to decrease a tank's HP.  When the Tank's hp is
        /// zero, we kill that tank. NOTE that this method WILL toggle a tank's dead status.
        /// If hit by a projectile, decrement hp by 1, if by a Beam, kill instantly.
        /// </summary>
        /// <param name="tankDamagedID">Tank being hurt</param>
        /// <param name="ownerOfProjID">Owner id of tank that shot</param>
        /// <param name="obj">what the tank was hit by (projectile or beam).</param>
        private void TankHit(int tankDamagedID, int ownerOfProjID, object obj)
        {
            Tank dealer   = tanks[ownerOfProjID];
            Tank receiver = tanks[tankDamagedID];

            if (obj is Projectile)
            {
                if (receiver.hitPoints == 1)
                {
                    receiver.DecreaseHP();
                    receiver.ToggleDead();
                    dealer.AddToScore();
                }

                else
                {
                    receiver.DecreaseHP();
                }
            }

            // Instant kill
            if (obj is Beam)
            {
                receiver.InstaKill();
                receiver.ToggleDead();
                dealer.AddToScore();
            }
        }