Example #1
0
        public ClothingResponse Execute(ref Person person, Weather weather)
        {
            ClothingResponse response = new ClothingResponse()
            {
                IsSuccessful = false,
                Response     = "fail"
            };

            if (person.IsWearing(Clothing.Footwear))
            {
                return(response);
            }
            if (person.IsWearing(Clothing.Pajamas))
            {
                return(response);
            }
            if (!person.IsWearing(Clothing.Pants))
            {
                return(response);
            }
            if (!person.IsWearing(Clothing.Socks) && weather == Weather.Cold)
            {
                return(response);
            }

            person.Wear(Clothing.Footwear);

            return(new ClothingResponse()
            {
                IsSuccessful = true,
                Response = weather == Weather.Hot ? "sandals" : "boots"
            });
        }
Example #2
0
        public ClothingResponse Execute(ref Person person, Weather weather)
        {
            ClothingResponse response = new ClothingResponse()
            {
                IsSuccessful = false,
                Response     = "fail"
            };

            if (person.IsWearing(Clothing.Pants))
            {
                return(response);
            }
            if (person.IsWearing(Clothing.Pajamas))
            {
                return(response);
            }

            person.Wear(Clothing.Pants);

            return(new ClothingResponse()
            {
                IsSuccessful = true,
                Response = weather == Weather.Hot ? "shorts" : "pants"
            });
        }
Example #3
0
        public ClothingResponse Execute(ref Person person, Weather weather)
        {
            ClothingResponse response = new ClothingResponse()
            {
                IsSuccessful = false,
                Response     = "fail"
            };

            if (person.IsWearing(Clothing.Jacket))
            {
                return(response);
            }
            if (person.IsWearing(Clothing.Pajamas))
            {
                return(response);
            }
            if (weather == Weather.Hot)
            {
                return(response);
            }

            if (!person.IsWearing(Clothing.Shirt))
            {
                return(response);
            }

            person.Wear(Clothing.Jacket);

            return(new ClothingResponse()
            {
                IsSuccessful = true,
                Response = "jacket"
            });
        }
Example #4
0
        public ClothingResponse Execute(ref Person person, Weather weather)
        {
            ClothingResponse response = new ClothingResponse()
            {
                IsSuccessful = false,
                Response     = "fail"
            };

            if (person.IsWearing(Clothing.Headwear))
            {
                return(response);
            }
            if (person.IsWearing(Clothing.Pajamas))
            {
                return(response);
            }
            if (!person.IsWearing(Clothing.Shirt))
            {
                return(response);
            }

            person.Wear(Clothing.Headwear);

            return(new ClothingResponse()
            {
                IsSuccessful = true,
                Response = weather == Weather.Hot ? "sun visor" : "hat"
            });
        }
Example #5
0
        public ClothingEngine(List <int> actions)
        {
            ClothingResponse response = new ClothingResponse()
            {
                IsSuccessful = false,
                Response     = "failed"
            };

            // Load the rules in order...
            //
            foreach (int action in actions)
            {
                rules.Add(ClothingRulesFactory.GetRule(action));
            }
        }
Example #6
0
        public ClothingResponse Execute(ref Person person, Weather weather)
        {
            ClothingResponse response = new ClothingResponse()
            {
                IsSuccessful = false,
                Response     = "fail"
            };

            if (person.IsWearing(Clothing.Pajamas))
            {
                return(response);
            }
            if (!person.IsWearing(Clothing.Footwear))
            {
                return(response);
            }
            if (!person.IsWearing(Clothing.Headwear))
            {
                return(response);
            }
            if (!person.IsWearing(Clothing.Socks) && weather == Weather.Cold)
            {
                return(response);
            }
            if (!person.IsWearing(Clothing.Shirt))
            {
                return(response);
            }
            if (!person.IsWearing(Clothing.Jacket) && weather == Weather.Cold)
            {
                return(response);
            }
            if (!person.IsWearing(Clothing.Pants))
            {
                return(response);
            }

            return(new ClothingResponse()
            {
                IsSuccessful = true,
                Response = "leaving house"
            });
        }
Example #7
0
        public ClothingResponse Execute(ref Person person, Weather weather)
        {
            ClothingResponse response = new ClothingResponse()
            {
                IsSuccessful = false,
                Response     = "fail"
            };

            if (person.IsWearing(Clothing.Pajamas))
            {
                person.Remove(Clothing.Pajamas);
                response = new ClothingResponse()
                {
                    IsSuccessful = true,
                    Response     = "removing PJ's"
                };
            }

            return(response);
        }
Example #8
0
        public void ExecuteRules(Person person, Weather weather)
        {
            // Execute the rules in order...
            //
            foreach (IClothingRule rule in rules)
            {
                //Console.WriteLine("Executing " + rule.GetType().ToString() + "...");

                ClothingResponse response = rule.Execute(ref person, weather);

                Console.Write(response.Response);
                if (response.IsSuccessful && response.Response != "leaving house")
                {
                    Console.Write(", ");
                }

                if (!response.IsSuccessful)
                {
                    return;
                }
            }
        }