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: objets_conso:
descriptions: descriptions:
- Description1: - Description1:
texte: "la bonne reponse" texte: "VSCode est le meilleur IDE de la terre"
condition: true condition: true
- Reponse_2: - Reponse_2:
@ -57,7 +57,7 @@ Personnes:
- tentative - tentative
descriptions: descriptions:
- Description1: - Description1:
texte: "la mauvaise reponse" texte: "Eclipse est le meilleur IDE de la terre"
condition: true condition: true
Territoire: 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 { try {
System.out.print("\nChoix : "); System.out.print("\nChoix : ");
selection = Integer.parseInt(reader.readLine()); selection = Integer.parseInt(reader.readLine());
@ -96,6 +103,8 @@ public class Jeu {
lieu = ((Chemin) choix_selection).emprunter(); lieu = ((Chemin) choix_selection).emprunter();
} else if (choix_selection instanceof Personne) { } else if (choix_selection instanceof Personne) {
((Personne) choix_selection).interragir(reader); ((Personne) choix_selection).interragir(reader);
} else if (choix_selection instanceof Transformation) {
((Transformation) choix_selection).transformer(reader);
} else { } else {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View file

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

View file

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

View file

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