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;

public class Generateur {

	public Labyrinthe labyrithe() {
		BufferedReader bfr= null;
		 try {
			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();
		}
		//FileReader file = new FileReader(json);
		Gson gson = new Gson();
		//String str="{\"positionX\":0,\"positionY\":0,\"sortie\":false,\"monstre\":[{\"nom\":\"premier monstre\",\"pAttaque\":5}],\"porte\":[{\"ouvert\":true, \"position\":\"H\"}]}";
		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();
		}
	}
	
	
}
