forked from menault/TD3_DEV51_Qualite_Algo
front + assets
This commit is contained in:
62
Jeu_pendu/Front/Gallows.java
Normal file
62
Jeu_pendu/Front/Gallows.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package front;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Gère les images du pendu (une par étape).
|
||||
* - Charge les images depuis assets
|
||||
*/
|
||||
public class Gallows {
|
||||
/** Dossier d'assets relatif à la racine du projet */
|
||||
private static final String ASSETS_DIR = "assets" + File.separator + "images";
|
||||
/** Nombre d'étapes (0 = aucun membre, 7 = étape finale) */
|
||||
private static final int MAX_STAGE = 6;
|
||||
|
||||
private static final ImageIcon[] ICONS = new ImageIcon[MAX_STAGE + 1];
|
||||
|
||||
static {
|
||||
for (int i = 0; i <= MAX_STAGE; i++) {
|
||||
String path = ASSETS_DIR + File.separator + i + ".png";
|
||||
File f = new File(path);
|
||||
if (f.exists()) {
|
||||
ICONS[i] = new ImageIcon(path);
|
||||
} else {
|
||||
// Placeholder si fichier manquant
|
||||
ICONS[i] = placeholder("Missing: " + i + ".png");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne l'icône correspondant au nombre d'erreurs.
|
||||
*/
|
||||
public static ImageIcon icon(int errors) {
|
||||
int idx = Math.max(0, Math.min(errors, MAX_STAGE));
|
||||
return ICONS[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée une petite image placeholder (si un asset est manquant).
|
||||
*/
|
||||
private static ImageIcon placeholder(String text) {
|
||||
int w = 320, h = 240;
|
||||
Image img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g = (Graphics2D) img.getGraphics();
|
||||
g.setColor(Color.LIGHT_GRAY);
|
||||
g.fillRect(0, 0, w, h);
|
||||
g.setColor(Color.DARK_GRAY);
|
||||
g.drawRect(0, 0, w - 1, h - 1);
|
||||
g.drawString(text, 10, h / 2);
|
||||
g.dispose();
|
||||
return new ImageIcon(img);
|
||||
}
|
||||
|
||||
// Import manquant pour BufferedImage
|
||||
private static class BufferedImage extends java.awt.image.BufferedImage {
|
||||
public BufferedImage(int width, int height, int imageType) {
|
||||
super(width, height, imageType);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user