Example #1
0
 public void RemoveOrganism()
 {
     this.Organism = null;
 }
Example #2
0
 public void AddOrganism(Organism organism)
 {
     this.Organism = organism;
 }
Example #3
0
 public Habitat(Environment environment, Organism organism)
 {
     this.Environment = environment;
     this.Organism = organism;
 }
Example #4
0
 public void AddOrganism(Organism organism, Coordinates location)
 {
     var habitat = this.Habitats[location.X, location.Y];
     habitat.AddOrganism(organism);
     this.OrganismHabitats.Add(organism, habitat);
 }
Example #5
0
        private void MoveOrganism(Organism organism, Habitat destination)
        {
            var source = this.OrganismHabitats[organism];

            // the organism cannot move if it is dead
            if (!organism.IsAlive)
            {
                throw new InvalidOperationException(
                    string.Format("Cannot move organism {0} to {1} because it is dead",
                                   organism, destination));
            }

            // the organism can only move to the destination if it is not obstructed
            if (destination.IsObstructed())
            {
                throw new InvalidOperationException(
                    string.Format("Cannot move organism {0} to {1} because the destination is obstructed",
                                  organism, destination));
            }

            // the organism can only move to the destination if it does not already contain an organism
            if (destination.ContainsOrganism())
            {
                throw new InvalidOperationException(
                    string.Format("Cannot move organism {0} to {1} because the destination is occupied by {2}",
                                  organism, destination, destination.Organism));
            }

            source.RemoveOrganism();
            destination.AddOrganism(organism);
            this.OrganismHabitats[organism] = destination;
        }
Example #6
0
 public void RemoveOrganism(Organism organism)
 {
     var habitat = this.OrganismHabitats[organism];
     habitat.RemoveOrganism();
     this.OrganismHabitats.Remove(organism);
 }