Advertisement
alefo

Untitled

Aug 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. static void AnimauxCroise(Ferme p_Ferme)
  2. {
  3.     Ferme dejaTeste = new Ferme();
  4.  
  5.     foreach (Animal animalA in p_Ferme)
  6.     {
  7.  
  8.         foreach (Animal animalB in p_Ferme)
  9.         {
  10.             if (!animalB.Equals(animalA))
  11.             {
  12.                 // On regarde si l'animal qu'on veut tester n'a pas déjà été testé
  13.                 bool tested = false;
  14.                 foreach (Animal deja in dejaTeste)
  15.                 {
  16.                     tested = tested || deja.Equals(animalB);
  17.                 }
  18.  
  19.                 if (!tested)
  20.                 {
  21.                     DateTime mortA = animalA.Arrivée.Add(animalA.Age);
  22.                     DateTime mortB = animalB.Arrivée.Add(animalB.Age);
  23.  
  24.                     if ((mortB.CompareTo(animalA.Arrivée) >= 0 && mortB.CompareTo(mortA) <= 0) ||
  25.                         (mortA.CompareTo(animalB.Arrivée) >= 0 && mortA.CompareTo(mortB) <= 0))
  26.                     {
  27.                         Console.Out.WriteLine(animalA.Nom + " a croisé " + animalB.Nom);
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.         dejaTeste.Ajouter(animalA);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement