LesSyms4/src/SimulationJeu.java

138 lines
3.9 KiB
Java
Raw Normal View History

2015-01-07 09:41:16 +00:00
import Cases.CaseAbstraite;
2014-12-03 08:13:23 +00:00
import Fabriques.Scenario.FabriqueScenarioAbstraite;
import Objets.ObjetAbstrait;
import Objets.ObjetAvecBonusForce;
import Objets.ObjetAvecBonusPV;
import Objets.ObjetAvecBonusVitesse;
2014-12-03 08:13:23 +00:00
import Observateur.Organisation;
import Person.Personnage;
import utils.InterfaceConsole;
2014-10-03 13:34:03 +00:00
import java.util.ArrayList;
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;
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);
intefaceC = new InterfaceConsole(plateau);
2014-10-03 13:34:03 +00:00
}
2015-01-07 09:41:16 +00:00
public void afficheTous() {
System.out.println("");
intefaceC.afficherPlateau();
2014-10-03 13:34:03 +00:00
}
public void recupererInformations() {
2015-01-31 10:03:59 +00:00
for (Personnage p : personnages) {
2014-10-03 13:34:03 +00:00
}
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;
afficheTous();
2015-01-07 09:41:16 +00:00
while (continuer) {
for (Personnage p : personnages) {
p.Execution(p.AnalyseSituation());
2015-01-07 09:41:16 +00:00
recupererInformations();
}
placerDesObjets();
afficheTous();
2015-01-07 09:41:16 +00:00
// 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
private void placerDesObjets() {
if (new Random().nextInt(2) == 1) {
if (new Random().nextInt(3) == 1) {
placementObjet(new ObjetAvecBonusPV("Toto", 10, 10, 10));
}
if (new Random().nextInt(3) == 2) {
placementObjet(new ObjetAvecBonusVitesse("Toto", 10, 10, 10));
}
if (new Random().nextInt(3) == 3) {
placementObjet(new ObjetAvecBonusForce("tptp", 10, 10, 10));
}
}
}
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);
// int x = 0;
// int y = 0;
2015-01-31 10:03:59 +00:00
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
private void placementObjet(ObjetAbstrait o) {
Random rand = new Random();
int x = rand.nextInt(plateau.length);
int y = rand.nextInt(plateau[x].length);
o.setCaseCourante(plateau[x][y]);
plateau[x][y].setObjetOccupant(o);
}
2015-01-07 09:41:16 +00:00
// Todo Save
2015-01-20 18:16:30 +00:00
private void enregistrerSimulation(String NomFichier) {
// Todo
//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");
//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);
//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);
//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);
//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
}