Exemple #1
0
        /// <summary>
        /// Gets the next color.
        /// </summary>
        /// <param name="preferredMood">The preferred mood.</param>
        /// <param name="secondaryMood">The secondary mood.</param>
        /// <returns></returns>
        public Color NextColor(ColorMoods preferredMood, ColorMoods secondaryMood)
        {
            if (_usedColors.Count == _colors.Count)
            {
                // We're all out of colors.  Reset.
                Reset();
            }

            // First try to find a color in the preferred mood
            Color result = FindUnused(preferredMood);

            if (result != Color.Transparent)
            {
                return(result);
            }
            else
            {
                // Try the secondary mood
                Color secondresult = FindUnused(secondaryMood);
                if (secondresult != Color.Transparent)
                {
                    return(secondresult);
                }
                else
                {
                    // Just return something
                    return(FindUnused(ColorMoods.All));
                }
            }
        }
Exemple #2
0
        private Color FindUnused(ColorMoods mood)
        {
            foreach (var pair in _colors)
            {
                // Use bitwise AND to see if this color passes - also make sure we haven't used it yet
                if ((pair.Value & mood) != 0 && !_usedColors.Contains(pair.Key))
                {
                    _usedColors.Add(pair.Key);
                    return(pair.Key);
                }
            }

            // If we get to this point, we have used all the colors
            return(Color.Transparent);
        }
Exemple #3
0
 /// <summary>
 /// Gets the next color.
 /// </summary>
 /// <param name="preferredMood">The preferred mood.</param>
 /// <returns></returns>
 public Color NextColor(ColorMoods preferredMood)
 {
     return(NextColor(preferredMood, ColorMoods.All));
 }