feat: 🔥 un java clean

This commit is contained in:
gdamms 2021-12-02 14:23:06 +01:00
parent d7f8d7766d
commit 87afcca542
9 changed files with 147 additions and 86 deletions

View file

@ -23,6 +23,20 @@ public class Action {
this.descriptions = descriptions; this.descriptions = descriptions;
} }
void actionner() {
for (Connaissance c : this.connaissances) {
if (!Jeu.explorateur.connaissances.contains(c)) {
Jeu.explorateur.connaissances.add(c);
}
}
for (Objet o : this.objetsRecus) {
Jeu.explorateur.objets.add(o);
}
for (Objet o : this.objetsConso) {
Jeu.explorateur.objets.remove(o);
}
}
@Override @Override
public String toString() { public String toString() {
for (Description d : this.descriptions) { for (Description d : this.descriptions) {

View file

@ -6,6 +6,6 @@ public class ConditionBoolean implements ConditionTest {
} }
public Boolean evaluer() { public Boolean evaluer() {
return bool; return this.bool;
} }
} }

View file

@ -18,9 +18,9 @@ public class Connaissance {
public String toString() { public String toString() {
for (Description d : this.descriptions) { for (Description d : this.descriptions) {
if (d.condition.evaluer()) { if (d.condition.evaluer()) {
return this.nom + ": " + d; return "(" + this.nom + " : " + d + ")";
} }
} }
return "No desc"; return "(" + this.nom + ")";
} }
} }

View file

@ -16,13 +16,15 @@ public class Explorateur {
@Override @Override
public String toString() { public String toString() {
String txt = new String(); String txt = "Objets :\n";
for (Objet c : this.objets) { for (Objet c : this.objets) {
txt.concat(c.toString()); txt += c + " ";
} }
txt += "\n\nConnaissances :\n";
for (Connaissance c : this.connaissances) { for (Connaissance c : this.connaissances) {
txt.concat(c.toString()); txt += c + " ";
} }
txt += "\n===================================================";
return txt; return txt;
} }

View file

@ -1,4 +1,8 @@
import java.util.List; import java.util.List;
import java.util.ArrayList;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Interaction { public class Interaction {
Condition visible; Condition visible;
@ -20,13 +24,44 @@ public class Interaction {
this.actions = actions; this.actions = actions;
} }
void interragir(BufferedReader reader, Lieu lieu) {
boolean arreter_interraction = false;
while (!arreter_interraction) {
System.out.println(this);
System.out.print("\nChoix : ");
List<Action> actions_choix = new ArrayList<>();
for (Action a : this.actions) {
if (a.visible.evaluer()) {
actions_choix.add(a);
}
}
int choix = 0;
Action a = null;
try {
choix = Integer.parseInt(reader.readLine());
a = actions_choix.get(choix);
} catch (NumberFormatException e) {
continue;
} catch (IndexOutOfBoundsException e) {
continue;
} catch (IOException e) {
e.printStackTrace();
}
a.actionner();
arreter_interraction = a.finInterraction.evaluer();
}
}
@Override @Override
public String toString() { public String toString() {
String res = "Interraction :"; String res = "";
int k = 0; int k = 0;
for (Action a : this.actions) { for (Action a : this.actions) {
if (a.visible.evaluer()) { if (a.visible.evaluer()) {
res += "\n" + k + " " + a; res += "[" + k + "] " + a + "\n";
k++; k++;
} }
} }

View file

@ -37,71 +37,44 @@ public class Jeu {
} }
while (!lieu.fin.evaluer()) { while (!lieu.fin.evaluer()) {
boolean recommencer = false;
System.out.println("\n\n\n\n\n\n\n\n\n\nLieu : " + lieu + "\n");
System.out.println(Jeu.explorateur); System.out.println(Jeu.explorateur);
boolean reverifier_interraction = true;
while (reverifier_interraction) {
reverifier_interraction = false;
for (Personne p : lieu.personnes) { for (Personne p : lieu.personnes) {
if (p.visible.evaluer() && p.obligatoire.evaluer()) { if (p.visible.evaluer() && p.obligatoire.evaluer()) {
for (Interaction i : p.interractions) { System.out.println(p + " :");
if (i.visible.evaluer()) {
System.out.println(i); p.interragir(reader, lieu);
boolean arreter_interraction = false; recommencer = true;
while (!arreter_interraction) { break;
List<Action> actions_choix = new ArrayList<>();
for (Action a : i.actions) {
if (a.visible.evaluer()) {
actions_choix.add(a);
} }
} }
int choix = 0; if (recommencer) {
try {
choix = Integer.parseInt(reader.readLine());
} catch (NumberFormatException e) {
continue; continue;
} catch (IOException e) {
e.printStackTrace();
}
Action a = actions_choix.get(choix);
for (Connaissance c : a.connaissances) {
if (!Jeu.explorateur.connaissances.contains(c)) {
Jeu.explorateur.connaissances.add(c);
}
}
for (Objet o : a.objetsRecus) {
Jeu.explorateur.objets.add(o);
}
for (Objet o : a.objetsConso) {
Jeu.explorateur.objets.remove(o);
} }
arreter_interraction = a.finInterraction.evaluer();
}
}
}
reverifier_interraction = true;
}
}
}
boolean chemin_pris = false;
for (Chemin c : territoire.chemins) { for (Chemin c : territoire.chemins) {
if (c.lieuIn == lieu) { if (c.lieuIn == lieu) {
if (c.visible.evaluer() && c.obligatoire.evaluer() && c.ouvert.evaluer()) { if (c.visible.evaluer() && c.obligatoire.evaluer() && c.ouvert.evaluer()) {
lieu = c.lieuOut; lieu = c.lieuOut;
chemin_pris = true; recommencer = true;
break;
} }
} }
} }
if (recommencer) {
continue;
}
if (!chemin_pris) {
int k = 0; int k = 0;
List<Chemin> chemins_choix = new ArrayList<>(); List<Chemin> chemins_choix = new ArrayList<>();
for (Chemin c : territoire.chemins) { for (Chemin c : territoire.chemins) {
if (c.lieuIn == lieu) { if (c.lieuIn == lieu) {
if (c.visible.evaluer() && c.ouvert.evaluer()) { if (c.visible.evaluer() && c.ouvert.evaluer()) {
chemins_choix.add(c); chemins_choix.add(c);
System.out.println(k + " " + c); System.out.println("[" + k + "] " + c);
k++; k++;
} }
} }
@ -112,7 +85,7 @@ public class Jeu {
if (lieu.personnes.contains(p)) { if (lieu.personnes.contains(p)) {
if (p.visible.evaluer()) { if (p.visible.evaluer()) {
personnes_choix.add(p); personnes_choix.add(p);
System.out.println(p); System.out.println("[" + k + "] " + p);
k++; k++;
} }
} }
@ -120,17 +93,25 @@ public class Jeu {
int choix = 0; int choix = 0;
try { try {
System.out.print("\nChoix : ");
choix = Integer.parseInt(reader.readLine()); choix = Integer.parseInt(reader.readLine());
} catch (NumberFormatException e) {
continue;
} catch (IOException e) {
e.printStackTrace();
}
if (choix < chemins_choix.size()) { if (choix < chemins_choix.size()) {
lieu = chemins_choix.get(choix).lieuOut; lieu = chemins_choix.get(choix).lieuOut;
} else { } else {
Personne p = personnes_choix.get(choix - chemins_choix.size());
System.out.println("\n\n\n\n\n\n\n\n\n\nLieu : " + lieu + "\n");
System.out.println(Jeu.explorateur);
System.out.println(p + " :");
p.interragir(reader, lieu);
} }
} catch (NumberFormatException e) {
continue;
} catch (IndexOutOfBoundsException e) {
continue;
} catch (IOException e) {
e.printStackTrace();
} }
} }
@ -297,6 +278,10 @@ public class Jeu {
List<Chemin> chemins = new ArrayList<>(); List<Chemin> chemins = new ArrayList<>();
List<Description> descriptions_chemin_enigme_succes = new ArrayList<>();
descriptions_chemin_enigme_succes.add(new Description("Route du succes", vraie));
Chemin enigme_succes = new Chemin( Chemin enigme_succes = new Chemin(
enigme, enigme,
succes, succes,
@ -306,9 +291,13 @@ public class Jeu {
new ArrayList<>(), new ArrayList<>(),
new ArrayList<>(), new ArrayList<>(),
new ArrayList<>(), new ArrayList<>(),
new ArrayList<>()); descriptions_chemin_enigme_succes);
chemins.add(enigme_succes); chemins.add(enigme_succes);
List<Description> descriptions_chemin_enigme_echec = new ArrayList<>();
descriptions_chemin_enigme_echec.add(new Description("Chemin de la mort", vraie));
Chemin enigme_echec = new Chemin( Chemin enigme_echec = new Chemin(
enigme, enigme,
echec, echec,
@ -318,7 +307,7 @@ public class Jeu {
new ArrayList<>(), new ArrayList<>(),
new ArrayList<>(), new ArrayList<>(),
new ArrayList<>(), new ArrayList<>(),
new ArrayList<>()); descriptions_chemin_enigme_echec);
chemins.add(enigme_echec); chemins.add(enigme_echec);
Territoire territoire = new Territoire( Territoire territoire = new Territoire(

View file

@ -28,4 +28,9 @@ public class Lieu {
this.objets = objets; this.objets = objets;
this.connaissances = connaissances; this.connaissances = connaissances;
} }
@Override
public String toString() {
return nom;
}
} }

View file

@ -21,9 +21,9 @@ public class Objet {
public String toString() { public String toString() {
for (Description d : this.descriptions) { for (Description d : this.descriptions) {
if (d.condition.evaluer()) { if (d.condition.evaluer()) {
return this.nom + ": " + d; return "(" + this.nom + ": " + d + ")";
} }
} }
return "No desc"; return "(" + this.nom + ")";
} }
} }

View file

@ -1,4 +1,6 @@
import java.util.List; import java.util.List;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Personne { public class Personne {
String nom; String nom;
@ -16,4 +18,18 @@ public class Personne {
this.obligatoire = obligatoire; this.obligatoire = obligatoire;
this.interractions = interractions; this.interractions = interractions;
} }
void interragir(BufferedReader reader, Lieu lieu) {
for (Interaction i : this.interractions) {
if (i.visible.evaluer()) {
i.interragir(reader, lieu);
}
break;
}
}
@Override
public String toString() {
return nom;
}
} }