-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6 done, insecte now have a special way to eat (ChasseHerbivore), Tou…
…rInsecte is mutch more easier to understand & full commented, new function isHungry in Creature.
- Loading branch information
1 parent
951e220
commit f4f6bac
Showing
7 changed files
with
159 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/fr/formiko/formiko/interfaces/ChasseHerbivore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package fr.formiko.formiko.interfaces; | ||
import fr.formiko.usuel.debug; import fr.formiko.usuel.erreur; import fr.formiko.usuel.g; import fr.formiko.formiko.Main; | ||
//def par défaut des fichiers depuis 0.79.5 | ||
import fr.formiko.formiko.Creature; | ||
import fr.formiko.formiko.Insecte; | ||
import java.io.Serializable; | ||
import fr.formiko.usuel.math.math; | ||
/** | ||
* {@summary Chasse implementation.<br/>} | ||
* Allow a creature to do hunt as an herbivore.<br/> | ||
* @author Hydrolien | ||
* @version 1.28 | ||
*/ | ||
public class ChasseHerbivore implements Serializable, Chasse { | ||
Creature c; | ||
public void chasser(Creature c, int directionSiPasDeProie){chasse(c);} | ||
/** | ||
*{@summary Hunt as an herbivore.<br>} | ||
*@version 1.28 | ||
*/ | ||
public void chasse(Creature c){ | ||
this.c=c; | ||
int nourritureMangeable = 1; | ||
if(c instanceof Insecte){nourritureMangeable=((Insecte)(c)).getNourritureMangeable();} | ||
if(c.getNourriture()<c.getNourritureMax()/2 && c.getCCase().getContenu().getNourritureInsecte() > nourritureMangeable){ | ||
manger(); | ||
}else{ | ||
c.ceDeplacer(true); // ce déplacer de façon alléatoire. | ||
} | ||
} | ||
|
||
/** | ||
*{@summary Eat as an herbivore.<br>} | ||
*@version 1.28 | ||
*/ | ||
public void manger(){ | ||
byte nourritureSurCase = c.getCCase().getContenu().getNourritureInsecte(); | ||
int nourritureMangeable = 1; | ||
if(c instanceof Insecte){nourritureMangeable=((Insecte)(c)).getNourritureMangeable();} | ||
if (nourritureSurCase > 0){ | ||
byte nourritureMangé = (byte) math.min(nourritureSurCase,nourritureMangeable); | ||
c.getCCase().getContenu().setNourritureInsecte((byte)(nourritureSurCase-nourritureMangé)); | ||
c.setNourriture(c.getNourriture() + nourritureMangé); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package fr.formiko.formiko; | ||
import fr.formiko.usuel.debug; import fr.formiko.usuel.erreur; import fr.formiko.usuel.g; import fr.formiko.formiko.Main; | ||
//def par défaut des fichiers depuis 0.79.5 | ||
import fr.formiko.formiko.Creature; | ||
import fr.formiko.usuel.test.TestCaseMuet; | ||
import org.junit.Test; | ||
import fr.formiko.formiko.Insecte; | ||
import fr.formiko.formiko.GCase; | ||
|
||
public class CreatureTest extends TestCaseMuet{ | ||
|
||
// Fonctions propre ----------------------------------------------------------- | ||
@Test | ||
public void testIsHungry(){ | ||
Main.initialisation(); | ||
GCase gc = new GCase(1,1); | ||
Insecte i = new Insecte(gc.getCCaseAlléa()); | ||
i.setNourritureMax(10); | ||
i.setNourriture(5); | ||
assertTrue(!i.isHungry(0)); | ||
assertTrue(!i.isHungry(20)); | ||
assertTrue(!i.isHungry(40)); | ||
assertTrue(!i.isHungry(49)); | ||
assertTrue(!i.isHungry(50)); | ||
assertTrue(i.isHungry(51)); | ||
assertTrue(i.isHungry(80)); | ||
assertTrue(i.isHungry(100)); | ||
//exception | ||
assertTrue(!i.isHungry(-20)); | ||
assertTrue(i.isHungry(200)); | ||
//more than full (should be correct by setNourriture(1) when setNourritureMax(1)). | ||
i.setNourriture(5); | ||
i.setNourritureMax(1); | ||
assertTrue(!i.isHungry(0)); | ||
assertTrue(!i.isHungry(100)); | ||
i.setNourritureMax(10); | ||
i.setNourriture(9); | ||
assertTrue(!i.isHungry(89)); | ||
assertTrue(i.isHungry(100)); | ||
i.setNourritureMax(100); | ||
i.setNourriture(2); | ||
assertTrue(!i.isHungry(2)); | ||
assertTrue(i.isHungry(3)); | ||
i.setNourritureMax(101); | ||
assertTrue(!i.isHungry(1)); | ||
assertTrue(i.isHungry(2)); | ||
assertTrue(i.isHungry(3)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters