1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
public class CreationGrille extends JPanel {
HashMap<ModelJoueur,Image> images = new HashMap<ModelJoueur,Image>();
JoueurHumain joueurHumain = new JoueurHumain("joueur1");
JoueurHumain joueurHumain2 = new JoueurHumain("joueur2");
TypesTerrains grilleType[][] = new TypesTerrains[4][4];
public CreationGrille(GrilleJeu grille) {
images.put(joueurHumain,lireImage("image.jpg"));
images.put(joueurHumain2,lireImage("image2.jpg"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
grilleGraphique(g);
}
private Image lireImage(String string) {
try {
return ImageIO.read(new File(string));
} catch (IOException e1) {
e1.printStackTrace();
return null;
}
}
public void grilleGraphique(Graphics g) {
CaseTerrain[][] caseTerrains = grilleJeu.getGrille();
int width = getWidth();
int height = getHeight();
int largeur = width / grilleJeu.getAbcisseMax();
int hauteur = height / grilleJeu.getOrdonneeMax();
for (int i = 0; i < grilleJeu.getAbcisseMax(); i++) {
for (int j = 0; j < grilleJeu.getOrdonneeMax(); j++) {
int x = i * largeur;
int y = j * hauteur;
g.drawImage(images.get(grilleType[i][j]), x,
y, largeur, hauteur, this);
g.drawImage(images2.get(grilleType[i][j]),x,y,largeur,hauteur,this);
}
} |
Partager