2015-01-07 09:41:16 +00:00
|
|
|
|
import Cases.CaseAbstraite;
|
2014-12-03 08:13:23 +00:00
|
|
|
|
import Fabriques.Scenario.FabriqueScenarioAbstraite;
|
|
|
|
|
import Observateur.Organisation;
|
|
|
|
|
import Person.Personnage;
|
2015-01-27 17:14:56 +00:00
|
|
|
|
import utils.InterfaceConsole;
|
2014-10-03 13:34:03 +00:00
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2015-01-27 17:14:56 +00:00
|
|
|
|
import java.util.Random;
|
2015-01-07 09:41:16 +00:00
|
|
|
|
import java.util.Scanner;
|
2014-10-03 13:34:03 +00:00
|
|
|
|
|
2015-01-20 18:16:30 +00:00
|
|
|
|
|
2014-10-03 13:34:03 +00:00
|
|
|
|
public class SimulationJeu {
|
2015-01-07 09:41:16 +00:00
|
|
|
|
ArrayList<Personnage> personnages;
|
|
|
|
|
CaseAbstraite[][] plateau;
|
2014-10-03 15:20:49 +00:00
|
|
|
|
Organisation o;
|
2014-12-03 08:13:23 +00:00
|
|
|
|
FabriqueScenarioAbstraite f;
|
2015-01-27 17:14:56 +00:00
|
|
|
|
InterfaceConsole intefaceC;
|
2015-01-20 18:16:30 +00:00
|
|
|
|
|
2014-12-03 08:13:23 +00:00
|
|
|
|
public SimulationJeu(FabriqueScenarioAbstraite fb) {
|
|
|
|
|
f = fb;
|
2015-01-07 09:41:16 +00:00
|
|
|
|
personnages = new ArrayList<Personnage>();
|
|
|
|
|
plateau = f.CreerPlateau();
|
|
|
|
|
|
|
|
|
|
// L'organisation dans les personnages. On aura une orga spécifique pour chaque
|
|
|
|
|
o = new Organisation();
|
|
|
|
|
personnages = f.CreerPersonnages(o);
|
|
|
|
|
|
2015-01-27 17:14:56 +00:00
|
|
|
|
intefaceC = new InterfaceConsole(plateau);
|
|
|
|
|
|
2014-10-03 13:34:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 09:41:16 +00:00
|
|
|
|
public void afficheTous() {
|
2015-01-27 17:14:56 +00:00
|
|
|
|
intefaceC.afficherPlateau();
|
2014-10-03 13:34:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 09:41:16 +00:00
|
|
|
|
public void mediationDesConflits() {
|
2015-01-31 10:03:59 +00:00
|
|
|
|
for (Personnage p : personnages) {
|
|
|
|
|
p.mediationConflits();
|
|
|
|
|
}
|
2014-10-03 13:34:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 09:41:16 +00:00
|
|
|
|
public void recupererInformations() {
|
|
|
|
|
// TODO récup infos + statistics + maj infos observateur ?
|
2014-10-03 13:34:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 09:41:16 +00:00
|
|
|
|
public void lancerJeu() {
|
2015-01-31 10:03:59 +00:00
|
|
|
|
placement();
|
2015-01-07 09:41:16 +00:00
|
|
|
|
|
|
|
|
|
boolean continuer = true;
|
|
|
|
|
while (continuer) {
|
2015-02-01 09:33:56 +00:00
|
|
|
|
afficheTous();
|
2015-01-07 09:41:16 +00:00
|
|
|
|
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
|
|
|
|
|
recupererInformations();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// bloquer le tour jusqu'a toucher une touche du clavier.
|
|
|
|
|
Scanner s = new Scanner(System.in);
|
|
|
|
|
s.nextLine();
|
2014-10-03 13:34:03 +00:00
|
|
|
|
}
|
2015-01-07 09:41:16 +00:00
|
|
|
|
|
2014-10-03 13:34:03 +00:00
|
|
|
|
}
|
2014-10-03 15:20:49 +00:00
|
|
|
|
|
2015-01-31 10:03:59 +00:00
|
|
|
|
private void placement() {
|
|
|
|
|
Random rand = new Random();
|
|
|
|
|
for (Personnage p : personnages) {
|
|
|
|
|
int x = rand.nextInt(plateau.length);
|
|
|
|
|
int y = rand.nextInt(plateau[x].length);
|
|
|
|
|
p.setCaseCourante(plateau[x][y]);
|
|
|
|
|
plateau[x][y].ajouterOccupant(p);
|
|
|
|
|
}
|
2014-10-03 15:20:49 +00:00
|
|
|
|
}
|
2015-01-07 09:41:16 +00:00
|
|
|
|
|
|
|
|
|
// Todo Save
|
2015-01-20 18:16:30 +00:00
|
|
|
|
private void enregistrerSimulation(String NomFichier) {
|
|
|
|
|
// Todo
|
|
|
|
|
|
|
|
|
|
|
2015-01-27 17:14:56 +00:00
|
|
|
|
//Nous allons commencer notre arborescence en cr<63>ant la racine XML
|
2015-01-20 18:16:30 +00:00
|
|
|
|
//qui sera ici "personnes".
|
|
|
|
|
// static Element racine = new Element("personnes");
|
|
|
|
|
|
2015-01-27 17:14:56 +00:00
|
|
|
|
//On cr<63>e un nouveau Document JDOM bas<61> sur la racine que l'on vient de cr<63>er
|
2015-01-20 18:16:30 +00:00
|
|
|
|
// static org.jdom.Document document = new Document(racine);
|
|
|
|
|
|
2015-01-27 17:14:56 +00:00
|
|
|
|
//On cr<63>e un nouvel Element etudiant et on l'ajoute
|
2015-01-20 18:16:30 +00:00
|
|
|
|
//en tant qu'Element de racine
|
|
|
|
|
// Element etudiant = new Element("etudiant");
|
|
|
|
|
//racine.addContent(etudiant);
|
|
|
|
|
|
2015-01-27 17:14:56 +00:00
|
|
|
|
//On cr<63>e un nouvel Attribut classe et on l'ajoute <20> etudiant
|
|
|
|
|
//gr<67>ce <20> la m<>thode setAttribute
|
2015-01-20 18:16:30 +00:00
|
|
|
|
// Attribute classe = new Attribute("classe","P2");
|
|
|
|
|
// etudiant.setAttribute(classe);
|
|
|
|
|
|
2015-01-27 17:14:56 +00:00
|
|
|
|
//On cr<63>e un nouvel Element nom, on lui assigne du texte
|
2015-01-20 18:16:30 +00:00
|
|
|
|
//et on l'ajoute en tant qu'Element de etudiant
|
|
|
|
|
//Element nom = new Element("nom");
|
|
|
|
|
// nom.setText("CynO");
|
|
|
|
|
// etudiant.addContent(nom);
|
|
|
|
|
|
|
|
|
|
}
|
2015-01-07 09:41:16 +00:00
|
|
|
|
|
|
|
|
|
// Todo import
|
2015-01-20 18:16:30 +00:00
|
|
|
|
private void ChargerSimulation(String NomFichier) {
|
|
|
|
|
// Todo
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-03 13:34:03 +00:00
|
|
|
|
}
|