Loading jeuAssemblage/src/main/Controller.java +3 −0 Changes for jeuAssemblage/src/main/Controller.java: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -36,6 +36,9 @@ public class Controller { } public void finishGame() { this.eventManager = new EventManager(); this.model.destroy(); this.model = new PlayBoard(); } // difficulty methods Loading jeuAssemblage/src/model/PlayBoard.java +24 −16 Changes for jeuAssemblage/src/model/PlayBoard.java: 24 added lines, 16 removed lines. Original line number Diff line number Diff line Loading @@ -92,6 +92,18 @@ public class PlayBoard { return ret; } /** * bla bla * are representation of an rectangle, contains respectively x, y, width, height */ public void destroy() { while (!this.alPieceOnBoard.isEmpty()) { Piece p = this.alPieceOnBoard.get(0); p.destroy(); this.alPieceOnBoard.remove(p); } } // Privates private ArrayList<Piece> createPieces(int numberPiece) { ArrayList<Piece> tempAl = new ArrayList<Piece>(); Loading Loading @@ -184,26 +196,22 @@ public class PlayBoard { } private int[] getArea() { int x = -1; int y = -1; int width = -1; int height = -1; for ( int i = 0; i < this.playBoard[0].length; i++) { for ( int j = 0; j < this.playBoard.length; j++) { if (this.playBoard[j][i] != 0) { if ( x == -1 && y == -1) { x = i; y = j; } else { if ( (i - x) > width ) width = (i - x); if ( (j - y) > height ) height = (j - y); } int x = this.playBoard[0].length; int y = this.playBoard.length; int xEnd = 0; int yEnd = 0; for (int i = 0; i < this.playBoard.length; i++) { for (int j = 0; j < this.playBoard[i].length; j++) { if ( this.playBoard[i][j] != 0 ) { if ( j < x ) x = j; if ( i < y ) y = i; if ( j > xEnd ) xEnd = j; if ( i > yEnd ) yEnd = i; } } } return new int[]{ x, y, width, height}; return new int[]{ x, y, xEnd + 1, yEnd + 1}; } // Static methods Loading jeuAssemblage/src/view/component/GameSummary.java 0 → 100644 +89 −0 Changes for jeuAssemblage/src/view/component/GameSummary.java: 89 added lines, 0 removed lines. Original line number Diff line number Diff line package view.component; import static view.utils.SwingUtils.*; import javax.swing.JPanel; import pieces.Piece; import view.utils.SwingUtils; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.geom.Rectangle2D; import main.Controller; import java.util.ArrayList; import java.awt.Color; public class GameSummary extends JPanel { private final Controller controller = Controller.getInstance(); public GameSummary() { super(); this.setLayout(null); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); SwingUtils.drawDebugBounds(this, g); int[] areaInformation = this.controller.areaInfomartion(); int xBegin = areaInformation[0]; int yBegin = areaInformation[1]; int xEnd = areaInformation[2]; int yEnd = areaInformation[3]; double componentSize = Math.min( getHeightTimesPourcent(this, 0.95f) / ((yEnd - yBegin) * 1d), getWidthTimesPourcent(this, 0.95f) / ((xEnd - xBegin) * 1d) ); double paddingWidth = this.getWidth () - (componentSize * ((xEnd - xBegin) * 1d)); double paddingHeight = this.getHeight() - (componentSize * ((yEnd - yBegin) * 1d)); //TODO METTRE A JOUR LA METHODE Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.WHITE); int[][] matrices = this.controller.getPlayBoard(); ArrayList<Piece> alreadyDraw = new ArrayList<Piece>(); for (int i = yBegin; i < yEnd ; i++) { double y = (i - yBegin) * componentSize + paddingHeight/2; for (int j = xBegin; j < xEnd; j++) { double x = (j - xBegin) * componentSize + paddingWidth/2; Rectangle2D shape = new Rectangle2D.Double(x, y, componentSize, componentSize); if (matrices[i][j] != 0) { Piece p = this.controller.getPieceById(matrices[i][j]); if (!alreadyDraw.contains(p)) { // TODO rotate the image if needed Image img = this.controller.getImageById(p.getInstanceId()); g2d.drawImage(img, (int) Math.ceil(x), (int) Math.ceil(y), (int) Math.floor(componentSize * 3), (int) Math.floor(componentSize * 3), null); alreadyDraw.add(p); } } else { g2d.draw(shape); } } } } } jeuAssemblage/src/view/component/board/Finish.java +4 −2 Changes for jeuAssemblage/src/view/component/board/Finish.java: 4 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ import javax.swing.JPanel; import main.Controller; import main.listener.EventListener; import view.MainFrame; import view.screen.SoloGameFinishScreen; import view.utils.SwingUtils; public class Finish extends JPanel implements EventListener{ Loading @@ -31,7 +33,7 @@ public class Finish extends JPanel implements EventListener{ this.update(); this.btnFinish.addActionListener(e -> { Finish.this.controller.finishGame(); MainFrame.getInstance().setContentPane(new SoloGameFinishScreen()); }); this.add(this.lblPreciseArea); Loading @@ -45,7 +47,7 @@ public class Finish extends JPanel implements EventListener{ public void update() { int[] areaInfo = this.controller.areaInfomartion(); lblPreciseArea.setText("Nombre de carrés : " + areaInfo[4]); lblArea.setText("Aire : " + (areaInfo[2] * areaInfo[3])); lblArea.setText("Aire : " + ((areaInfo[2] - areaInfo[0]) * (areaInfo[3] - areaInfo[1]))); } @Override Loading jeuAssemblage/src/view/screen/SoloGameFinishScreen.java +83 −0 Changes for jeuAssemblage/src/view/screen/SoloGameFinishScreen.java: 83 added lines, 0 removed lines. Original line number Diff line number Diff line package view.screen; import static view.utils.SwingUtils.*; import java.awt.Graphics; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import main.Controller; import view.MainFrame; import view.component.GameSummary; import view.utils.SwingUtils; public class SoloGameFinishScreen extends JPanel { private GameSummary gameSummary; private final JLabel lblArea = new JLabel(); private final JButton btnSolo = new JButton("Solo"); private final JButton btnMenu = new JButton("Menu"); public SoloGameFinishScreen() { setLayout(null); this.gameSummary = new GameSummary(); int[] areaInfo = Controller.getInstance().areaInfomartion(); this.lblArea.setText("Aire : " + ((areaInfo[2] - areaInfo[0]) * (areaInfo[3] - areaInfo[1]))); this.btnSolo.addActionListener(e -> { Controller.getInstance().finishGame(); MainFrame.getInstance().setContentPane(new SoloGameCreation()); }); this.btnMenu.addActionListener(e -> { Controller.getInstance().finishGame(); MainFrame.getInstance().setContentPane(new MainScreen()); }); this.add(this.gameSummary); this.add(this.lblArea); this.add(this.btnMenu); this.add(this.btnSolo); super.doLayout(); } @Override public void doLayout() { super.doLayout(); final int PADDING_LEFT = getWidthTimesPourcent (this, .05f); final int PADDING_TOP = getHeightTimesPourcent(this, .05f); this.gameSummary.setBounds( PADDING_LEFT, PADDING_TOP, getWidthTimesPourcent (this, .4f), getHeightTimesPourcent(this, .9f) ); final int PADDING_LEFT_GRID = PADDING_LEFT * 2 + this.gameSummary.getWidth(); this.lblArea.setBounds( PADDING_LEFT_GRID, PADDING_TOP, getWidthTimesPourcent (this, .1f), getHeightTimesPourcent(this, .2f) ); this.btnMenu.setBounds( PADDING_LEFT_GRID, this.getHeight() - getHeightTimesPourcent(this, .11f), getWidthTimesPourcent (this, .07f), getHeightTimesPourcent(this, .06f) ); this.btnSolo.setBounds( PADDING_LEFT_GRID + this.btnMenu.getWidth() + PADDING_LEFT, this.getHeight() - getHeightTimesPourcent(this, .11f), getWidthTimesPourcent (this, .07f), getHeightTimesPourcent(this, .06f) ); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); SwingUtils.drawDebugBounds(this, g); } } Loading
jeuAssemblage/src/main/Controller.java +3 −0 Changes for jeuAssemblage/src/main/Controller.java: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -36,6 +36,9 @@ public class Controller { } public void finishGame() { this.eventManager = new EventManager(); this.model.destroy(); this.model = new PlayBoard(); } // difficulty methods Loading
jeuAssemblage/src/model/PlayBoard.java +24 −16 Changes for jeuAssemblage/src/model/PlayBoard.java: 24 added lines, 16 removed lines. Original line number Diff line number Diff line Loading @@ -92,6 +92,18 @@ public class PlayBoard { return ret; } /** * bla bla * are representation of an rectangle, contains respectively x, y, width, height */ public void destroy() { while (!this.alPieceOnBoard.isEmpty()) { Piece p = this.alPieceOnBoard.get(0); p.destroy(); this.alPieceOnBoard.remove(p); } } // Privates private ArrayList<Piece> createPieces(int numberPiece) { ArrayList<Piece> tempAl = new ArrayList<Piece>(); Loading Loading @@ -184,26 +196,22 @@ public class PlayBoard { } private int[] getArea() { int x = -1; int y = -1; int width = -1; int height = -1; for ( int i = 0; i < this.playBoard[0].length; i++) { for ( int j = 0; j < this.playBoard.length; j++) { if (this.playBoard[j][i] != 0) { if ( x == -1 && y == -1) { x = i; y = j; } else { if ( (i - x) > width ) width = (i - x); if ( (j - y) > height ) height = (j - y); } int x = this.playBoard[0].length; int y = this.playBoard.length; int xEnd = 0; int yEnd = 0; for (int i = 0; i < this.playBoard.length; i++) { for (int j = 0; j < this.playBoard[i].length; j++) { if ( this.playBoard[i][j] != 0 ) { if ( j < x ) x = j; if ( i < y ) y = i; if ( j > xEnd ) xEnd = j; if ( i > yEnd ) yEnd = i; } } } return new int[]{ x, y, width, height}; return new int[]{ x, y, xEnd + 1, yEnd + 1}; } // Static methods Loading
jeuAssemblage/src/view/component/GameSummary.java 0 → 100644 +89 −0 Changes for jeuAssemblage/src/view/component/GameSummary.java: 89 added lines, 0 removed lines. Original line number Diff line number Diff line package view.component; import static view.utils.SwingUtils.*; import javax.swing.JPanel; import pieces.Piece; import view.utils.SwingUtils; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.geom.Rectangle2D; import main.Controller; import java.util.ArrayList; import java.awt.Color; public class GameSummary extends JPanel { private final Controller controller = Controller.getInstance(); public GameSummary() { super(); this.setLayout(null); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); SwingUtils.drawDebugBounds(this, g); int[] areaInformation = this.controller.areaInfomartion(); int xBegin = areaInformation[0]; int yBegin = areaInformation[1]; int xEnd = areaInformation[2]; int yEnd = areaInformation[3]; double componentSize = Math.min( getHeightTimesPourcent(this, 0.95f) / ((yEnd - yBegin) * 1d), getWidthTimesPourcent(this, 0.95f) / ((xEnd - xBegin) * 1d) ); double paddingWidth = this.getWidth () - (componentSize * ((xEnd - xBegin) * 1d)); double paddingHeight = this.getHeight() - (componentSize * ((yEnd - yBegin) * 1d)); //TODO METTRE A JOUR LA METHODE Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.WHITE); int[][] matrices = this.controller.getPlayBoard(); ArrayList<Piece> alreadyDraw = new ArrayList<Piece>(); for (int i = yBegin; i < yEnd ; i++) { double y = (i - yBegin) * componentSize + paddingHeight/2; for (int j = xBegin; j < xEnd; j++) { double x = (j - xBegin) * componentSize + paddingWidth/2; Rectangle2D shape = new Rectangle2D.Double(x, y, componentSize, componentSize); if (matrices[i][j] != 0) { Piece p = this.controller.getPieceById(matrices[i][j]); if (!alreadyDraw.contains(p)) { // TODO rotate the image if needed Image img = this.controller.getImageById(p.getInstanceId()); g2d.drawImage(img, (int) Math.ceil(x), (int) Math.ceil(y), (int) Math.floor(componentSize * 3), (int) Math.floor(componentSize * 3), null); alreadyDraw.add(p); } } else { g2d.draw(shape); } } } } }
jeuAssemblage/src/view/component/board/Finish.java +4 −2 Changes for jeuAssemblage/src/view/component/board/Finish.java: 4 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ import javax.swing.JPanel; import main.Controller; import main.listener.EventListener; import view.MainFrame; import view.screen.SoloGameFinishScreen; import view.utils.SwingUtils; public class Finish extends JPanel implements EventListener{ Loading @@ -31,7 +33,7 @@ public class Finish extends JPanel implements EventListener{ this.update(); this.btnFinish.addActionListener(e -> { Finish.this.controller.finishGame(); MainFrame.getInstance().setContentPane(new SoloGameFinishScreen()); }); this.add(this.lblPreciseArea); Loading @@ -45,7 +47,7 @@ public class Finish extends JPanel implements EventListener{ public void update() { int[] areaInfo = this.controller.areaInfomartion(); lblPreciseArea.setText("Nombre de carrés : " + areaInfo[4]); lblArea.setText("Aire : " + (areaInfo[2] * areaInfo[3])); lblArea.setText("Aire : " + ((areaInfo[2] - areaInfo[0]) * (areaInfo[3] - areaInfo[1]))); } @Override Loading
jeuAssemblage/src/view/screen/SoloGameFinishScreen.java +83 −0 Changes for jeuAssemblage/src/view/screen/SoloGameFinishScreen.java: 83 added lines, 0 removed lines. Original line number Diff line number Diff line package view.screen; import static view.utils.SwingUtils.*; import java.awt.Graphics; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import main.Controller; import view.MainFrame; import view.component.GameSummary; import view.utils.SwingUtils; public class SoloGameFinishScreen extends JPanel { private GameSummary gameSummary; private final JLabel lblArea = new JLabel(); private final JButton btnSolo = new JButton("Solo"); private final JButton btnMenu = new JButton("Menu"); public SoloGameFinishScreen() { setLayout(null); this.gameSummary = new GameSummary(); int[] areaInfo = Controller.getInstance().areaInfomartion(); this.lblArea.setText("Aire : " + ((areaInfo[2] - areaInfo[0]) * (areaInfo[3] - areaInfo[1]))); this.btnSolo.addActionListener(e -> { Controller.getInstance().finishGame(); MainFrame.getInstance().setContentPane(new SoloGameCreation()); }); this.btnMenu.addActionListener(e -> { Controller.getInstance().finishGame(); MainFrame.getInstance().setContentPane(new MainScreen()); }); this.add(this.gameSummary); this.add(this.lblArea); this.add(this.btnMenu); this.add(this.btnSolo); super.doLayout(); } @Override public void doLayout() { super.doLayout(); final int PADDING_LEFT = getWidthTimesPourcent (this, .05f); final int PADDING_TOP = getHeightTimesPourcent(this, .05f); this.gameSummary.setBounds( PADDING_LEFT, PADDING_TOP, getWidthTimesPourcent (this, .4f), getHeightTimesPourcent(this, .9f) ); final int PADDING_LEFT_GRID = PADDING_LEFT * 2 + this.gameSummary.getWidth(); this.lblArea.setBounds( PADDING_LEFT_GRID, PADDING_TOP, getWidthTimesPourcent (this, .1f), getHeightTimesPourcent(this, .2f) ); this.btnMenu.setBounds( PADDING_LEFT_GRID, this.getHeight() - getHeightTimesPourcent(this, .11f), getWidthTimesPourcent (this, .07f), getHeightTimesPourcent(this, .06f) ); this.btnSolo.setBounds( PADDING_LEFT_GRID + this.btnMenu.getWidth() + PADDING_LEFT, this.getHeight() - getHeightTimesPourcent(this, .11f), getWidthTimesPourcent (this, .07f), getHeightTimesPourcent(this, .06f) ); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); SwingUtils.drawDebugBounds(this, g); } }