2021-12-01 19:55:46 +00:00
|
|
|
import java.util.List;
|
2021-12-02 13:23:06 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.IOException;
|
2021-12-01 19:55:46 +00:00
|
|
|
|
2021-12-01 07:58:07 +00:00
|
|
|
public class Interaction {
|
|
|
|
Condition visible;
|
|
|
|
List<Connaissance> connaissances;
|
|
|
|
List<Objet> objetsRecus;
|
|
|
|
List<Objet> objetsConso;
|
|
|
|
List<Action> actions;
|
|
|
|
|
|
|
|
public Interaction(
|
|
|
|
Condition visible,
|
|
|
|
List<Connaissance> connaissances,
|
|
|
|
List<Objet> objetsRecus,
|
|
|
|
List<Objet> objetsConso,
|
|
|
|
List<Action> actions) {
|
|
|
|
this.visible = visible;
|
|
|
|
this.connaissances = connaissances;
|
|
|
|
this.objetsRecus = objetsRecus;
|
|
|
|
this.objetsConso = objetsConso;
|
|
|
|
this.actions = actions;
|
|
|
|
}
|
2021-12-01 19:55:46 +00:00
|
|
|
|
2021-12-02 13:23:06 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-01 19:55:46 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2021-12-02 13:23:06 +00:00
|
|
|
String res = "";
|
2021-12-01 19:55:46 +00:00
|
|
|
int k = 0;
|
2021-12-01 20:19:08 +00:00
|
|
|
for (Action a : this.actions) {
|
2021-12-01 19:55:46 +00:00
|
|
|
if (a.visible.evaluer()) {
|
2021-12-02 13:23:06 +00:00
|
|
|
res += "[" + k + "] " + a + "\n";
|
2021-12-01 19:55:46 +00:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
2021-12-01 20:19:08 +00:00
|
|
|
return res;
|
2021-12-01 19:55:46 +00:00
|
|
|
}
|
2021-12-01 07:58:07 +00:00
|
|
|
}
|