diff --git a/OOP_2B6_PROJECT/src/windowInterface/JPanelChessBoard.java b/OOP_2B6_PROJECT/src/windowInterface/JPanelChessBoard.java index 78a68de..56d4be3 100644 --- a/OOP_2B6_PROJECT/src/windowInterface/JPanelChessBoard.java +++ b/OOP_2B6_PROJECT/src/windowInterface/JPanelChessBoard.java @@ -22,10 +22,10 @@ public class JPanelChessBoard extends JPanel { private Game myGame; private MyInterface interfaceGlobal; private BufferedImage spriteSheet; - private int PIECE_WIDTH = 16; //in spritesheet - private int PIECE_HEIGHT = 16; //in spritesheet + private int PIECE_WIDTH = 16; + private int PIECE_HEIGHT = 16; private int MARGIN = 6; - + private boolean pieceSelectorMode; private boolean selectedPieceIsWhite; private PieceType selectedPieceType; @@ -45,33 +45,30 @@ public class JPanelChessBoard extends JPanel { } pieceSelectorMode = false; pieceAdderMode = false; - addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent me) { - // System.out.println(me); - if(pieceSelectorMode) { - int x = Math.round(me.getX()/cellWidth()); - selectedPieceType = PieceType.values()[5-x]; + addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent me) { + if (pieceSelectorMode) { + int x = Math.round(me.getX() / cellWidth()); + selectedPieceType = PieceType.values()[5 - x]; selectedPieceIsWhite = (me.getY() > cellHeight()); pieceSelectorMode = false; } else { - if(myGame == null) { + if (myGame == null) { interfaceGlobal.instantiateSimu(); } - int x = (me.getX()*myGame.getWidth())/getWidth(); - int y = (me.getY()*myGame.getHeight())/getHeight(); - if(pieceAdderMode) { - //TODO - myGame.setPiece(selectedPieceIsWhite,selectedPieceType, x, y); + int x = (me.getX() * myGame.getWidth()) / getWidth(); + int y = (me.getY() * myGame.getHeight()) / getHeight(); + if (pieceAdderMode) { + myGame.setPiece(selectedPieceIsWhite, selectedPieceType, x, y); pieceAdderMode = false; } else { - myGame.clickCoords(x,y); + myGame.clickCoords(x, y); } } repaint(); - } - }); + } + }); } - public void setGame(Game simu) { myGame = simu; @@ -81,116 +78,117 @@ public class JPanelChessBoard extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); this.setBackground(Color.black); - if(pieceSelectorMode) { + if (pieceSelectorMode) { g.drawImage( - spriteSheet, - 0, - 0, - Math.round(5*cellWidth()), - Math.round(2*cellHeight()), - null - ); + spriteSheet, + 0, + 0, + Math.round(5 * cellWidth()), + Math.round(2 * cellHeight()), + null + ); return; } if (myGame != null) { - // Draw Interface from state of simulator float cellWidth = cellWidth(); float cellHeight = cellHeight(); - g.setColor(Color.white); - for(int x=0; x