projet-genie-logiciel-systeme/runtime-workspace/fr.n7.game.examples/src-gen/Jeu.java

122 lines
3.9 KiB
Java
Raw Normal View History

2021-12-09 17:54:08 +00:00
import java.io.InputStreamReader;
import java.io.BufferedReader;
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;
}
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
2022-01-18 18:49:37 +00:00
int selection = 0;
List<Object> choix = new ArrayList<>();
clearScreen();
2022-01-18 18:49:37 +00:00
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) {
2022-01-18 18:49:37 +00:00
System.out.println(p + ":");
2021-12-09 17:54:08 +00:00
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
}
}
}
for (Chemin c : territoire.chemins) {
if (c.lieuIn == lieu) {
2022-01-18 18:49:37 +00:00
if (c.visible.evaluer()) {
if (c.ouvert.evaluer()) {
System.out.println("[" + choix.size() + "] " + c);
choix.add(c);
} else {
System.out.println("[X] " + c);
}
2021-12-09 17:54:08 +00:00
}
}
}
for (Personne p : personnes) {
if (lieu.personnes.contains(p)) {
if (p.visible.evaluer()) {
2022-01-18 18:49:37 +00:00
System.out.println("[" + choix.size() + "] " + p);
choix.add(p);
2021-12-09 17:54:08 +00:00
}
}
}
try {
System.out.print("\nChoix : ");
2022-01-18 18:49:37 +00:00
selection = Integer.parseInt(reader.readLine());
Object choix_selection = choix.get(selection);
2022-01-16 17:14:57 +00:00
2022-01-18 18:49:37 +00:00
if (choix_selection instanceof Chemin) {
lieu = ((Chemin) choix_selection).emprunter();
} else if (choix_selection instanceof Personne) {
personne = (Personne) choix_selection;
2021-12-09 17:54:08 +00:00
} else {
2022-01-18 18:49:37 +00:00
throw new UnsupportedOperationException();
2021-12-09 17:54:08 +00:00
}
2022-01-18 18:49:37 +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);
}
}
2022-01-18 18:49:37 +00:00
// TODO: faire le truc des dépots dans les lieux
// TODO: arreter de créer pleins d'objets et créer des objets anonymes que l'on
// place dans une hashmap avec son nom ?