Example #1
0
        /// <summary>
        /// Randomly selects a <see cref="JukeBoxMusic"/> from the musicList.
        /// </summary>
        /// <param name="recursionDepth">
        /// The number of times ActuallySelectRandomMusic has been called recursively;
        /// this happens when the IRequirement of a choosen JukeBoxMusic has not been fulfilled.
        /// </param>
        /// <returns>
        /// The JukeBoxMusic that has been selected;
        /// or null if none.
        /// </returns>
        private JukeBoxMusic ActuallySelectRandomMusic(int recursionDepth = 0)
        {
            const int MaximumRecursionDepth = 10;

            if (this.musicList.Length == 0)
            {
                return(null);
            }

            if (recursionDepth >= MaximumRecursionDepth)
            {
                return(this.musicList[0]);
            }

            JukeBoxMusic music = this.musicList[rand.RandomRange(0, musicList.Length - 1)];

            if (music == null)
            {
                return(null);
            }

            if (!this.CanPlayMusic(music))
            {
                return(this.ActuallySelectRandomMusic(++recursionDepth));
            }

            return(music);
        }
Example #2
0
 private bool CanPlayMusic(JukeBoxMusic music)
 {
     //            if( music.Requirement != null )
     //{
     //    if( !music.Requirement.IsFulfilledBy( this.ingameState.Player ) )
     return(true);
 }
Example #3
0
        /// <summary>
        /// Randomly selects a music from the music list.
        /// </summary>
        /// <returns>
        /// The music that has been selected.
        /// </returns>
        private Sound SelectRandomMusic()
        {
            JukeBoxMusic music = this.ActuallySelectRandomMusic();

            if (music == null)
            {
                return(null);
            }

            Sound musicResource = audioSystem.GetMusic(music.FileName);

            if (musicResource != null)
            {
                musicResource.LoadAsMusic(false);
            }

            return(musicResource);
        }