projet-genie-logiciel-systeme/runtime-workspace/fr.n7.game.examples/src-gen/Jeu.java
2022-01-16 18:14:57 +01:00

115 lines
3.5 KiB
Java

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;
Lieu lieu = null;
Personne personne = null;
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();
}
void jouer() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// on cherche le (premier) lieu de départ
for (Lieu l : territoire.lieux) {
if (l.depart.evaluer()) {
lieu = l;
break;
}
}
// tant qu'on est pas sur un lieu de fin
mainloop: while (!lieu.fin.evaluer()) {
clearScreen();
System.out.println("Lieu actuel: " + lieu + "\n");
System.out.println("Explorateur:\n" + Jeu.explorateur + "\n");
System.out.println("-".repeat(50));
for (Personne p : lieu.personnes) {
if (p.visible.evaluer() && p.obligatoire.evaluer() || p == personne) {
System.out.println(p + " :");
p.interragir(reader, lieu);
personne = null;
continue mainloop;
}
}
for (Chemin c : territoire.chemins) {
if (c.lieuIn == lieu) {
if (c.visible.evaluer() && c.obligatoire.evaluer() && c.ouvert.evaluer()) {
lieu = c.lieuOut;
continue mainloop;
}
}
}
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());
if (choix < chemins_choix.size()) {
lieu = chemins_choix.get(choix).emprunter();
} else {
personne = personnes_choix.get(choix - chemins_choix.size());
}
} catch (Exception e) {
continue;
}
}
System.out.println("FIN : " + lieu.nom);
}
}