correction de la sauvegarde et de la référence aux portes, ajout de méthode toString
This commit is contained in:
parent
71004f4902
commit
e119bf5920
@ -4,14 +4,17 @@ import labyrinthe.*;
|
||||
import modeles.*;
|
||||
import javafx.util.*;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.GenericArrayType;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
public class Menu {
|
||||
|
||||
public Labyrinthe menuStartGame() {
|
||||
System.out.println("L'Aventure vous appelle ! Le choix s'offre a vous, une histoire peut s'ecrire une autre peut continuer :\n1) Nouvelle Partie\n2) Continuer votre progression");
|
||||
switch(Clavier.entrerClavierInt()) {
|
||||
case 1:
|
||||
return new Labyrinthe(20);
|
||||
return new Labyrinthe(20);//le nombre peut changer
|
||||
case 2:
|
||||
Sauvegarde ge = new Sauvegarde();
|
||||
return ge.labyrinthe();
|
||||
@ -156,7 +159,7 @@ public class Menu {
|
||||
System.out.println("Voulez-vous acheter un objet:(votre bourse :"+perso.getValeurBourse() +")\n1) Oui\n2) Non");
|
||||
switch(Clavier.entrerClavierString()) {
|
||||
case "1":
|
||||
System.out.println(Marche.creerObjetsAVendre(lab)+"\nVoulez-vous acheter une arme ? (oui/non)");
|
||||
System.out.println(perso.getSalle().creerObjetsAVendre(lab)+"\nVoulez-vous acheter une arme ? (oui/non)");
|
||||
String selection=Clavier.entrerClavierString();
|
||||
if(selection.contentEquals("oui")) {
|
||||
System.out.println("Quel numero pour l'arme ?");
|
||||
@ -180,14 +183,12 @@ public class Menu {
|
||||
|
||||
public void menuJeu() {
|
||||
Labyrinthe lab=menuStartGame();
|
||||
Marche marche= (Marche) lab.getListePorte().get(0).getSalle1();
|
||||
Personnage perso = menuSelection(lab);
|
||||
boolean jeu=true;
|
||||
perso.setSalle(lab.getListePorte().get(0).getSalle1());
|
||||
try {
|
||||
do {
|
||||
jeu=Menudeplacement(perso, perso.getSalle(),lab);
|
||||
if (perso.getSalle().getType().contentEquals("Marche") && perso.isVivant()) {
|
||||
if (perso.getSalle().isEstMarche() && perso.isVivant()) {
|
||||
lab.restore();
|
||||
MenuMarche(perso, lab);
|
||||
}
|
||||
@ -195,7 +196,6 @@ public class Menu {
|
||||
}catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
if (perso.isVivant()) System.out.println("Felicitation vous avez vaincu le grand Neltharion ! Vous avez sauver Azeroth");
|
||||
}
|
||||
|
||||
public String menuCombat(Monstre mons, Personnage perso, Labyrinthe lab) throws IOException {
|
||||
|
@ -13,42 +13,84 @@ import java.io.PrintWriter;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import labyrinthe.Labyrinthe;
|
||||
import modeles.Personnage;
|
||||
|
||||
public class Sauvegarde {
|
||||
|
||||
public Labyrinthe labyrinthe() {
|
||||
BufferedReader bfr= null;
|
||||
try {
|
||||
bfr = new BufferedReader(new FileReader("C:\\Users\\Nicolas\\eclipse-workspace\\Projet_Java\\JAVA\\PROJET-PMT_STRI1A\\src\\json\\lab.json"));
|
||||
BufferedReader bfrP=null;
|
||||
BufferedReader bfrPe=null;
|
||||
|
||||
try {
|
||||
bfr = new BufferedReader(new FileReader("C:\\Users\\theo\\Documents\\lab.json"));
|
||||
bfrP= new BufferedReader(new FileReader("C:\\Users\\theo\\Documents\\perBor.json"));
|
||||
bfrPe=new BufferedReader(new FileReader("C:\\Users\\theo\\Documents\\perAra.json"));
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
Labyrinthe labyrithe = gson.fromJson(bfr, Labyrinthe.class);
|
||||
Personnage per1=gson.fromJson(bfrP, Personnage.class);
|
||||
Personnage per=gson.fromJson(bfrPe, Personnage.class);
|
||||
labyrithe.getListePersonnage().add(per);
|
||||
labyrithe.getListePersonnage().add(per1);
|
||||
try {
|
||||
labyrithe.adaptSalle();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return labyrithe;
|
||||
}
|
||||
|
||||
|
||||
public void save(Labyrinthe lab) throws IOException{
|
||||
saveAra(lab.getListePersonnage().remove(0));
|
||||
saveBor(lab.getListePersonnage().remove(0));
|
||||
Gson gson =new Gson();
|
||||
|
||||
String str = gson.toJson(lab);
|
||||
System.out.println(str);
|
||||
System.out.println(lab.getListePorte().toString());
|
||||
try {
|
||||
File file = new File("C:\\Users\\Nicolas\\eclipse-workspace\\Projet_Java\\JAVA\\PROJET-PMT_STRI1A\\src\\json\\lab.json");
|
||||
|
||||
File file = new File("C:\\Users\\theo\\Documents\\lab.json");
|
||||
file.createNewFile();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write(str);
|
||||
writer.close();
|
||||
|
||||
//file.print(s);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void saveBor(Personnage pers) throws IOException{
|
||||
Gson gson=new Gson();
|
||||
String str=gson.toJson(pers);
|
||||
System.out.println(str);
|
||||
try {
|
||||
File file = new File("C:\\Users\\theo\\Documents\\perBor.json");
|
||||
file.createNewFile();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write(str);
|
||||
writer.close();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public void saveAra(Personnage pers) throws IOException{
|
||||
Gson gson=new Gson();
|
||||
String str=gson.toJson(pers);
|
||||
System.out.println(str);
|
||||
try {
|
||||
File file = new File("C:\\Users\\theo\\Documents\\perAra.json");
|
||||
file.createNewFile();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write(str);
|
||||
writer.close();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
{"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}]}
|
@ -31,7 +31,7 @@ public class Labyrinthe {
|
||||
listeArmure.add(armure);
|
||||
Armure armure2=new Armure("armure de fer",70,15,7);
|
||||
listeArmure.add(armure2);
|
||||
Armure armure3=new Armure("Le kevlar",230,15,8);
|
||||
Armure armure3=new Armure("Le kevlar",230,20,10);
|
||||
listeArmure.add(armure3);
|
||||
|
||||
Personnage perso=new Personnage("Aramis",10,1);
|
||||
@ -62,8 +62,10 @@ public class Labyrinthe {
|
||||
mons = new Monstre("Neltharion, le Destructeur", 80,20);
|
||||
this.listeMonstre.add(mons);
|
||||
|
||||
Marche marche = new Marche();
|
||||
|
||||
List<Salle> ListSalle=new ArrayList<Salle>();
|
||||
Salle marche= new Salle(0,0, false,true);
|
||||
for (Personnage p : this.listePersonnage)p.setSalle(marche);
|
||||
ListSalle.add(marche);
|
||||
List<Integer>table;
|
||||
Salle salle;
|
||||
@ -166,14 +168,14 @@ public class Labyrinthe {
|
||||
result = result * a;
|
||||
}
|
||||
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void restore() {
|
||||
Random rd =new Random();
|
||||
for (Porte p : listePorte) {
|
||||
|
||||
if (p.getSalle1().estVide() && !p.getSalle1().getType().contentEquals("Marche")) {
|
||||
if (p.getSalle1().estVide() && !p.getSalle1().isEstMarche()) {
|
||||
|
||||
for (int i =0; i<rd.nextInt(4);i++) {
|
||||
p.getSalle1().getListeEnnemie().add(rd.nextInt(listeMonstre.size()-3));
|
||||
@ -181,7 +183,7 @@ public class Labyrinthe {
|
||||
|
||||
}
|
||||
|
||||
if (p.getSalle1().estVide() && !p.getSalle1().getType().contentEquals("Marche")) {
|
||||
if (p.getSalle1().estVide() && !p.getSalle1().isEstMarche()) {
|
||||
|
||||
for (int i =0; i<rd.nextInt(4);i++) {
|
||||
|
||||
@ -191,6 +193,24 @@ public class Labyrinthe {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void adaptSalle() throws Exception {
|
||||
List<Salle> listeSalle =new ArrayList<Salle>();
|
||||
for (Porte po : listePorte) {
|
||||
if (!contents(po.getSalle1(),listeSalle)) listeSalle.add(po.getSalle1());
|
||||
if (!contents(po.getSalle2(),listeSalle)) listeSalle.add(po.getSalle2());
|
||||
}
|
||||
for (Personnage p : listePersonnage) {
|
||||
int i =0;
|
||||
while (!p.getSalle().equals(listeSalle.get(i++)) && i<listeSalle.size());
|
||||
if (i-1>=listeSalle.size())throw new Exception("La salle du personnage n'existe pas ");
|
||||
else {
|
||||
System.out.println(this.getListePorte().toString());
|
||||
p.seDeplacer(listeSalle.get(i-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contents(Salle s, List<Salle> ls) {
|
||||
for (Salle p : ls) {
|
||||
if(s.equals(p)) return true;
|
||||
|
@ -1,40 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package labyrinthe;
|
||||
import modeles.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author flavien
|
||||
*
|
||||
*/
|
||||
public class Marche extends Salle {
|
||||
|
||||
public Marche() {
|
||||
super(0,0, false);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return "Marche";
|
||||
}
|
||||
|
||||
public static String creerObjetsAVendre(Labyrinthe lab) {
|
||||
String listeSarme="";
|
||||
String listeSarmure="";
|
||||
String listeobjet="";
|
||||
int i = 0;
|
||||
int j =0;
|
||||
|
||||
for (Arme arme : lab.listeArme) listeSarme +=i++ +") "+ arme.getNom() + " au prix de : " + arme.getPrix()+"\n";
|
||||
|
||||
for (Armure armure : lab.listeArmure) listeSarmure +=j++ +") "+ armure.getNom()+ " au prix de : " + armure.getPrix()+"\n";
|
||||
|
||||
listeobjet = "Armes :\n" + listeSarme + "\nArmures :\n" + listeSarmure;
|
||||
|
||||
return listeobjet;
|
||||
}
|
||||
|
||||
}
|
@ -44,11 +44,17 @@ public class Porte {
|
||||
}
|
||||
|
||||
public Salle prochainSaut(Salle s) {
|
||||
if (s==this.salle1) {
|
||||
if (s.equals(this.salle1)) {
|
||||
return salle2;
|
||||
} else return salle1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Porte [ouvert=" + ouvert + ", salle1=" + salle1 + ", salle2=" + salle2 + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javafx.util.Pair;
|
||||
import modeles.Arme;
|
||||
import modeles.Armure;
|
||||
|
||||
|
||||
public class Salle {
|
||||
@ -11,21 +13,24 @@ public class Salle {
|
||||
private boolean sortie;
|
||||
private List<Integer> listePorte= new ArrayList<Integer>();
|
||||
private List<Integer> listeEnnemie= new ArrayList<Integer>(); //indice de monstre
|
||||
private boolean estMarche;
|
||||
|
||||
public Salle(int x, int y, boolean out) {
|
||||
public Salle(int x, int y, boolean out,boolean marche) {
|
||||
this.listeEnnemie=new ArrayList<Integer>();
|
||||
this.coordonnees=new Pair<Integer,Integer>(x,y);
|
||||
this.sortie=out;
|
||||
this.estMarche=marche;
|
||||
}
|
||||
|
||||
public Salle(int positionX, int positionY, boolean sortie, List<Integer> listeEnnemie) {
|
||||
this.coordonnees=new Pair<Integer,Integer>(positionX,positionY);
|
||||
this.sortie = sortie;
|
||||
this.listeEnnemie = listeEnnemie;
|
||||
this.estMarche=false;
|
||||
}
|
||||
|
||||
public String getType(){
|
||||
return "salle";
|
||||
public boolean isEstMarche() {
|
||||
return estMarche;
|
||||
}
|
||||
|
||||
public Pair<Integer,Integer> getCoordonnes() {
|
||||
@ -64,4 +69,27 @@ public class Salle {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String creerObjetsAVendre(Labyrinthe lab) {
|
||||
if (!estMarche)return "";
|
||||
String listeSarme="";
|
||||
String listeSarmure="";
|
||||
String listeobjet="";
|
||||
int i = 0;
|
||||
int j =0;
|
||||
|
||||
for (Arme arme : lab.listeArme) listeSarme +=i++ +") "+ arme.getNom() + " au prix de : " + arme.getPrix()+" (dégat bonus : "+arme.getpArme()+" /durabilité : "+arme.getUsure()+" )\n";
|
||||
|
||||
for (Armure armure : lab.listeArmure) listeSarmure +=j++ +") "+ armure.getNom()+ " au prix de : " + armure.getPrix()+" (protection : "+armure.getpArmure()+" /durabilité : "+armure.getUsure()+") \n";
|
||||
|
||||
listeobjet = "Armes :\n" + listeSarme + "\nArmures :\n" + listeSarmure;
|
||||
|
||||
return listeobjet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Salle [coordonnees=" + coordonnees + ", sortie=" + sortie + ", listePorte=" + listePorte
|
||||
+ ", listeEnnemie=" + listeEnnemie + ", estMarche=" + estMarche + "]";
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,11 @@ public class Monstre extends EtreVivant {
|
||||
|
||||
public int attaquer(Personnage def,Labyrinthe lab) {
|
||||
int pAttaqueLoc;
|
||||
if (def.getArmure()>=0) pAttaqueLoc=this.getpAttaque()-(lab.getListeArmure().get(def.getArmure()).getpArmure());
|
||||
|
||||
if (def.getArmure()>=0) {
|
||||
lab.getListeArmure().get(def.getArmure()).utilisation();
|
||||
pAttaqueLoc=this.getpAttaque()-(lab.getListeArmure().get(def.getArmure()).getpArmure());
|
||||
}
|
||||
else pAttaqueLoc=this.getpAttaque();
|
||||
def.pVie-=pAttaqueLoc;
|
||||
if (def.pVie<=0)def.setVivant(false);
|
||||
|
@ -28,7 +28,7 @@ public abstract class Objet {
|
||||
|
||||
public void utilisation() { // diminue la résistance de l'objet
|
||||
this.usure--;
|
||||
if (this.usure == 0) System.out.println(this.nom+"s'est cassée !");
|
||||
if (this.usure == 0) System.out.println("\n\noh non ! "+this.nom+" s'est cassée !\n\n");
|
||||
}
|
||||
|
||||
public abstract String getType();
|
||||
|
@ -66,6 +66,7 @@ public class Personnage extends EtreVivant {
|
||||
|
||||
public int attaquer(Monstre monstre,Labyrinthe lab) {
|
||||
if(arme>=0) {
|
||||
lab.getListeArme().get(arme).utilisation();
|
||||
monstre.pVie=monstre.pVie-(lab.getListeArme().get(arme).getpArme()+getpAttaque());
|
||||
if (monstre.pVie<=0)monstre.setVivant(false);
|
||||
return lab.getListeArme().get(arme).getpArme()+getpAttaque();
|
||||
|
Loading…
Reference in New Issue
Block a user