public void RemoveOrganism()
 {
     this.Organism = null;
 }
 public void AddOrganism(Organism organism)
 {
     this.Organism = organism;
 }
 public Habitat(Environment environment, Organism organism)
 {
     this.Environment = environment;
     this.Organism = organism;
 }
 public void AddOrganism(Organism organism, Coordinates location)
 {
     var habitat = this.Habitats[location.X, location.Y];
     habitat.AddOrganism(organism);
     this.OrganismHabitats.Add(organism, habitat);
 }
        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;
        }
 public void RemoveOrganism(Organism organism)
 {
     var habitat = this.OrganismHabitats[organism];
     habitat.RemoveOrganism();
     this.OrganismHabitats.Remove(organism);
 }