feat: ajout des transformations en java

This commit is contained in:
Laurent Fainsin 2022-01-19 10:44:51 +01:00
parent 97dd01d59f
commit b5a2ce68a1
10 changed files with 1990 additions and 1741 deletions

View file

@ -45,7 +45,7 @@ Personnes:
objets_conso:
descriptions:
- Description1:
texte: "la bonne reponse"
texte: "VSCode est le meilleur IDE de la terre"
condition: true
- Reponse_2:
@ -57,7 +57,7 @@ Personnes:
- tentative
descriptions:
- Description1:
texte: "la mauvaise reponse"
texte: "Eclipse est le meilleur IDE de la terre"
condition: true
Territoire:

View file

@ -85,6 +85,13 @@ public class Jeu {
}
}
for (Transformation t : transformations.values()) {
if (t.possible()) {
System.out.println("[" + choix.size() + "] " + t);
choix.add(t);
}
}
try {
System.out.print("\nChoix : ");
selection = Integer.parseInt(reader.readLine());
@ -96,6 +103,8 @@ public class Jeu {
lieu = ((Chemin) choix_selection).emprunter();
} else if (choix_selection instanceof Personne) {
((Personne) choix_selection).interragir(reader);
} else if (choix_selection instanceof Transformation) {
((Transformation) choix_selection).transformer(reader);
} else {
throw new UnsupportedOperationException();
}

View file

@ -4,10 +4,10 @@ import java.util.Map;
import static java.util.Map.entry;
public class Prototype {
public static void main(String[] args) {
public static void main(String[] args) {
// "Objets"
Map<String, Objet> jeu_objets = Map.ofEntries(
// Objets
Map<String, Objet> jeu_objets = Map.ofEntries(
entry(
"warpToken",
new Objet(
@ -27,7 +27,8 @@ public class Prototype {
new ConditionBoolean(
true
)),
)
),
List.of(
new ConditionBoolean(
true
@ -36,12 +37,16 @@ public class Prototype {
new ConditionBoolean(
false
)),
)
),
List.of(
new ConditionBoolean(
false
)))),
)
)
)
),
List.of(
new Description(
"Description1",
@ -52,7 +57,14 @@ public class Prototype {
new ConditionBoolean(
true
)))))))),
)
)
)
)
)
)
)
),
entry(
"warpTicket",
new Objet(
@ -64,7 +76,10 @@ public class Prototype {
new ConditionBoolean(
true
)))),
)
)
)
),
List.of(
new Description(
"Description1",
@ -75,7 +90,14 @@ public class Prototype {
new ConditionBoolean(
true
)))))))),
)
)
)
)
)
)
)
),
entry(
"warpReceipt",
new Objet(
@ -87,7 +109,10 @@ public class Prototype {
new ConditionBoolean(
true
)))),
)
)
)
),
List.of(
new Description(
"Description1",
@ -98,23 +123,58 @@ public class Prototype {
new ConditionBoolean(
true
)))))))));
)
)
)
)
)
)
)
)
);
// "Connaissances"
Map<String, Connaissance> jeu_connaissances = Map.ofEntries();
// Connaissances
Map<String, Connaissance> jeu_connaissances = Map.ofEntries(
);
// "Transformations"
Map<String, Transformation> jeu_transformations = Map.ofEntries();
// Transformations
Map<String, Transformation> jeu_transformations = Map.ofEntries(
entry(
"TestTransfo",
new Transformation(
"TestTransfo",
new Condition(
List.of(
List.of(
new ConditionBoolean(
true
// "Explorateur"
Jeu.explorateur = new Explorateur(
)
)
)
),
List.of(
jeu_objets.get("warpReceipt")
),
List.of(
jeu_objets.get("warpTicket")
)
)
)
);
// Explorateur
Jeu.explorateur = new Explorateur(
5,
new ArrayList<>(List.of()),
new ArrayList<>(List.of(
jeu_objets.get("warpTicket"))));
)),
new ArrayList<>(List.of(
jeu_objets.get("warpTicket")
))
);
// "Personnes"
Map<String, Personne> jeu_personnes = Map.ofEntries(
// Personnes
Map<String, Personne> jeu_personnes = Map.ofEntries(
entry(
"cashier",
new Personne(
@ -125,14 +185,20 @@ public class Prototype {
new ConditionBoolean(
true
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
false
)))),
)
)
)
),
List.of(
new Interaction(
"Parler",
@ -142,10 +208,16 @@ public class Prototype {
new ConditionBoolean(
true
)))),
List.of(),
List.of(),
List.of(),
)
)
)
),
List.of(
),
List.of(
),
List.of(
),
List.of(
new Action(
"Acheter",
@ -153,23 +225,32 @@ public class Prototype {
List.of(
List.of(
new ConditionObjet(
jeu_objets.get(
"warpTicket"),
jeu_objets.get("warpTicket"),
"==",
1)))),
1
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
true
)))),
List.of(),
)
)
)
),
List.of(
),
List.of(
jeu_objets.get("warpToken"),
jeu_objets.get("warpReceipt")),
jeu_objets.get("warpReceipt")
),
List.of(
jeu_objets.get("warpTicket")),
jeu_objets.get("warpTicket")
),
List.of(
new Description(
"Description1",
@ -180,7 +261,13 @@ public class Prototype {
new ConditionBoolean(
true
))))))),
)
)
)
)
)
)
),
new Action(
"Quitter",
new Condition(
@ -189,17 +276,26 @@ public class Prototype {
new ConditionBoolean(
true
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
true
)))),
List.of(),
List.of(),
List.of(),
)
)
)
),
List.of(
),
List.of(
),
List.of(
),
List.of(
new Description(
"Description1",
@ -210,10 +306,22 @@ public class Prototype {
new ConditionBoolean(
true
)))))))))))));
)
)
)
)
)
)
)
)
)
)
)
)
);
// "Lieux"
Map<String, Lieu> territoire_lieux = Map.ofEntries(
// Lieux
Map<String, Lieu> territoire_lieux = Map.ofEntries(
entry(
"preWarp",
new Lieu(
@ -224,23 +332,33 @@ public class Prototype {
new ConditionBoolean(
false
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
true
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
false
)))),
)
)
)
),
List.of(
jeu_personnes.get("cashier")),
jeu_personnes.get("cashier")
),
List.of(
new Description(
"Description1",
@ -251,9 +369,18 @@ public class Prototype {
new ConditionBoolean(
true
)))))),
new ArrayList<>(List.of()),
List.of())),
)
)
)
)
)
),
new ArrayList<>(List.of(
)),
List.of(
)
)
),
entry(
"postWarp",
new Lieu(
@ -264,22 +391,32 @@ public class Prototype {
new ConditionBoolean(
true
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
false
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
false
)))),
List.of(),
)
)
)
),
List.of(
),
List.of(
new Description(
"Description1",
@ -290,9 +427,18 @@ public class Prototype {
new ConditionBoolean(
true
)))))),
new ArrayList<>(List.of()),
List.of())),
)
)
)
)
)
),
new ArrayList<>(List.of(
)),
List.of(
)
)
),
entry(
"END",
new Lieu(
@ -303,22 +449,32 @@ public class Prototype {
new ConditionBoolean(
false
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
false
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
true
)))),
List.of(),
)
)
)
),
List.of(
),
List.of(
new Description(
"Description1",
@ -329,12 +485,22 @@ public class Prototype {
new ConditionBoolean(
true
)))))),
new ArrayList<>(List.of()),
List.of())));
)
)
)
)
)
),
new ArrayList<>(List.of(
)),
List.of(
)
)
)
);
// "Chemins"
Map<String, Chemin> territoire_chemins = Map.ofEntries(
// Chemins
Map<String, Chemin> territoire_chemins = Map.ofEntries(
entry(
"Warp",
new Chemin(
@ -347,25 +513,38 @@ public class Prototype {
new ConditionObjet(
jeu_objets.get("warpToken"),
">",
0)))),
0
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
true
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
false
)))),
List.of(),
List.of(),
)
)
)
),
List.of(
jeu_objets.get("warpToken")),
),
List.of(
),
List.of(
jeu_objets.get("warpToken")
),
List.of(
new Description(
"DescriptionToken",
@ -376,7 +555,12 @@ public class Prototype {
new ConditionObjet(
jeu_objets.get("warpToken"),
"==",
0))))),
0
)
)
)
)
),
new Description(
"DescriptionNoToken",
"Warp description (token acquired)",
@ -386,7 +570,15 @@ public class Prototype {
new ConditionObjet(
jeu_objets.get("warpToken"),
"==",
1)))))))),
1
)
)
)
)
)
)
)
),
entry(
"EndChemin",
new Chemin(
@ -399,24 +591,36 @@ public class Prototype {
new ConditionBoolean(
true
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
true
)))),
)
)
)
),
new Condition(
List.of(
List.of(
new ConditionBoolean(
false
)))),
List.of(),
List.of(),
List.of(),
)
)
)
),
List.of(
),
List.of(
),
List.of(
),
List.of(
new Description(
"DescriptionToken",
@ -427,20 +631,29 @@ public class Prototype {
new ConditionBoolean(
true
)))))))));
)
)
)
)
)
)
)
)
);
// Territoire
Territoire jeu_territoire = new Territoire(territoire_lieux, territoire_chemins);
// Territoire
Territoire jeu_territoire = new Territoire(territoire_lieux, territoire_chemins);
// Jeu
Jeu ze_GAME = new Jeu(
// Jeu
Jeu ze_GAME = new Jeu(
jeu_territoire,
jeu_objets,
jeu_connaissances,
jeu_personnes,
jeu_transformations);
jeu_transformations
);
ze_GAME.jouer();
ze_GAME.jouer();
}
}
}

View file

@ -1,3 +1,4 @@
import java.io.BufferedReader;
import java.util.List;
public class Transformation {
@ -16,4 +17,24 @@ public class Transformation {
this.objetsSources = objetsSources;
this.objetsResultats = objetsResultats;
}
public void transformer(BufferedReader reader) {
Jeu.clearScreen();
for (Objet objet : objetsResultats) {
Jeu.explorateur.objets.add(objet);
}
for (Objet objet : objetsSources) {
Jeu.explorateur.objets.remove(objet);
}
}
@Override
public String toString() {
return "Transformation " + this.nom;
}
public boolean possible() {
return this.possible.evaluer() && Jeu.explorateur.objets.containsAll(this.objetsSources);
}
}

View file

@ -24,6 +24,12 @@ Objets:
condition: true
Transformations:
- TestTransfo:
condition: true
objets_in:
- warpReceipt
objets_out:
- warpTicket
Connaissances:

View file

@ -34,7 +34,7 @@ Map<String, Connaissance> jeu_connaissances = Map.ofEntries(
[for (c : Connaissance | jeu.connaissances)]
entry(
"[c.name/]",
new Objet(
new Connaissance(
"[c.name/]",
[print_condition(c.visible)/],
[print_descriptions(c.descriptions)/]

View file

@ -34,7 +34,7 @@ Map<String, Connaissance> jeu_connaissances = Map.ofEntries(
[for (c : Connaissance | jeu.connaissances)]
entry(
"[c.name/]",
new Objet(
new Connaissance(
"[c.name/]",
[print_condition(c.visible)/],
[print_descriptions(c.descriptions)/]