示例#1
0
        /// <summary>
        /// Every alga that has at least 10 HP divides itself in two. Each gets half the amount of HP.
        /// </summary>
        public void ReproduceAlgae()
        {
            List <Organism> AlgaList = new List <Organism>();

            AlgaList = PseudoLink <Organism, Alga> .GetSubset(Organisms);

            foreach (Alga alga in AlgaList.Where(w => (w.HP >= 10)))
            {
                Organisms.Add(alga.GiveBirth());
                alga.LoseHP(alga.HP / 2);
                string str = string.Format("An alga just gave birth to a smaller alga.");
            }
        }
示例#2
0
 /// <summary>
 /// Each alga grows at each turn.
 /// Takes the form of gaining some HP.
 /// No upper bound as far as algae are concerned.
 /// </summary>
 public void GrowAlgae()
 {
     Console.WriteLine(" * *********\nAlgae growing!\n**********");
     foreach (Alga alga in PseudoLink <Organism, Alga> .GetSubset(Organisms))
     {
         if (alga.IsAlive)
         {
             alga.RegainHP();
             string str = string.Format("An alga just gained 1 HP and is now at {0} HP.", alga.HP);
             WriteToFile(str);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Used to manage fish reproduction.
        ///
        /// </summary>
        public void ReproduceFishes()
        {
            List <Organism> FishList = new List <Organism>();

            FishList = PseudoLink <Organism, Fish> .GetSubset(Organisms);

            foreach (Fish fish in FishList)
            {
                if (!IsFishHungry(fish))
                {
                    // TODO: maybe change this and reflect random encounter of fish and random element (be it fish or else)
                    // TODO: random encounters may be factorised into their own method (lunchtime and reproducefishes)
                    int  nbr       = CustomRandom.GetRandom(FishList.Count);
                    Fish otherFish = ((Fish)FishList[nbr]);

                    if (otherFish != fish)  // A fish cannot inseminate themselves!
                    {
                        /*
                         * Opportunistic hermaphrodism :
                         * If fish is a sole or a clownfish and encounters same species and same sex,
                         * fish will switch sex, then engage in (newly found) monogamistic encounter.
                         */
                        if ((fish is Sole || fish is Clownfish) &&
                            otherFish.GetType().Name.Equals(fish.GetType().Name) &&
                            fish.Gender == otherFish.Gender
                            )
                        {
                            fish.SwitchSex();
                        }

                        // Monogamistic encounter
                        if (fish.GetType().Name.Equals(otherFish.GetType().Name) &&
                            fish.Gender != otherFish.Gender && otherFish.IsAlive)
                        {
                            // Add newborn fish to list
                            Organisms.Add(fish.GiveBirth(fish));

                            string str = string.Format("\tThe {0}s {1} and {2} had a child together!\n", fish.GetType().Name, fish.Name, otherFish.Name);

                            Aquarium.DualOutput(str);
                        }
                    }
                }
            }
        }
示例#4
0
 /// <summary>
 /// Each turn, a fish gets angrier. Takes the form of losing 1 HP.
 /// </summary>
 public void StarveEveryFish()
 {
     Console.WriteLine("**********\nA fish needs a meal\n**********");
     // Each fish tries eating something
     foreach (Fish fish in PseudoLink <Organism, Fish> .GetSubset(Organisms))
     {
         if (fish.IsAlive)
         {
             fish.LoseHP();
             string str = string.Format("Fish of type {0} named {1}, {2}, {3} turns old is getting hungrier and loses 1 HP. They now have {4} HP.", fish.GetType().Name, fish.Name, fish.Gender, fish.Age, fish.HP);
             WriteToFile(str);
             if (IsFishHungry(fish))
             {
                 str = string.Format("{0} is now hungry and will try to find something to eat.", fish.Name);
                 WriteToFile(str);
             }
         }
     }
 }
示例#5
0
        /// <summary>
        /// Each organism of type fish gets one shot at eating.
        /// Tests are made to determine if random target can be eaten.
        /// Actions follow
        /// </summary>
        public void LunchTime()
        {
            Console.WriteLine("**********\nLunchTime Starts!\n**********");

            // Each fish tries to eat something
            foreach (Fish fish in PseudoLink <Organism, Fish> .GetSubset(Organisms))
            {
                // Get random element in Organisms. Send it to each fish. Conditions tested in Eat(Organism target)
                if (fish.IsAlive && fish.HP <= 5)
                {
                    int      nbr    = CustomRandom.GetRandom(Organisms.Count());
                    Organism target = Organisms[nbr];
                    if (target.IsAlive)
                    {
                        fish.Eat(Organisms[nbr]);
                    }
                }
            }
            Console.ResetColor();
            Console.WriteLine("**********\nLunchTime over! For now.\n**********");
        }
示例#6
0
        /// <summary>
        /// Gives account of aquarium's state at end of turn. Output to console.
        /// </summary>
        public void StatusDisplay()
        {
            List <Organism> ListFish = new List <Organism>();

            ListFish = PseudoLink <Organism, Fish> .GetSubset(Organisms);

            ListFish = PseudoLink <Organism> .GetIf(ListFish, IsOrganismAlive);

            string str = string.Format("At the end of turn {0}. {1} fishes alive. {2} algae alive. Still alive:",
                                       turn,
                                       PseudoLink <Organism> .GetCountWhen(ListFish, IsOrganismAlive),
                                       PseudoLink <Organism> .GetCountWhen((PseudoLink <Organism, Alga> .GetSubset(Organisms)), IsOrganismAlive));

            Console.WriteLine(str);
            WriteToFile(str);

            foreach (Fish fish in ListFish)
            {
                Console.WriteLine(" {0},", fish.Name);
            }
            ++turn;
        }