Persistance fonctionnelle

This commit is contained in:
Nicolas 2019-05-14 21:43:12 +02:00
parent d0708fb2f0
commit 7b3f48f0fa
9 changed files with 82 additions and 59 deletions

View File

@ -0,0 +1,3 @@
/Generateur.class
/gsonGenerator.class
/main.class

View File

@ -1,49 +1 @@
{
"listePersonnage":[
{
"nom":"test",
"pVieMax":10,
"pVie":10,
"pAttaque":20,
"arme":null,
"armure":null,
"bourse":null
}
],
"listeSalle":[
{
"positionX":0,
"positionY":0,
"sortie":false,
"listeEnnemie":[{"nom":"premiermonstre",
"pAttaque":5}
],
"listePorte":[{"ouvert":true,
"orientation":"H"}]
}
],
"listeArme":[
{"nom":"arme1",
"prix":10,
"resistance":10,
"pArme":10}],
"listeArmure":[ {"nom":"armure1",
"prix":10,
"resistance":10,
"pArmure":10}],
"listePorte":[
{
"id":1,
"ouvert":false,
"orientation":"Z",
}
],
"listeMonstre":[{"nom":"premiermonstre",
"pAttaque":5}]
}
{"listePersonnage":[{"listepotion":[],"nom":"Aramis","pVieMax":10,"pVie":10,"pAttaque":1,"vivant":true},{"listepotion":[],"nom":"Boromis","pVieMax":8,"pVie":8,"pAttaque":2,"vivant":true}],"listeArme":[{"pArme":2,"nom":"Epee en bois","prix":5,"usure":10},{"pArme":4,"nom":"Epee en acier","prix":15,"usure":10},{"pArme":4,"nom":"Epee en acier solide","prix":25,"usure":20},{"pArme":7,"nom":"Epee de cristal","prix":30,"usure":5},{"pArme":10,"nom":"Lame Blanche","prix":200,"usure":30}],"listeArmure":[{"pArmure":5,"nom":"armure de cuir","prix":10,"usure":10},{"pArmure":2,"nom":"armure en papier","prix":5,"usure":5},{"pArmure":5,"nom":"armure de fer","prix":30,"usure":10},{"pArmure":8,"nom":"Le kevlar","prix":150,"usure":15}],"listePorte":[{"id":1,"ouvert":true,"salle1":{"coordonnees":{"key":0,"value":0},"sortie":false,"listePorte":[]},"salle2":{"coordonnees":{"key":1,"value":0},"sortie":false,"listePorte":[],"listeEnnemie":[5]}},{"id":1,"ouvert":true,"salle1":{"coordonnees":{"key":0,"value":0},"sortie":false,"listePorte":[]},"salle2":{"coordonnees":{"key":0,"value":1},"sortie":false,"listePorte":[],"listeEnnemie":[3,1]}},{"id":1,"ouvert":true,"salle1":{"coordonnees":{"key":1,"value":1},"sortie":false,"listePorte":[],"listeEnnemie":[]},"salle2":{"coordonnees":{"key":0,"value":1},"sortie":false,"listePorte":[],"listeEnnemie":[3,1]}},{"id":1,"ouvert":true,"salle1":{"coordonnees":{"key":2,"value":0},"sortie":false,"listePorte":[],"listeEnnemie":[4,0]},"salle2":{"coordonnees":{"key":1,"value":0},"sortie":false,"listePorte":[],"listeEnnemie":[5]}},{"id":1,"ouvert":true,"salle1":{"coordonnees":{"key":2,"value":0},"sortie":false,"listePorte":[],"listeEnnemie":[4,0]},"salle2":{"coordonnees":{"key":2,"value":1},"sortie":true,"listePorte":[],"listeEnnemie":[3,3]}},{"id":1,"ouvert":true,"salle1":{"coordonnees":{"key":2,"value":1},"sortie":true,"listePorte":[],"listeEnnemie":[3,3]},"salle2":{"coordonnees":{"key":1,"value":1},"sortie":false,"listePorte":[],"listeEnnemie":[]}}],"listeMonstre":[{"nom":"pantin en bois","pVieMax":5,"pVie":5,"pAttaque":1,"vivant":true},{"nom":"araignee geante agressive","pVieMax":7,"pVie":7,"pAttaque":5,"vivant":true},{"nom":"pantin de fer","pVieMax":40,"pVie":40,"pAttaque":1,"vivant":true},{"nom":"Golem de Jade","pVieMax":40,"pVie":40,"pAttaque":3,"vivant":true},{"nom":"Neltharion le Gardeterre","pVieMax":100,"pVie":100,"pAttaque":10,"vivant":true},{"nom":"Neltharion, le Destructeur","pVieMax":80,"pVie":80,"pAttaque":20,"vivant":true}]}

View File

@ -10,10 +10,10 @@ public class main {
public static void main(String[] args) {
gsonGenerator generateur = new gsonGenerator();
Generateur gene = new Generateur();
Labyrinthe lab = gene.labyrithe();
//Generateur gene = new Generateur();
//Labyrinthe lab = gene.labyrithe();
//lab.getListeSalle();
Monstre monstre =new Monstre("test",5);
//Monstre monstre =new Monstre("test",5);
Arme arme = new Arme("arme1", 10, 10, 10);
System.out.println("");

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,17 @@
/Arme.class
/Armure.class
/Bourse.class
/Clavier.class
/EtreVivant.class
/Generateur.class
/Labyrinthe.class
/Marche.class
/Menu.class
/Monstre.class
/Objet.class
/Personnage.class
/Porte.class
/Potion.class
/Salle.class
/main.class
/sauvegarde.class

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>modeles</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -2,8 +2,13 @@ package modeles;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import com.google.gson.Gson;
@ -12,7 +17,7 @@ public class Generateur {
public Labyrinthe labyrithe() {
BufferedReader bfr= null;
try {
bfr = new BufferedReader(new FileReader("C:\\Users\\theo\\Documents\\Java\\Projet\\javaProject\\src\\modeles\\lab.json"));
bfr = new BufferedReader(new FileReader("C:\\Users\\Nicolas\\eclipse-workspace\\Projet_Java\\JAVA\\PROJET-PMT_STRI1A\\src\\json\\lab.json"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -23,6 +28,24 @@ public class Generateur {
Labyrinthe labyrithe = gson.fromJson(bfr, Labyrinthe.class);
return labyrithe;
}
public void save(Labyrinthe lab) throws IOException{
Gson gson =new Gson();
String str = gson.toJson(lab);
System.out.println(str);
try {
File file = new File("C:\\Users\\Nicolas\\eclipse-workspace\\Projet_Java\\JAVA\\PROJET-PMT_STRI1A\\src\\json\\lab.json");
file.createNewFile();
FileWriter writer = new FileWriter(file);
writer.write(str);
writer.close();
//file.print(s);
}catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,17 +1,22 @@
package modeles;
import java.io.IOException;
public class main {
/*public static void main(String[] args) {
public static void main(String[] args) throws IOException {
Generateur gene = new Generateur();
Labyrinthe lab = gene.labyrithe();
//lab.getListeSalle();
//lab.getListeSalle();
Labyrinthe lab2 =new Labyrinthe();
Arme arme = new Arme("arme1", 10, 10, 10);
System.out.println("");
}*/
Labyrinthe lab = new Labyrinthe();
lab.labyrinthe1();
gene.save(lab);
lab2=gene.labyrithe();
System.out.println("");
}
}

View File

@ -0,0 +1 @@
/Test.class