11package ihm ;
22
33import java .awt .Graphics ;
4-
54import java .awt .Image ;
65import java .io .File ;
76import java .io .IOException ;
87import java .util .EnumMap ;
98import java .util .Map ;
9+ import java .util .logging .Level ;
10+ import java .util .logging .Logger ;
1011
1112import javax .imageio .ImageIO ;
1213import javax .swing .JPanel ;
1718import static ihm .SokobanWindow .IMAGE_SIZE ;
1819
1920
20- @ SuppressWarnings ("serial" )
2121public class SokobanPanel extends JPanel {
22+ private static final Logger LOGGER = Logger .getLogger (SokobanPanel .class .getName ());
2223
2324 private static EnumMap <TileType , Image > images ;
2425
@@ -27,29 +28,28 @@ public class SokobanPanel extends JPanel {
2728 public SokobanPanel (Controller controller ) {
2829 this .controller = controller ;
2930 try {
30- images = new EnumMap <TileType , Image >(
31- Map .of (
32- TileType .FLOOR , ImageIO .read ( new File ( "img/Vide.jpg" )),
33- TileType .WALL , ImageIO .read ( new File ( "img/Mur.jpg" )),
34- TileType .UNSTORED_BOX , ImageIO .read ( new File ( "img/Caisse.jpg" )),
35- TileType .STORED_BOX , ImageIO .read ( new File ( "img/CaisseRangee.jpg" )),
36- TileType .STORAGE_AREA , ImageIO .read ( new File ( "img/Rangement.jpg" )),
37- TileType .WORKER_ON_FLOOR , ImageIO .read ( new File ( "img/Joueur.jpg" )),
38- TileType .OUTSIDE , ImageIO .read ( new File ( "img/Background.jpg" )),
39- TileType .WORKER_IN_STORAGE_AREA , ImageIO .read ( new File ( "img/JoueurRangement.jpg" ))
40- )
41- );
31+ images = new EnumMap <>( Map .of (
32+ TileType .FLOOR , ImageIO .read (new File ( "img/Vide.jpg" )),
33+ TileType .WALL , ImageIO .read (new File ( "img/Mur.jpg" )),
34+ TileType .UNSTORED_BOX , ImageIO .read (new File ( "img/Caisse.jpg" )),
35+ TileType .STORED_BOX , ImageIO .read (new File ( "img/CaisseRangee.jpg" )),
36+ TileType .STORAGE_AREA , ImageIO .read (new File ( "img/Rangement.jpg" )),
37+ TileType .WORKER_ON_FLOOR , ImageIO .read (new File ( "img/Joueur.jpg" )),
38+ TileType .OUTSIDE , ImageIO .read (new File ( "img/Background.jpg" )),
39+ TileType .WORKER_IN_STORAGE_AREA , ImageIO .read (new File ( "img/JoueurRangement.jpg" ))
40+ ));
4241 }
4342 catch ( IOException e ) {
44- e . printStackTrace ( );
43+ LOGGER . log ( Level . SEVERE , "Error loading game images" , e );
4544 }
4645 }
46+
4747 @ Override
4848 public void paint ( Graphics g ) {
4949 super .paint ( g );
50- // Le côté métier raisonne en [ligne, colonne]
51- // Le côté IHM raisonne en [x, y]
52- // Donc x <=> colonne et y <=> ligne
50+ // Business logic uses [row, column] coordinates
51+ // UI uses [x, y] coordinates
52+ // So x <=> column and y <=> row
5353 for (int l = 0 ; l < controller .warehouse .getLines (); l ++ ) {
5454 for (int c = 0 ; c < controller .warehouse .getColumns (); c ++ ) {
5555 g .drawImage ( images .get ( controller .warehouse .getCase ( l , c ).getContent ()), c * IMAGE_SIZE , l * IMAGE_SIZE , IMAGE_SIZE , IMAGE_SIZE , null );
0 commit comments