Example #1
0
        // Returns false if the user wants a particular critter and the plant DOES NOT have it.
        // Returns true if the user wants a particular critter and the plant has it. We are treating all the critter flags as "OR"s, so that
        //     if the user says YES to both hummingbirds and bees, then they get plants that attract either instead of only getting plants that
        //     attract both
        // Returns true if the user didn't specify that they wanted a particular critter.
        private bool CrittersMatch(MyCriteria wanted, Plant candidate)
        {
            bool result = false;

            if ((wanted.AttractsBirds && candidate.AttractsBirds.HasFlag(YesNoMaybe.Yes)) ||
                (wanted.AttractsHummingbirds && candidate.AttractsHummingbirds.HasFlag(YesNoMaybe.Yes)) ||
                (wanted.AttractsButterflies && candidate.AttractsButterflies.HasFlag(YesNoMaybe.Yes)) ||
                (wanted.AttractsNativeBees && candidate.AttractsNativeBees.HasFlag(YesNoMaybe.Yes)) ||
                (!wanted.AttractsBirds && !wanted.AttractsButterflies && !wanted.AttractsHummingbirds && !wanted.AttractsNativeBees))
            {
                result = true;
            }

            return(result);
        }
Example #2
0
        // Returns false if the user wants a particular color and the plant does not have it
        // Returns true if either the user wants all colors, or the plant has their color in the description
        private bool ColorsMatch(MyCriteria wanted, Plant candidate)
        {
            if (wanted.FlowerColors == FlowerColor.AnyColor)
            {
                return(true);
            }

            foreach (KeyValuePair <FlowerColor, string> entry in wanted.FlowerColorDict)
            {
                // do something with entry.Value or entry.Key
                if (wanted.FlowerColors.HasFlag(entry.Key))
                {
                    //Get the strings we're going to be searching, and make both lower case to make searching work better
                    string color = entry.Value.ToLower();
                    string plant = candidate.NotableVisuals.ToLower();

                    //Search through the description of the plant to see if it has a matching flower color
                    if (plant.Contains(color))
                    {
                        //break out with a positive result as soon as we find at least one match
                        return(true);
                    }
                }
            }

            /* OLD CODE
             * if (wanted.FlowerColorDict.ContainsKey(wanted.FlowerColors))
             * {
             *  //Get the strings we're going to be searching, and make both lower case to make searching work better
             *  string color = wanted.FlowerColorDict[wanted.FlowerColors].ToLower();
             *  string plant = candidate.NotableVisuals.ToLower();
             *
             *  //search through the description of the plant to see if it has a matching flower color
             *  if (plant.Contains(color))
             *  {
             *      return true;
             *  }
             * }
             * else
             * {
             *  //value not in dictionary, need to fix that
             * }
             */
            return(false);
        }
Example #3
0
        //TODO is there a logic bug here? This will return FALSE if...
        //   -- a plant is Unknown for Napa, and the user said they want plants that are Yes for Napa, then that plant
        //   -- a plant is No for Napa, and the user said they want plants NOT in Napa
        private bool CountiesMatch(MyCriteria wanted, Plant candidate)
        {
            bool result = false;

            if (wanted.NativeTo_Alameda && candidate.NativeTo_Alameda.HasFlag(YesNoMaybe.Yes) ||
                wanted.NativeTo_Contra_Costa && candidate.NativeTo_Contra_Costa.HasFlag(YesNoMaybe.Yes) ||
                wanted.NativeTo_Marin && candidate.NativeTo_Marin.HasFlag(YesNoMaybe.Yes) ||
                wanted.NativeTo_Napa && candidate.NativeTo_Napa.HasFlag(YesNoMaybe.Yes) ||
                wanted.NativeTo_Santa_Clara && candidate.NativeTo_Santa_Clara.HasFlag(YesNoMaybe.Yes) ||
                wanted.NativeTo_San_Francisco && candidate.NativeTo_San_Francisco.HasFlag(YesNoMaybe.Yes) ||
                wanted.NativeTo_San_Mateo && candidate.NativeTo_San_Mateo.HasFlag(YesNoMaybe.Yes) ||
                wanted.NativeTo_Solano && candidate.NativeTo_Solano.HasFlag(YesNoMaybe.Yes) ||
                wanted.NativeTo_Sonoma && candidate.NativeTo_Sonoma.HasFlag(YesNoMaybe.Yes))
            {
                result = true;
            }

            return(result);
        }