From 59c1aaf71ae17a53711aa7aacd9df8b419b9628c Mon Sep 17 00:00:00 2001
From: Laurent Fainsin
Date: Sun, 16 Jan 2022 18:14:57 +0100
Subject: [PATCH] =?UTF-8?q?am=C3=A9lioration=20du=20proto=20java?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../fr.n7.game.examples/enigmeLibre.game | 158 +
.../fr.n7.game.examples/src-gen/Chemin.java | 15 +
.../src-gen/Explorateur.java | 11 +-
.../src-gen/Interaction.java | 26 +-
.../fr.n7.game.examples/src-gen/Jeu.java | 47 +-
.../fr.n7.game.examples/src-gen/Objet.java | 6 +-
.../src-gen/Prototype.java | 9 +-
.../fr.n7.game.examples/test1.game | 53 +
.../fr.n7.game.examples/test2.game | 91 +
.../n7/game/toPrototype/main/toPrototype.emtl | 4758 ++++++++---------
.../n7/game/toPrototype/main/toPrototype.mtl | 2 +-
.../n7/game/toPrototype/main/toPrototype.mtl | 2 +-
.../xtext/tests/.GameParsingTest.xtendbin | Bin 3389 -> 3389 bytes
workspace/fr.n7.game.xtext/model/Game.ocl | 4 +
.../xtext/generator/.GameGenerator.xtendbin | Bin 2284 -> 2284 bytes
15 files changed, 2748 insertions(+), 2434 deletions(-)
create mode 100644 runtime-workspace/fr.n7.game.examples/enigmeLibre.game
create mode 100644 runtime-workspace/fr.n7.game.examples/test1.game
create mode 100644 runtime-workspace/fr.n7.game.examples/test2.game
diff --git a/runtime-workspace/fr.n7.game.examples/enigmeLibre.game b/runtime-workspace/fr.n7.game.examples/enigmeLibre.game
new file mode 100644
index 0000000..15fb4f3
--- /dev/null
+++ b/runtime-workspace/fr.n7.game.examples/enigmeLibre.game
@@ -0,0 +1,158 @@
+Objets:
+ - tentative:
+ taille: 1
+ visible: true
+ descriptions:
+ - Description1:
+ texte: "permet repondre une question du sphinx"
+ condition: true
+
+Transformations:
+
+Connaissances:
+ - Reussite:
+ visible: true
+ descriptions:
+ - Description1:
+ texte: "Permet de se casser de la"
+ condition: true
+
+Explorateur:
+ taille: 3
+ connaissances:
+ objets:
+ - tentative
+ - tentative
+ - tentative
+
+Personnes:
+ - Sphinx:
+ visible: ! Reussite && tentative > 0
+ obligatoire: false
+ interactions:
+ - Parler:
+ visible: true
+ connaissances:
+ objets_recus:
+ objets_conso:
+ actions:
+ - Reponse_1:
+ visible: true
+ fin_interaction: true
+ connaissances:
+ - Reussite
+ objets_recus:
+ objets_conso:
+ descriptions:
+ - Description1:
+ texte: "la bonne reponse"
+ condition: true
+
+ - Reponse_2:
+ visible: true
+ fin_interaction: true
+ connaissances:
+ objets_recus:
+ objets_conso:
+ - tentative
+ descriptions:
+ - Description1:
+ texte: "la mauvaise reponse"
+ condition: true
+ - Combattre:
+ visible: true
+ connaissances:
+ objets_recus:
+ objets_conso:
+ actions:
+ - Action_1:
+ visible: true
+ fin_interaction: true
+ connaissances:
+ - Reussite
+ objets_recus:
+ objets_conso:
+ descriptions:
+ - Description1:
+ texte: "la bonne reponse"
+ condition: true
+
+ - Action_2:
+ visible: true
+ fin_interaction: true
+ connaissances:
+ objets_recus:
+ objets_conso:
+ - tentative
+ descriptions:
+ - Description1:
+ texte: "la mauvaise reponse"
+ condition: true
+
+Territoire:
+ Lieux:
+ - Enigme:
+ deposable: true
+ depart: true
+ fin: false
+ personnes:
+ - Sphinx
+ descriptions:
+ - Description1:
+ texte: "lieu de depart"
+ condition: true
+ objets:
+ connaissances:
+
+ - Succes:
+ deposable: false
+ depart: false
+ fin: true
+ personnes:
+ descriptions:
+ - Description1:
+ texte: "lieu succes"
+ condition: true
+ objets:
+ connaissances:
+
+ - Echec:
+ deposable: false
+ depart: false
+ fin: true
+ personnes:
+ descriptions:
+ - Description1:
+ texte: "lieu echec"
+ condition: true
+ objets:
+ connaissances:
+
+ Chemins:
+ - Win:
+ lieu_in: Enigme
+ lieu_out: Succes
+ ouvert: true
+ visible: Reussite
+ obligatoire: false
+ connaissances:
+ objets_recus:
+ objets_conso:
+ descriptions:
+ - Description1:
+ texte: "Le chemin de la victoire !"
+ condition: true
+
+ - Loose:
+ lieu_in: Enigme
+ lieu_out: Echec
+ ouvert: true
+ visible: tentative == 0
+ obligatoire: false
+ connaissances:
+ objets_recus:
+ objets_conso:
+ descriptions:
+ - Description1:
+ texte: "Le chemin de la loose !"
+ condition: true
diff --git a/runtime-workspace/fr.n7.game.examples/src-gen/Chemin.java b/runtime-workspace/fr.n7.game.examples/src-gen/Chemin.java
index 9702699..1b960dc 100644
--- a/runtime-workspace/fr.n7.game.examples/src-gen/Chemin.java
+++ b/runtime-workspace/fr.n7.game.examples/src-gen/Chemin.java
@@ -45,4 +45,19 @@ public class Chemin {
}
return "No desc";
}
+
+ public Lieu emprunter() {
+ for (Objet o : this.objetsRecus) {
+ Jeu.explorateur.objets.add(o);
+ }
+ for (Objet o : this.objetsConso) {
+ Jeu.explorateur.objets.remove(o);
+ }
+ for (Connaissance c : this.connaissancesRecus) {
+ if (!Jeu.explorateur.connaissances.contains(c)) {
+ Jeu.explorateur.connaissances.add(c);
+ }
+ }
+ return this.lieuOut;
+ }
}
diff --git a/runtime-workspace/fr.n7.game.examples/src-gen/Explorateur.java b/runtime-workspace/fr.n7.game.examples/src-gen/Explorateur.java
index 7a58a88..b4679a8 100644
--- a/runtime-workspace/fr.n7.game.examples/src-gen/Explorateur.java
+++ b/runtime-workspace/fr.n7.game.examples/src-gen/Explorateur.java
@@ -16,16 +16,7 @@ public class Explorateur {
@Override
public String toString() {
- String txt = "Objets :\n";
- for (Objet c : this.objets) {
- txt += c + " ";
- }
- txt += "\n\nConnaissances :\n";
- for (Connaissance c : this.connaissances) {
- txt += c + " ";
- }
- txt += "\n===================================================";
- return txt;
+ return "\tObjets : " + this.objets + "\n\tConnaissances : " + this.connaissances;
}
}
diff --git a/runtime-workspace/fr.n7.game.examples/src-gen/Interaction.java b/runtime-workspace/fr.n7.game.examples/src-gen/Interaction.java
index 4e059f9..af17beb 100644
--- a/runtime-workspace/fr.n7.game.examples/src-gen/Interaction.java
+++ b/runtime-workspace/fr.n7.game.examples/src-gen/Interaction.java
@@ -25,9 +25,20 @@ public class Interaction {
}
void interragir(BufferedReader reader, Lieu lieu) {
- boolean arreter_interraction = false;
- while (!arreter_interraction) {
+ for (Objet o : this.objetsRecus) {
+ Jeu.explorateur.objets.add(o);
+ }
+ for (Objet o : this.objetsConso) {
+ Jeu.explorateur.objets.remove(o);
+ }
+ for (Connaissance c : this.connaissances) {
+ if (!Jeu.explorateur.connaissances.contains(c)) {
+ Jeu.explorateur.connaissances.add(c);
+ }
+ }
+
+ while (true) {
System.out.println(this);
System.out.print("\nChoix : ");
@@ -37,21 +48,20 @@ public class Interaction {
actions_choix.add(a);
}
}
+
int choix = 0;
Action a = null;
try {
choix = Integer.parseInt(reader.readLine());
a = actions_choix.get(choix);
- } catch (NumberFormatException e) {
+ } catch (Exception e) {
continue;
- } catch (IndexOutOfBoundsException e) {
- continue;
- } catch (IOException e) {
- e.printStackTrace();
}
+
a.actionner();
- arreter_interraction = a.finInterraction.evaluer();
+ if (a.finInterraction.evaluer())
+ break;
}
}
diff --git a/runtime-workspace/fr.n7.game.examples/src-gen/Jeu.java b/runtime-workspace/fr.n7.game.examples/src-gen/Jeu.java
index c2a5fe3..70d5170 100644
--- a/runtime-workspace/fr.n7.game.examples/src-gen/Jeu.java
+++ b/runtime-workspace/fr.n7.game.examples/src-gen/Jeu.java
@@ -12,6 +12,9 @@ public class Jeu {
List personnes;
List transformations;
+ Lieu lieu = null;
+ Personne personne = null;
+
public Jeu(
Territoire territoire,
List objets,
@@ -33,7 +36,7 @@ public class Jeu {
void jouer() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- Lieu lieu = null;
+ // on cherche le (premier) lieu de départ
for (Lieu l : territoire.lieux) {
if (l.depart.evaluer()) {
lieu = l;
@@ -41,38 +44,32 @@ public class Jeu {
}
}
- while (!lieu.fin.evaluer()) {
- boolean recommencer = false;
+ // tant qu'on est pas sur un lieu de fin
+ mainloop: while (!lieu.fin.evaluer()) {
clearScreen();
- System.out.println("Lieu : " + lieu + "\n");
- System.out.println(Jeu.explorateur);
+ 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()) {
+ if (p.visible.evaluer() && p.obligatoire.evaluer() || p == personne) {
System.out.println(p + " :");
p.interragir(reader, lieu);
- recommencer = true;
- break;
+ personne = null;
+ continue mainloop;
}
}
- if (recommencer) {
- continue;
- }
for (Chemin c : territoire.chemins) {
if (c.lieuIn == lieu) {
if (c.visible.evaluer() && c.obligatoire.evaluer() && c.ouvert.evaluer()) {
lieu = c.lieuOut;
- recommencer = true;
- break;
+ continue mainloop;
}
}
}
- if (recommencer) {
- continue;
- }
int k = 0;
List chemins_choix = new ArrayList<>();
@@ -101,24 +98,14 @@ public class Jeu {
try {
System.out.print("\nChoix : ");
choix = Integer.parseInt(reader.readLine());
+
if (choix < chemins_choix.size()) {
- lieu = chemins_choix.get(choix).lieuOut;
+ lieu = chemins_choix.get(choix).emprunter();
} else {
- Personne p = personnes_choix.get(choix - chemins_choix.size());
-
- clearScreen();
- System.out.println("Lieu : " + lieu + "\n");
- System.out.println(Jeu.explorateur);
- System.out.println(p + " :");
-
- p.interragir(reader, lieu);
+ personne = personnes_choix.get(choix - chemins_choix.size());
}
- } catch (NumberFormatException e) {
+ } catch (Exception e) {
continue;
- } catch (IndexOutOfBoundsException e) {
- continue;
- } catch (IOException e) {
- e.printStackTrace();
}
}
diff --git a/runtime-workspace/fr.n7.game.examples/src-gen/Objet.java b/runtime-workspace/fr.n7.game.examples/src-gen/Objet.java
index 79c35fa..df7b075 100644
--- a/runtime-workspace/fr.n7.game.examples/src-gen/Objet.java
+++ b/runtime-workspace/fr.n7.game.examples/src-gen/Objet.java
@@ -19,11 +19,13 @@ public class Objet {
@Override
public String toString() {
+ String str = null;
for (Description d : this.descriptions) {
if (d.condition.evaluer()) {
- return "(" + this.nom + ": " + d + ")";
+ str = this.nom + "(" + d + ")";
+ break;
}
}
- return "(" + this.nom + ")";
+ return str;
}
}
diff --git a/runtime-workspace/fr.n7.game.examples/src-gen/Prototype.java b/runtime-workspace/fr.n7.game.examples/src-gen/Prototype.java
index 1953051..cdb107e 100644
--- a/runtime-workspace/fr.n7.game.examples/src-gen/Prototype.java
+++ b/runtime-workspace/fr.n7.game.examples/src-gen/Prototype.java
@@ -8,6 +8,7 @@ public class Prototype {
public static void main(String[] args) {
// "Objets"
+
List jeu_objets = new ArrayList<>();
List objet_tentative_descriptions = new ArrayList<>();
@@ -52,6 +53,7 @@ List jeu_objets = new ArrayList<>();
jeu_objets.add(objet_tentative);
// "Connaissances"
+
List jeu_connaissances = new ArrayList<>();
List connaissance_Reussite_descriptions = new ArrayList<>();
@@ -95,6 +97,7 @@ List jeu_connaissances = new ArrayList<>();
jeu_connaissances.add(connaissance_Reussite);
// "Transformations"
+
List jeu_transformations = new ArrayList<>();
@@ -144,7 +147,7 @@ List jeu_personnes = new ArrayList<>();
List personne_obligatoire_Sphinx_1_conditions_TEST_list = new ArrayList<>();
personne_obligatoire_Sphinx_1_conditions_TEST_list.add(
- new ConditionBoolean(true)
+ new ConditionBoolean(false)
);
personne_obligatoire_Sphinx_1_conditions_ET_list.add(
new ConditionEt(personne_obligatoire_Sphinx_1_conditions_TEST_list)
@@ -582,7 +585,7 @@ List territoire_chemins = new ArrayList<>();
List chemin_obligatoire_Win_1_conditions_TEST_list = new ArrayList<>();
chemin_obligatoire_Win_1_conditions_TEST_list.add(
- new ConditionBoolean(true)
+ new ConditionBoolean(false)
);
chemin_obligatoire_Win_1_conditions_ET_list.add(
new ConditionEt(chemin_obligatoire_Win_1_conditions_TEST_list)
@@ -662,7 +665,7 @@ List territoire_chemins = new ArrayList<>();
List chemin_obligatoire_Loose_2_conditions_TEST_list = new ArrayList<>();
chemin_obligatoire_Loose_2_conditions_TEST_list.add(
- new ConditionBoolean(true)
+ new ConditionBoolean(false)
);
chemin_obligatoire_Loose_2_conditions_ET_list.add(
new ConditionEt(chemin_obligatoire_Loose_2_conditions_TEST_list)
diff --git a/runtime-workspace/fr.n7.game.examples/test1.game b/runtime-workspace/fr.n7.game.examples/test1.game
new file mode 100644
index 0000000..0357f66
--- /dev/null
+++ b/runtime-workspace/fr.n7.game.examples/test1.game
@@ -0,0 +1,53 @@
+Objets:
+
+Transformations:
+
+Connaissances:
+
+Explorateur:
+ taille: 0
+ connaissances:
+ objets:
+
+Personnes:
+
+Territoire:
+ Lieux:
+ - preWarp:
+ deposable: true
+ depart: true
+ fin: false
+ personnes:
+ descriptions:
+ - Description1:
+ texte: "preWarp description"
+ condition: true
+ objets:
+ connaissances:
+
+ - postWarp:
+ deposable: false
+ depart: false
+ fin: true
+ personnes:
+ descriptions:
+ - Description1:
+ texte: "postWarp description"
+ condition: true
+ objets:
+ connaissances:
+
+ Chemins:
+ - Warp:
+ lieu_in: preWarp
+ lieu_out: postWarp
+ ouvert: true
+ visible: true
+ obligatoire: false
+ connaissances:
+ objets_recus:
+ objets_conso:
+ descriptions:
+ - Description1:
+ texte: "warp description"
+ condition: true
diff --git a/runtime-workspace/fr.n7.game.examples/test2.game b/runtime-workspace/fr.n7.game.examples/test2.game
new file mode 100644
index 0000000..177d774
--- /dev/null
+++ b/runtime-workspace/fr.n7.game.examples/test2.game
@@ -0,0 +1,91 @@
+Objets:
+ - warpToken:
+ taille: 1
+ visible: true
+ descriptions:
+ - Description1:
+ texte: "warpToken description"
+ condition: true
+
+Transformations:
+
+Connaissances:
+
+Explorateur:
+ taille: 1
+ connaissances:
+ objets:
+ - warpToken
+
+Personnes:
+
+Territoire:
+ Lieux:
+ - preWarp:
+ deposable: false
+ depart: true
+ fin: false
+ personnes:
+ descriptions:
+ - Description1:
+ texte: "preWarp description"
+ condition: true
+ objets:
+ connaissances:
+
+ - postWarp:
+ deposable: false
+ depart: false
+ fin: false
+ personnes:
+ descriptions:
+ - Description1:
+ texte: "postWarp description"
+ condition: true
+ objets:
+ connaissances:
+
+ - END:
+ deposable: false
+ depart: false
+ fin: true
+ personnes:
+ descriptions:
+ - Description1:
+ texte: "END description"
+ condition: true
+ objets:
+ connaissances:
+
+ Chemins:
+ - Warp:
+ lieu_in: preWarp
+ lieu_out: postWarp
+ ouvert: true
+ visible: true
+ obligatoire: false
+ connaissances:
+ objets_recus:
+ objets_conso:
+ - warpToken
+ descriptions:
+ - DescriptionToken:
+ texte: "preWarp description (need token)"
+ condition: warpToken == 0
+ - DescriptionNoToken:
+ texte: "preWarp description (token acquired)"
+ condition: warpToken == 1
+
+ - EndChemin:
+ lieu_in: postWarp
+ lieu_out: END
+ ouvert: true
+ visible: true
+ obligatoire: false
+ connaissances:
+ objets_recus:
+ objets_conso:
+ descriptions:
+ - DescriptionToken:
+ texte: "END description"
+ condition: true
diff --git a/workspace/fr.n7.game.toPrototype/bin/fr/n7/game/toPrototype/main/toPrototype.emtl b/workspace/fr.n7.game.toPrototype/bin/fr/n7/game/toPrototype/main/toPrototype.emtl
index 99a5201..af4b58a 100644
--- a/workspace/fr.n7.game.toPrototype/bin/fr/n7/game/toPrototype/main/toPrototype.emtl
+++ b/workspace/fr.n7.game.toPrototype/bin/fr/n7/game/toPrototype/main/toPrototype.emtl
@@ -14,7 +14,7 @@
@@ -123,7 +123,7 @@
@@ -224,7 +224,7 @@
@@ -363,13 +363,13 @@
-
+