mirror of
https://forge.univ-lyon1.fr/tplifap4/gyromite_ya.git
synced 2024-02-27 13:31:49 +01:00
aller retour IA
This commit is contained in:
parent
1cba55e095
commit
2b2e5cda5c
@ -10,5 +10,10 @@ package modele.calculs;
|
||||
*
|
||||
*/
|
||||
public enum Direction {
|
||||
haut, bas, gauche, droite, action
|
||||
}
|
||||
haut, bas, gauche, droite, action;
|
||||
|
||||
public static Direction inversDir(Direction direct) {
|
||||
return direct == droite ? gauche : direct == gauche ? droite : null;
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +1,40 @@
|
||||
package modele.calculs;
|
||||
|
||||
import modele.donnees.ElementDynamique;
|
||||
import modele.donnees.ElementFond;
|
||||
import modele.donnees.Entite;
|
||||
import modele.donnees.Heros;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class IA extends RealisateurDeDeplacement {
|
||||
int alt = 0;
|
||||
Direction d = Direction.droite;
|
||||
|
||||
int genererInt(int borneInf, int borneSup){
|
||||
Random rand = new Random();
|
||||
int nb;
|
||||
nb = borneInf+rand.nextInt(borneSup-borneInf);
|
||||
return nb;
|
||||
}
|
||||
|
||||
int alt = 0;
|
||||
protected boolean realiserDeplacement() {
|
||||
for (ElementDynamique e : lstEntitesDynamiques)
|
||||
if (e instanceof modele.donnees.IA) {
|
||||
if(alt < 3){
|
||||
alt++;
|
||||
}else{
|
||||
e.avancerDirectionChoisie(null);
|
||||
alt = 0;
|
||||
if (alt < 3) {
|
||||
alt++;
|
||||
} else {
|
||||
modele.donnees.IA ia = (modele.donnees.IA) e;
|
||||
if(ia.avancerDirectionChoisieunique(d) == false){
|
||||
d = Direction.inversDir(d);
|
||||
ia.avancerDirectionChoisieunique(d);
|
||||
}else if(ia.regarderDansLaDirection(d) instanceof Heros){
|
||||
ia.avancerDirectionChoisie(null); // TODO
|
||||
} else {
|
||||
ia.avancerDirectionChoisieunique(d);
|
||||
}
|
||||
|
||||
alt = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ public class IA extends Entite {
|
||||
return super.avancerDirectionChoisie(jeu.getDirection(this, jeu.getHector()));
|
||||
}
|
||||
|
||||
public boolean avancerDirectionChoisieunique(Direction d) {
|
||||
return jeu.deplacerEntite(this, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean peutEtreEcrase() {
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user