Analyse de la situation et déplacement.

This commit is contained in:
amine 2015-02-01 11:50:15 +01:00
parent 6e4e647866
commit 8e08b9c8df
22 changed files with 202 additions and 197 deletions

View File

@ -4,8 +4,7 @@
<entry_points version="2.0" />
</component>
<component name="IdProvider" IDEtalkID="5EBAA9F33699B0593DE250C306D65C2A" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -87,4 +87,12 @@ public abstract class CaseAbstraite {
}
public abstract String affichageSpecial();
public Coordonnees getCoord() {
return coord;
}
public void setCoord(Coordonnees coord) {
this.coord = coord;
}
}

View File

@ -24,4 +24,9 @@ public class Coordonnees {
public void setCol(int col) {
this.col = col;
}
@Override
public String toString() {
return "col " + getCol() + " ligne " + getLigne();
}
}

View File

@ -1,7 +1,12 @@
package Comportements;
import Cases.CaseAbstraite;
import Objets.ObjetAbstrait;
import Person.Personnage;
import utils.Tuple;
import java.util.ArrayList;
public interface ComportementAction {
public void executerAction(Personnage joueur);
public void executerAction(Personnage joueur, Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>> t);
}

View File

@ -1,15 +1,31 @@
package Comportements;
import Cases.CaseAbstraite;
import Cases.CaseColore;
import Objets.ObjetAbstrait;
import Person.Personnage;
import Person.PersonnageBattleZone;
import utils.Tuple;
import java.util.ArrayList;
import java.util.Random;
public class ComportementActionChangerCouleurCase implements ComportementAction {
@Override
public void executerAction(Personnage p) {
public void executerAction(Personnage p, Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>> t) {
ArrayList<CaseAbstraite> cases = t.c;
int size = cases.size();
int item = new Random().nextInt(size);
CaseColore caseColore = (CaseColore) p.getCaseCourante();
PersonnageBattleZone personnage = (PersonnageBattleZone) p;
caseColore.setCouleur(personnage.getCouleur());
caseColore.setOccupant(null);
CaseColore dest = (CaseColore) cases.get(item);
dest.setOccupant(p);
p.setCaseCourante(dest);
dest.setCouleur(personnage.getCouleur());
}
}

View File

@ -1,11 +1,16 @@
package Comportements;
import Cases.CaseAbstraite;
import Objets.ObjetAbstrait;
import Person.Personnage;
import utils.Tuple;
import java.util.ArrayList;
public class ComportementActionRamasserNeige implements ComportementAction {
@Override
public void executerAction(Personnage joueur) {
public void executerAction(Personnage joueur, Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>> t) {
}
}

View File

@ -1,27 +1,30 @@
package Comportements;
import Cases.CaseAbstraite;
import Cases.PointsCardinaux;
import Cases.RandomPointCardinal;
import Objets.ObjetAbstrait;
import Person.Personnage;
import utils.Tuple;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Random;
public class ComportementActionSeDeplacer implements ComportementAction {
@Override
public void executerAction(Personnage perso) {
public void executerAction(Personnage perso, Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>> t) {
ArrayList<CaseAbstraite> cases = t.c;
int size = cases.size();
int item = new Random().nextInt(size);
System.out.println("Je suis en " + perso.getCaseCourante().getCoord().toString());
CaseAbstraite c = perso.getCaseCourante();
HashMap<PointsCardinaux, CaseAbstraite> voisins = c.getVoisins();
RandomPointCardinal<PointsCardinaux> p = new RandomPointCardinal<PointsCardinaux>(PointsCardinaux.class);
PointsCardinaux point = null;
do {
point = p.random();
} while (voisins.get(point) == null);
CaseAbstraite destination = voisins.get(point);
CaseAbstraite destination = cases.get(item);
destination.setOccupant(perso);
perso.setCaseCourante(destination);
c.setOccupant(null);
System.out.println("Je suis en " + perso.getCaseCourante().getCoord().toString());
}
}

View File

@ -1,11 +1,16 @@
package Comportements;
import Cases.CaseAbstraite;
import Objets.ObjetAbstrait;
import Person.Personnage;
import utils.Tuple;
import java.util.ArrayList;
public class ComportementActionTirerBalon implements ComportementAction {
@Override
public void executerAction(Personnage joueur) {
public void executerAction(Personnage joueur, Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>> t) {
}
}

View File

@ -1,11 +1,16 @@
package Comportements;
import Cases.CaseAbstraite;
import Objets.ObjetAbstrait;
import Person.Personnage;
import utils.Tuple;
import java.util.ArrayList;
public class ComportementActionTirerBouleDeNeige implements ComportementAction {
@Override
public void executerAction(Personnage joueur) {
public void executerAction(Personnage joueur, Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>> t) {
}
}

View File

@ -1,5 +1,5 @@
package Comportements;
public enum EAction {
ChangerCouleurCase,RamasserNeige,SeDeplacer,TirerBalon,TirerBouleDeNeige,Null
ChangerCouleurCase, RamasserNeige, SeDeplacer, TirerBalon, TirerBouleDeNeige
}

View File

@ -4,11 +4,8 @@ import Person.Personnage;
public class EtatPersonnageOK extends EtatPersonnageAbstrait {
private int nbTourKO;
public EtatPersonnageOK(Personnage perso) {
super(perso);
this.nbTourKO = 3;
}
@Override

View File

@ -1,11 +1,9 @@
package Objets;
import Cases.CaseAbstraite;
import Person.Personnage;
public abstract class ObjetAbstrait {
protected CaseAbstraite caseCourante;
protected Personnage perso;
protected String nom;
protected double pointsDeVie;
protected double force;
@ -16,8 +14,6 @@ public abstract class ObjetAbstrait {
this.pointsDeVie = 100;
this.force = 10;
this.vitesse = 1;
this.perso = null;
this.caseCourante = null;
}
@ -26,9 +22,7 @@ public abstract class ObjetAbstrait {
this.pointsDeVie=lifePoint;
this.force=strength;
this.vitesse=speed;
this.caseCourante=null;
this.perso = null;
}
public CaseAbstraite getCaseCourante() {
@ -70,12 +64,4 @@ public abstract class ObjetAbstrait {
public void setVitesse(double vitesse) {
this.vitesse = vitesse;
}
public Personnage getPerso() {
return perso;
}
public void setPerso(Personnage perso) {
this.perso = perso;
}
}

View File

@ -8,6 +8,12 @@ public class ObjetAvecBonusForce extends ObjetAbstrait {
super(name, lifePoint, strength, speed);
// TODO Auto-generated constructor stub
}
public double getPointsDeVie() {return perso.getPointsDeVie() + 20;}
public double getForce() {return perso.getForce() + 0.5;}
public double getPointsDeVie() {
return 20;
}
public double getForce() {
return 0.5;
}
}

View File

@ -8,5 +8,7 @@ public class ObjetAvecBonusPV extends ObjetAbstrait {
// TODO Auto-generated constructor stub
}
public double getPointsDeVie() {return perso.getPointsDeVie() + 80;}
public double getPointsDeVie() {
return 80;
}
}

View File

@ -8,5 +8,7 @@ public class ObjetAvecBonusVitesse extends ObjetAbstrait {
// TODO Auto-generated constructor stub
}
public double getPointsDeVie() {return perso.getVitesse() + 2;}
public double getPointsDeVie() {
return 2;
}
}

View File

@ -9,6 +9,7 @@ import Etats.EtatPersonnageAbstrait;
import Etats.EtatPersonnageKO;
import Etats.EtatPersonnageOK;
import Objets.ObjetAbstrait;
import utils.Tuple;
import java.util.ArrayList;
import java.util.HashMap;
@ -18,6 +19,7 @@ public class Personnage extends PersonnagesAbstraits {
protected CaseAbstraite caseCourante;
protected ObjetAbstrait objet;
protected String nom;
protected String groupe;
protected double pointsDeVie;
@ -73,95 +75,20 @@ public class Personnage extends PersonnagesAbstraits {
}
}
public Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>> AnalyseSituation() {
HashSet<CaseAbstraite> voisinsDesVoisins = getCaseAbstraitesForPortee();
ArrayList<CaseAbstraite> casesVoisines = new ArrayList<CaseAbstraite>(voisinsDesVoisins);
ArrayList<ObjetAbstrait> objets = rechercheObjetProche(voisinsDesVoisins);
ArrayList<Personnage> personnages = rechercheJoueur(voisinsDesVoisins);
public EtatPersonnageAbstrait getEtatCourant() {
return etatCourant;
}
public void setEtatCourant(EtatPersonnageAbstrait etatCourant) {
this.etatCourant = etatCourant;
}
public double getPointsDeVie() {
return pointsDeVie;
}
public void setPointsDeVie(double pointsDeVie) {
this.pointsDeVie = pointsDeVie;
}
public double getForce() {
return force;
}
public void setForce(double force) {
this.force = force;
}
public double getVitesse() {
return vitesse;
}
public void setVitesse(double vitesse) {
this.vitesse = vitesse;
}
public String getGroupe() {
return groupe;
}
public void setGroupe(String equipe) {
groupe = equipe;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public CaseAbstraite getCaseCourante() {
return caseCourante;
casesVoisines.remove(this.caseCourante);
return new Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>>(objets, personnages, casesVoisines);
}
public void setCaseCourante(CaseAbstraite caseCourante) {
this.caseCourante = caseCourante;
this.voisins = this.caseCourante.getVoisins();
public void Execution(Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>> t) {
Action.executerAction(this, t);
}
public double getPortee() {
return portee;
}
public void setPortee(double portee) {
this.portee = portee;
}
public EAction getAction() {
return action;
}
public void setAction(EAction action) {
this.action = action;
}
public void AnalyseSituation() {
ArrayList<ObjetAbstrait> objets = rechercheObjetProche();
ArrayList<Personnage> personnages = rechercheJoueur();
}
public void Execution() {
Action.executerAction(this);
}
public void ResoudreLesConflits(){
}
public HashMap<PointsCardinaux, CaseAbstraite> voisinsPortee(CaseAbstraite c, int rayon) {
HashMap<PointsCardinaux, CaseAbstraite> voisinsActuels = new HashMap<PointsCardinaux, CaseAbstraite>();
@ -178,12 +105,9 @@ public class Personnage extends PersonnagesAbstraits {
}
}
public ArrayList<ObjetAbstrait> rechercheObjetProche() {
public ArrayList<ObjetAbstrait> rechercheObjetProche(HashSet<CaseAbstraite> voisinsDesVoisins) {
ArrayList<ObjetAbstrait> objetsVoisins = new ArrayList<ObjetAbstrait>();
HashSet<CaseAbstraite> voisinsDesVoisins = getCaseAbstraitesForPortee();
for (CaseAbstraite c : voisinsDesVoisins) {
if (c.getObjetOccupant() != null) {
objetsVoisins.add(c.getObjetOccupant());
@ -199,11 +123,8 @@ public class Personnage extends PersonnagesAbstraits {
}
public ArrayList<Personnage> rechercheJoueur() {
public ArrayList<Personnage> rechercheJoueur(HashSet<CaseAbstraite> voisinsDesVoisins) {
ArrayList<Personnage> personnes = new ArrayList<Personnage>();
HashSet<CaseAbstraite> voisinsDesVoisins = getCaseAbstraitesForPortee();
for (CaseAbstraite c : voisinsDesVoisins) {
if (c.getOccupant() != null) {
personnes.add(c.getOccupant());
@ -243,4 +164,79 @@ public class Personnage extends PersonnagesAbstraits {
this.setAction(nouvelAction);
}
public ObjetAbstrait getObjet() {
return objet;
}
public void setObjet(ObjetAbstrait objet) {
this.objet = objet;
}
public double getPointsDeVie() {
double bonus = 0;
if (getObjet() != null) {
bonus = getObjet().getPointsDeVie();
}
return bonus + pointsDeVie;
}
public double getForce() {
double bonus = 0;
if (getObjet() != null) {
bonus = getObjet().getForce();
}
return bonus + force;
}
public double getVitesse() {
double bonus = 0;
if (getObjet() != null) {
bonus = getObjet().getVitesse();
}
return bonus + vitesse;
}
public String getGroupe() {
return groupe;
}
public void setGroupe(String equipe) {
groupe = equipe;
}
public String getNom() {
return nom;
}
public CaseAbstraite getCaseCourante() {
return caseCourante;
}
public void setCaseCourante(CaseAbstraite caseCourante) {
this.caseCourante = caseCourante;
this.voisins = this.caseCourante.getVoisins();
}
public double getPortee() {
return portee;
}
public EAction getAction() {
return action;
}
public void setAction(EAction action) {
this.action = action;
}
public HashMap<PointsCardinaux, CaseAbstraite> getVoisins() {
return voisins;
}
public void setVoisins(HashMap<PointsCardinaux, CaseAbstraite> voisins) {
this.voisins = voisins;
}
}

View File

@ -1,15 +0,0 @@
package Person;
import Objets.ObjetAvecBonusVitesse;
public class PersonnageBattleZoneAvecUnHoverboard extends ObjetAvecBonusVitesse {
protected PersonnageBattleZoneAvecUnHoverboard(String name,
double lifePoint, double strength, double speed, PersonnageBattleZone PBZ) {
super(name, lifePoint, strength, speed);
// TODO Auto-generated constructor stub
this.perso=PBZ;
}
}

View File

@ -1,15 +0,0 @@
package Person;
import Objets.ObjetAvecBonusForce;
public class PersonnageBattleZoneAvecUnMarteau extends ObjetAvecBonusForce {
protected PersonnageBattleZoneAvecUnMarteau(String name, double lifePoint,
double strength, double speed, PersonnageBattleZone PBZ) {
super(name, lifePoint, strength, speed);
// TODO Auto-generated constructor stub
this.perso=PBZ;
}
}

View File

@ -1,15 +0,0 @@
package Person;
import Objets.ObjetAvecBonusPV;
public class PersonnageBattleZoneAvecUneArmure extends ObjetAvecBonusPV {
protected PersonnageBattleZoneAvecUneArmure(String name, double lifePoint,
double strength, double speed, PersonnageBattleZone PBZ) {
super(name, lifePoint, strength, speed);
// TODO Auto-generated constructor stub
this.perso=PBZ;
}
}

View File

@ -1,8 +1,10 @@
import Cases.CaseAbstraite;
import Fabriques.Scenario.FabriqueScenarioAbstraite;
import Objets.ObjetAbstrait;
import Observateur.Organisation;
import Person.Personnage;
import utils.InterfaceConsole;
import utils.Tuple;
import java.util.ArrayList;
import java.util.Random;
@ -33,29 +35,24 @@ public class SimulationJeu {
intefaceC.afficherPlateau();
}
public void mediationDesConflits() {
for (Personnage p : personnages) {
p.mediationConflits();
}
}
public void recupererInformations() {
// TODO récup infos + statistics + maj infos observateur ?
for (Personnage p : personnages) {
}
}
public void lancerJeu() {
placement();
boolean continuer = true;
afficheTous();
while (continuer) {
afficheTous();
for (Personnage p : personnages) {
p.AnalyseSituation();
p.Execution();
mediationDesConflits(); // utiliser le pattern avec l'historique pour les actions. On pourra faire un retour arrière si conflit + réexecturer
Tuple<ArrayList<ObjetAbstrait>, ArrayList<Personnage>, ArrayList<CaseAbstraite>> t = p.AnalyseSituation();
p.Execution(t);
recupererInformations();
}
afficheTous();
// bloquer le tour jusqu'a toucher une touche du clavier.
Scanner s = new Scanner(System.in);
s.nextLine();

View File

@ -10,12 +10,12 @@ public class InterfaceConsole {
}
public void afficherPlateau() {
for (int i = 0; i < plateau.length; i++) {
for (int j = 0; j < plateau[i].length; j++) {
if (plateau[i][j].getOccupant() != null) {
System.out.print(plateau[i][j].getOccupant().getNom().charAt(0) + " | ");
for (CaseAbstraite[] aPlateau : plateau) {
for (CaseAbstraite anAPlateau : aPlateau) {
if (anAPlateau.getOccupant() != null) {
System.out.print(anAPlateau.getOccupant().getNom().charAt(0) + " | ");
} else {
System.out.print(" " + plateau[i][j].affichageSpecial() + " | ");
System.out.print(" " + anAPlateau.affichageSpecial() + " | ");
}
}
System.out.println();

13
src/utils/Tuple.java Normal file
View File

@ -0,0 +1,13 @@
package utils;
public class Tuple<P, O, C> {
public final P p;
public final O o;
public final C c;
public Tuple(P p, O o, C c) {
this.p = p;
this.o = o;
this.c = c;
}
}