예제 #1
0
 public void RemoveOrganism()
 {
     this.Organism = null;
 }
예제 #2
0
 public void AddOrganism(Organism organism)
 {
     this.Organism = organism;
 }
예제 #3
0
 public Habitat(Environment environment, Organism organism)
 {
     this.Environment = environment;
     this.Organism = organism;
 }
예제 #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);
 }
예제 #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;
        }
예제 #6
0
 public void RemoveOrganism(Organism organism)
 {
     var habitat = this.OrganismHabitats[organism];
     habitat.RemoveOrganism();
     this.OrganismHabitats.Remove(organism);
 }