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

@ -1,9 +1,13 @@
package database;
import java.awt.Point;
import java.io.IOException;
import java.sql.SQLException;
import carte.CarteEquipementStat;
import carte.CarteLieu;
import carte.CarteLieuMultiple;
import carte.CarteLieuType;
import carte.CartePiochable;
import condition.ConditionClassPersonnage;
import condition.ConditionEquipe;
@ -21,9 +25,6 @@ import effet.action.ActionMultiple;
import effet.action.ActionReveal;
import effet.action.ActionVoler;
import main.Joueur;
import main.TypeLumiere;
import main.TypeTenebre;
import main.TypeVision;
import personnage.Allie;
import personnage.Bob;
import personnage.CartePersonnage;
@ -44,6 +45,7 @@ public class CreatingCardsTest {
//Ange gardien
try {
/*
DatabaseManager.queryInsertObject(2,new CartePiochable(CartePiochable.Type.LUMIERE,
new EffetSelf(new ActionAltererStatistiquesJoueur(Joueur.PLAYER_IMMUNITY, 1, true))));
@ -237,10 +239,47 @@ public class CreatingCardsTest {
DatabaseManager.queryInsertObject(55,new LoupGarou());
DatabaseManager.queryInsertObject(56,new Metamorphe());
DatabaseManager.queryInsertObject(57,new Vampire());
*/
//62
//CarteLieu lieu1 = new CarteLieuType(CartePiochable.Type.VISION,new Point(2,3));
DatabaseManager.queryInsertObject(62,new CarteLieuType(CartePiochable.Type.VISION,new Point(2,3)));
//63
CarteLieu lieu2 = new CarteLieuType(CartePiochable.Type.TENEBRE,new Point(-1,8));
DatabaseManager.queryInsertObject(63,lieu2);
// 64
CarteLieu lieu3 = new CarteLieu(new Point(-1,9));
lieu3.setEffet(new EffetChoisirEffet(new EffetChoisirCible(new ActionAltererStatistiquesJoueur(Joueur.PLAYER_HP,-2,true)),
new EffetChoisirCible(new ActionAltererStatistiquesJoueur(Joueur.PLAYER_HP,1,true))));
DatabaseManager.queryInsertObject(64,lieu3);
// 65
CarteLieu lieu4 = new CarteLieuType(CartePiochable.Type.LUMIERE,new Point(-1,6));
DatabaseManager.queryInsertObject(65,lieu4);
CarteLieu lieu5 = new CarteLieuMultiple(new Point(4,5));
DatabaseManager.queryInsertObject(66,lieu5);
// 66
CarteLieu lieu6 = new CarteLieu(new Point(-1,9));
lieu6.setEffet(new EffetChoisirCible(new ActionVoler(ActionVoler.VOLER)));
DatabaseManager.queryInsertObject(67,lieu6);
} catch (IOException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

View File

@ -85,6 +85,8 @@ public class DatabaseManager {
table = QueryGenerator.getTable("CartesPersonnage");
} else if(id <= 61) {
table = QueryGenerator.getTable("CartesDos");
} else if(id <= 67) {
table = QueryGenerator.getTable("CartesLieu");
}
String query = null;

View File

@ -5,12 +5,15 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import carte.Carte;
import carte.CarteLieu;
import carte.CartePiochable;
import personnage.CartePersonnage;
@ -32,16 +35,16 @@ public class RessourceLoader {
private final int ID_DOS_TENEBRE= 59;
private final int ID_DOS_VISION= 61;
private Map<String, Map<Carte, Image>> ressourcesCartes;
private Map<Carte, Image> ressourcesCartes;
private Map<String, Image> ressourcesDosCartes;
public RessourceLoader() {
this.ressourcesCartes = new HashMap<String, Map<Carte,Image>>();
this.ressourcesCartes = new HashMap<Carte,Image>();
this.ressourcesDosCartes = new HashMap<String, Image>();
}
private static Map<Integer, Carte> loadCards() throws ClassNotFoundException, IOException{
private Map<Integer, Carte> loadCards() throws ClassNotFoundException, IOException{
Table t = new Table();
Map<Integer, Carte> cartes = new HashMap<Integer,Carte>();
@ -60,7 +63,7 @@ public class RessourceLoader {
return cartes;
}
private static Map<Integer, Carte> getMapType(CartePiochable.Type t, Map<Integer, Carte> cartes){
private Map<Integer, Carte> getMapType(CartePiochable.Type t, Map<Integer, Carte> cartes){
Map<Integer, Carte> cartesType = new HashMap<Integer, Carte>();
@ -80,7 +83,7 @@ public class RessourceLoader {
return cartesType;
}
private static Map<Integer, Carte> getMapPersonnage(Map<Integer, Carte> cartes){
private Map<Integer, Carte> getMapPersonnage(Map<Integer, Carte> cartes){
Map<Integer, Carte> cartesPersonnage = new HashMap<Integer, Carte>();
@ -102,15 +105,14 @@ public class RessourceLoader {
return is.readObject();
}
private static Image loadImage(int id) throws IOException {
private Image loadImage(int id) throws IOException {
String name = ""+id+".png";
String url = "ressources/cartes/"+name;
System.out.println(url);
Image picture = ImageIO.read(new File(url));
return picture;
}
private static Map<Carte, Image> getMapImageCarte(Map<Integer, Carte> cartes) throws IOException{
private Map<Carte, Image> getMapImageCarte(Map<Integer, Carte> cartes) throws IOException{
Map<Carte, Image> mapCarteImage = new HashMap<Carte, Image>();
@ -123,8 +125,7 @@ public class RessourceLoader {
return mapCarteImage;
}
public void loadRessources() {
try {
@ -134,17 +135,14 @@ public class RessourceLoader {
Map<Integer, Carte> mapL = getMapType(CartePiochable.Type.LUMIERE, cartes);
Map<Integer, Carte> mapV = getMapType(CartePiochable.Type.VISION, cartes);
Map<Integer, Carte> mapP = getMapPersonnage(cartes);
/*
Map<Carte, Image> mapIT = getMapImageCarte(mapT);
Map<Carte, Image> mapIL = getMapImageCarte(mapT);
Map<Carte, Image> mapIV = getMapImageCarte(mapT);
Map<Carte, Image> mapIP = getMapImageCarte(mapT);
Map<Carte, Image> mapIL = getMapImageCarte(mapL);
Map<Carte, Image> mapIV = getMapImageCarte(mapV);
Map<Carte, Image> mapIP = getMapImageCarte(mapP);
*/
this.ressourcesCartes.put(CARTES_TENEBRE, mapIT);
this.ressourcesCartes.put(CARTES_LUMIERE, mapIL);
this.ressourcesCartes.put(CARTES_LUMIERE, mapIV);
this.ressourcesCartes.put(CARTES_LUMIERE, mapIP);
this.ressourcesCartes = (getMapImageCarte(cartes));
this.ressourcesDosCartes.put(DOS_TENEBRE, loadImage(ID_DOS_TENEBRE));
this.ressourcesDosCartes.put(DOS_LUMIERE, loadImage(ID_DOS_LUMIERE));
@ -155,11 +153,59 @@ public class RessourceLoader {
e.printStackTrace();
}
}
public static void main(String[] args) {
RessourceLoader rl = new RessourceLoader();
rl.loadRessources();
public List<Carte> getCartes() {
return new ArrayList<Carte>(this.ressourcesCartes.keySet());
}
public static List<CartePiochable> getCartesType(CartePiochable.Type t, List<Carte> cartes){
List<CartePiochable> cartesType = new ArrayList<CartePiochable>();
for(Carte c : cartes) {
if(c instanceof CartePiochable) {
CartePiochable carte = (CartePiochable) c;
CartePiochable.Type type = carte.getType();
if(t == type) {
cartesType.add(carte);
}
}
}
return cartesType;
}
public static List<CarteLieu> getCartesType(List<Carte> cartes){
List<CarteLieu> cartesLieu = new ArrayList<CarteLieu>();
for(Carte c : cartes) {
if(c instanceof CarteLieu) {
CarteLieu carte = (CarteLieu) c;
cartesLieu.add(carte);
}
}
return cartesLieu;
}
public static List<CartePersonnage> getCartesPersonnages(List<Carte> cartes) {
List<CartePersonnage> cartesLieu = new ArrayList<CartePersonnage>();
for(Carte c : cartes) {
if(c instanceof CartePersonnage) {
CartePersonnage carte = (CartePersonnage) c;
cartesLieu.add(carte);
}
}
return cartesLieu;
}
}