Ajout constructeur de Plateau en s'appuyant de RessourceLoader

This commit is contained in:
Paul Gross
2020-05-07 16:58:31 +02:00
parent 9fca28f7bb
commit 144ffd5434
17 changed files with 309 additions and 118 deletions

View File

@@ -8,6 +8,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import database.RessourceLoader;
import effet.Effet;
import ihm.controller.PlateauController;
import javafx.application.Platform;
@@ -17,6 +18,8 @@ public class GestionnaireJeu {
private static GestionnaireJeu gj;
private Map<Integer, Joueur> mapJoueurs;
private RessourceLoader ressourceLoader;
private static Plateau plateau;
private static PlateauController pc;
@@ -38,15 +41,6 @@ public class GestionnaireJeu {
public void lancerPartie() {
plateau.start();
}
public void jouer(Configuration c) {
}
public static Configuration lancerConfiguration() {
//TODO
return null;
}
public Joueur choisirParmisTous(Joueur joueur, List<Joueur> joueurs) {
return joueurs.get(0);
@@ -68,6 +62,13 @@ public class GestionnaireJeu {
});
}
public void updateVieJoueur(Joueur joueur, int damage) {
Platform.runLater(() -> {
pc.updateVieJoueur(joueur, damage);
});
}
public boolean choisir(Joueur joueur) {
Platform.runLater(() -> {
@@ -132,8 +133,8 @@ public class GestionnaireJeu {
for(Joueur j : mapJoueurs.values()) {
joueurs.add(j);
}
plateau = new Plateau(joueurs);
//plateau = new Plateau(joueurs,ressourceLoader.getCartes());
}
@@ -151,15 +152,14 @@ public class GestionnaireJeu {
}
public void updateVieJoueur(Joueur joueur, int damage) {
pc.updateVieJoueur(joueur, damage);
}
public static void endGame() {
plateau.stop();
}
public void setRessourceLoader(RessourceLoader rl) {
this.ressourceLoader = rl;
}

View File

@@ -4,8 +4,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import carte.CarteLieu;
import carte.Carte;
import carte.CarteEquipement;
import carte.CarteLieu;
import effet.Effet;
import personnage.CartePersonnage;
import personnage.CartePersonnage.Equipe;
@@ -64,6 +65,9 @@ public class Joueur {
return this.cartePersonnage.getEquipe();
}
private void changeStat(String key, int valeur) {
this.stats.put(key, valeur);
}
public void setStat(String key, int valeur) {
this.stats.put(key, valeur);
updateVictoirePlateau();
@@ -87,10 +91,10 @@ public class Joueur {
private void updateVie() {
int damage = damageTaken();
this.plateau.updateVieJoueur(this, damage);
}
public int damageTaken() {
System.out.println(this.cartePersonnage.getPv()+ " "+this.getStat(PLAYER_HP));
return this.cartePersonnage.getPv() - this.getStat(PLAYER_HP);
}
@@ -130,7 +134,7 @@ public class Joueur {
j2.gestionnaireEquipements.retirer(equipement);
this.gestionnaireEquipements.ajouter(equipement); }
public CarteEquipement choisir(List<CarteEquipement> equipements) {
public Object choisir(List<?> equipements) {
return null;
}
@@ -193,6 +197,7 @@ public class Joueur {
public void setCartePersonnage(CartePersonnage cp) {
this.cartePersonnage = cp;
this.changeStat(PLAYER_HP, cp.getPv());
}
public void setPlateau(Plateau plateau2) {

View File

@@ -9,26 +9,22 @@ import carte.CartePiochable;
public class Pioche {
private Stack<CartePiochable> cartesPiochables;
private CartePiochable.Type type;
public Pioche(List<CartePiochable> cartesPiochables) {
}
public Pioche(CartePiochable.Type type, List<CartePiochable> list1) {
public Pioche(List<CartePiochable> list1) {
super();
this.type = type;
this.cartesPiochables = new Stack<CartePiochable>();
this.cartesPiochables.addAll(cartesPiochables);
this.cartesPiochables.addAll(list1);
melanger();
}
public void melanger()
{
Collections.shuffle(cartesPiochables);
}
public CartePiochable piocher() {
public CartePiochable piocher() {
return cartesPiochables.pop();
}
}

View File

@@ -7,9 +7,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import carte.Carte;
import carte.CarteLieu;
import carte.CarteLieuMultiple;
import carte.CarteLieuType;
import carte.CartePiochable;
import database.RessourceLoader;
import effet.Effet;
import effet.EffetChoisirCible;
import effet.EffetChoisirEffet;
@@ -121,6 +124,66 @@ public class Plateau extends Thread{
}
public Plateau(List<Joueur> joueurs, List<Carte> cartes) {
this.gj = GestionnaireJeu.getGestionnaireJeu();
this.lieux = new ArrayList<>();
this.stats = new HashMap<>();
this.joueurs = joueurs;
this.stats.put(NB_MORTS, 0);
this.stats.put(NB_MORTS_NEUTRAL, 0);
this.stats.put(NB_MORTS_HUNTER, 0);
this.stats.put(NB_MORTS_SHADOW, 0);
this.stats.put(PARTIE_FINIE, 0);
this.stats.put(NB_HUNTERS, 0);
this.stats.put(NB_SHADOWS, 0);
this.stats.put(NB_NEUTRES, 0);
joueurs.forEach(x -> x.setPlateau(this));
List<CartePiochable> lumiere = RessourceLoader.getCartesType(CartePiochable.Type.LUMIERE, cartes);
List<CartePiochable> tenebre = RessourceLoader.getCartesType(CartePiochable.Type.TENEBRE, cartes);
List<CartePiochable> vision = RessourceLoader.getCartesType(CartePiochable.Type.VISION, cartes);
Map<CartePiochable.Type, List<CartePiochable>> map = new HashMap<CartePiochable.Type, List<CartePiochable>>();
map.put(CartePiochable.Type.LUMIERE,lumiere);
map.put(CartePiochable.Type.TENEBRE,tenebre);
map.put(CartePiochable.Type.VISION,vision);
List<CarteLieu> lieux = RessourceLoader.getCartesType(cartes);
lieux.forEach(x -> {
if(x instanceof CarteLieuType) {
CarteLieuType clt = (CarteLieuType)x;
clt.setPioche(new Pioche(map.get(clt.getType())));
}
if(x instanceof CarteLieuMultiple) {
CarteLieuMultiple clm = (CarteLieuMultiple)x;
List<Pioche> lp = new ArrayList<Pioche>();
lp.add(new Pioche(map.get(CartePiochable.Type.LUMIERE)));
lp.add(new Pioche(map.get(CartePiochable.Type.TENEBRE)));
lp.add(new Pioche(map.get(CartePiochable.Type.VISION)));
clm.setPioches(lp);
}
});
List<CartePersonnage> personnages = RessourceLoader.getCartesPersonnages(cartes);
try {
initCartePersonnage(personnages);
} catch (Exception e) {
}
setLieux(lieux);
}
public void initCartePersonnage(List<CartePersonnage> cps) throws Exception {
@@ -211,12 +274,7 @@ public class Plateau extends Thread{
System.out.println("Vous passez a "+currentJoueur.getStat(Joueur.PLAYER_HP)+" pv");
if(isPartieTerminee()) break;
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("\n");
System.out.println("Souhaitez vous attaquer quelqu'un ?");
@@ -229,12 +287,6 @@ public class Plateau extends Thread{
System.out.println("Il n'y a personne a attaquer.");
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
i++;