示例#1
0
        public void start(ref LemonadeStand stand, String weatherState, int temperature)
        {
            List <String> peopleNames = new List <String> {
                "Joe", "Jimmy", "Jon", "Velda", "Colleen", "Borus", "Patrick", "Anna", "Joanne",
                "Upsilon", "Plato", "Socrates", "Earl", "Ingryd", "Ella", "Terryl"
            };


            //preference according to weather
            int    potentialCustomers = 0;
            int    soldTo             = 0;
            Random rnd = new Random();

            // 10 waves of 3-10 people
            for (int i = 0; i < 10; i++)
            {
                //make a random amount of people appear here
                for (int j = 0; j < rnd.Next(3, 10); j++)
                {
                    if (stand.checkPitcher())
                    {
                        Person p = new Person(peopleNames);
                        // how weather influences person
                        if (weatherState == "Sunny")
                        {
                            p.influenceBuyChance(0.3);
                        }
                        if (weatherState == "Rainy")
                        {
                            p.influenceBuyChance(-0.3);
                        }
                        p.influenceBuyChance(stand.getPopularity());
                        p.influenceBuyChance(.25 - stand.getPrice());

                        p.influenceBuyChance(temperature / 65);

                        if (p.makeDecision(ref stand))
                        {
                            soldTo++;
                        }
                    }

                    potentialCustomers++;
                }
                //people make a decision if they want to by here
                System.Threading.Thread.Sleep(2000);
            }
            //returns money made and popularity gained
            Console.Clear();
            UI.writeLineAt($"You Sold to {soldTo} of {potentialCustomers} potential customers", stand.pos);
        }
示例#2
0
        public bool makeDecision(ref LemonadeStand L)
        {
            //decides if they want some lemonade

            Random      rnd      = new Random();
            Func <bool> decision = () => {
                double n = rnd.Next(0, 100) * buyChance;
                if (n > 50)
                {
                    return(true);
                }
                return(false);
            };

            if (decision())
            {
                //buyin some lemonade
                if (this.money > L.getPrice())
                {
                    double cost = L.sellTo(this);
                    this.money -= cost;

                    if (this.likes(L.getRecipe()))
                    {
                        UI.writeLineAt($"{this.name}: Like the lemonade", L.pos);
                        L.incrementPopularity();
                    }
                    else
                    {
                        UI.writeLineAt($"{this.name}: This lemonade is meh", L.pos);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                Console.WriteLine();
                return(false);
            }
        }