コード例 #1
0
ファイル: Block.cs プロジェクト: rafidamr/2016-Bomberman
        /// <summary>
        /// Sets a power up entity on this game block.
        /// </summary>
        /// <param name="entity">The power up entity to assign to this block</param>
        /// <exception cref="InvalidOperationException">If this block already contains a power up entity</exception>
        public void SetPowerUpEntity(IPowerUpEntity entity)
        {
            if (PowerUpEntity != null && entity != null)
            {
                throw new InvalidOperationException("Block already contains a power up entity " + PowerUpEntity.ToString());
            }

            PowerUpEntity = entity;

            if (PowerUpEntity != null)
            {
                PowerUpEntity.Location = _location;
            }
        }
コード例 #2
0
ファイル: Block.cs プロジェクト: rafidamr/2016-Bomberman
        /// <summary>
        /// Applies the power up to the player entity currently on this game block
        /// </summary>
        /// <exception cref="InvalidOperationException">If there is no player entity on this block</exception>
        /// <exception cref="InvalidOperationException">If there is no power up entity on this block</exception>
        public void ApplyPowerUp()
        {
            if (Entity == null || Entity.GetType() != typeof(PlayerEntity))
            {
                throw new InvalidOperationException("Power up cannot be applied wihout a player present");
            }

            if (PowerUpEntity == null)
            {
                throw new InvalidOperationException("There is no power up entity on this game block " + Location);
            }

            PowerUpEntity.PerformPowerUp((PlayerEntity)Entity);
            PowerUpEntity = null;
        }