m1.chocobarlite/src/chocobar/combi/ChocoGraph.java
2009-05-01 08:07:06 +00:00

93 lines
2.1 KiB
Java

package chocobar.combi;
import java.util.*;
import java.lang.reflect.Method;
import java.lang.ClassNotFoundException;
import java.lang.NoSuchMethodException;
import java.lang.IllegalAccessException;
import chocobar.GenericChocoGraph;
import graph.GenericGraph;
import conf.ChocoConfig;
public class ChocoGraph implements GenericChocoGraph
{
static int width;
static int height;
Graph configGraph;
/**
* Constructeur d'un graphe de jeu de Chocobar avec les barres
* de taille (width * height)
**/
public ChocoGraph()
{
this.width=ChocoConfig.size;
this.height=ChocoConfig.height;
this.configGraph=null;
}
/**
* Generation du graphe de jeu.
**/
public GenericGraph genChoco(boolean isList)
{
// Création des Vectors
ChocoBar[] cBars;
try {
// Recherche du bon ChocoBar
Class cCBM = Class.forName("chocobar."+ChocoConfig.chocoBarModel);
Class[] paramsType = {Class.forName("java.lang.Integer"), Class.forName("java.lang.Integer")};
Method genChocoBars = cCBM.getMethod("genChocoBars", paramsType);
Object[] paramsValue = {new Integer(width), new Integer(height)};
cBars = (chocobar.combi.ChocoBar[]) genChocoBars.invoke(null, paramsValue);
ChocoBarSet cbs = new ChocoBarSet(cBars);
// Création de l'objet Graph
configGraph = new Graph();
configGraph.setSize(cbs.size());
// Création des Noeuds
// On sait que les noeud fils sont forcément *après* les noeuds pères.
for (int i=0; (i<cbs.size()); i++) {
for (int j=i+1; (j<cbs.size()); j++) {
if (cbs.item(j).isNextOf(cbs.item(i))) {
// le j-ieme est le fils du i-eme
configGraph.addEdge(i,j);
}
}
}
} catch (Exception e) {
e.printStackTrace();
/*
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalAccessException e) {
*/
}
return configGraph;
}
/**
* Fonction qui renvoie le graph de cet objet
**/
public Graph getGraph()
{
return this.configGraph;
}
/**
* Fonction qui affiche tous les ChocoBar dans ce graphe
**/
public void displayAll(){
System.out.println("ChocoGraph:displayAll()");
}
/** Usine pour la construction du graph.
*/
}