2021-12-09 17:54:08 +00:00
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class Jeu {
|
|
|
|
public static Explorateur explorateur;
|
|
|
|
Territoire territoire;
|
|
|
|
List<Objet> objets;
|
|
|
|
List<Connaissance> connaissances;
|
|
|
|
List<Personne> personnes;
|
|
|
|
List<Transformation> transformations;
|
|
|
|
|
2022-01-16 17:14:57 +00:00
|
|
|
Lieu lieu = null;
|
|
|
|
Personne personne = null;
|
|
|
|
|
2021-12-09 17:54:08 +00:00
|
|
|
public Jeu(
|
|
|
|
Territoire territoire,
|
|
|
|
List<Objet> objets,
|
|
|
|
List<Connaissance> connaissances,
|
|
|
|
List<Personne> personnes,
|
|
|
|
List<Transformation> transformations) {
|
|
|
|
this.territoire = territoire;
|
|
|
|
this.objets = objets;
|
|
|
|
this.connaissances = connaissances;
|
|
|
|
this.personnes = personnes;
|
|
|
|
this.transformations = transformations;
|
|
|
|
}
|
|
|
|
|
2021-12-10 14:19:47 +00:00
|
|
|
public static void clearScreen() {
|
|
|
|
System.out.print("\033[H\033[2J");
|
|
|
|
System.out.flush();
|
|
|
|
}
|
|
|
|
|
2021-12-09 17:54:08 +00:00
|
|
|
void jouer() {
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
|
|
|
|
2022-01-16 17:14:57 +00:00
|
|
|
// on cherche le (premier) lieu de départ
|
2021-12-09 17:54:08 +00:00
|
|
|
for (Lieu l : territoire.lieux) {
|
|
|
|
if (l.depart.evaluer()) {
|
|
|
|
lieu = l;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 17:14:57 +00:00
|
|
|
// tant qu'on est pas sur un lieu de fin
|
|
|
|
mainloop: while (!lieu.fin.evaluer()) {
|
2021-12-09 17:54:08 +00:00
|
|
|
|
2021-12-10 14:19:47 +00:00
|
|
|
clearScreen();
|
2022-01-16 17:14:57 +00:00
|
|
|
System.out.println("Lieu actuel: " + lieu + "\n");
|
|
|
|
System.out.println("Explorateur:\n" + Jeu.explorateur + "\n");
|
|
|
|
System.out.println("-".repeat(50));
|
2021-12-09 17:54:08 +00:00
|
|
|
|
|
|
|
for (Personne p : lieu.personnes) {
|
2022-01-16 17:14:57 +00:00
|
|
|
if (p.visible.evaluer() && p.obligatoire.evaluer() || p == personne) {
|
2021-12-09 17:54:08 +00:00
|
|
|
System.out.println(p + " :");
|
|
|
|
|
|
|
|
p.interragir(reader, lieu);
|
2022-01-16 17:14:57 +00:00
|
|
|
personne = null;
|
|
|
|
continue mainloop;
|
2021-12-09 17:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Chemin c : territoire.chemins) {
|
|
|
|
if (c.lieuIn == lieu) {
|
|
|
|
if (c.visible.evaluer() && c.obligatoire.evaluer() && c.ouvert.evaluer()) {
|
|
|
|
lieu = c.lieuOut;
|
2022-01-16 17:14:57 +00:00
|
|
|
continue mainloop;
|
2021-12-09 17:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int k = 0;
|
|
|
|
List<Chemin> chemins_choix = new ArrayList<>();
|
|
|
|
for (Chemin c : territoire.chemins) {
|
|
|
|
if (c.lieuIn == lieu) {
|
|
|
|
if (c.visible.evaluer() && c.ouvert.evaluer()) {
|
|
|
|
chemins_choix.add(c);
|
|
|
|
System.out.println("[" + k + "] " + c);
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Personne> personnes_choix = new ArrayList<>();
|
|
|
|
for (Personne p : personnes) {
|
|
|
|
if (lieu.personnes.contains(p)) {
|
|
|
|
if (p.visible.evaluer()) {
|
|
|
|
personnes_choix.add(p);
|
|
|
|
System.out.println("[" + k + "] " + p);
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int choix = 0;
|
|
|
|
try {
|
|
|
|
System.out.print("\nChoix : ");
|
|
|
|
choix = Integer.parseInt(reader.readLine());
|
2022-01-16 17:14:57 +00:00
|
|
|
|
2021-12-09 17:54:08 +00:00
|
|
|
if (choix < chemins_choix.size()) {
|
2022-01-16 17:14:57 +00:00
|
|
|
lieu = chemins_choix.get(choix).emprunter();
|
2021-12-09 17:54:08 +00:00
|
|
|
} else {
|
2022-01-16 17:14:57 +00:00
|
|
|
personne = personnes_choix.get(choix - chemins_choix.size());
|
2021-12-09 17:54:08 +00:00
|
|
|
}
|
2022-01-16 17:14:57 +00:00
|
|
|
} catch (Exception e) {
|
2021-12-09 17:54:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("FIN : " + lieu.nom);
|
|
|
|
}
|
|
|
|
}
|