From c1902c184df2d4977702fb6aeeb12e7ea21177a2 Mon Sep 17 00:00:00 2001 From: Justine Yannis Date: Fri, 14 Oct 2022 12:49:51 +0200 Subject: [PATCH] SuppressionPremiers tests --- premierTests/Grille.java | 71 --------------------------- premierTests/GrilleMouseListener.java | 17 ------- premierTests/Pion.java | 23 --------- premierTests/Puissance4_View.java | 33 ------------- premierTests/Utils.java | 11 ----- 5 files changed, 155 deletions(-) delete mode 100644 premierTests/Grille.java delete mode 100644 premierTests/GrilleMouseListener.java delete mode 100644 premierTests/Pion.java delete mode 100644 premierTests/Puissance4_View.java delete mode 100644 premierTests/Utils.java diff --git a/premierTests/Grille.java b/premierTests/Grille.java deleted file mode 100644 index 45b43ab..0000000 --- a/premierTests/Grille.java +++ /dev/null @@ -1,71 +0,0 @@ -import javax.swing.*; -import java.awt.*; - -public class Grille extends JPanel { - - private Pion grille[][]; - private int playerTurn = Utils.PLAYER_ONE; - - public Grille() { - super(); - /* - * On peut remplacer GridBagLayout par un GridLayout - */ - GridBagLayout gbl = new GridBagLayout(); - this.setLayout(gbl); - GridBagConstraints gbc = new GridBagConstraints(); - grille = new Pion[Utils.COLUMN_COUNT][Utils.ROW_COUNT]; - for (int x = 0; x < Utils.COLUMN_COUNT; x++) { - for (int y = 0; y < Utils.ROW_COUNT; y++) { - Pion pion = new Pion(); - gbc.gridx = x; - gbc.gridy = y; - gbc.fill = GridBagConstraints.BOTH; - gbc.anchor = GridBagConstraints.CENTER; - gbc.gridwidth = 1; - gbc.gridheight = 1; - gbc.weightx = 0; - gbc.weighty = 0; - gbc.insets = new Insets(0, 0, 0, 0); - - this.add(pion, gbc); - - grille[x][y] = pion; - } - } - - int minimumWidth = Utils.COLUMN_COUNT * grille[0][0].getMinimumSize().width; - int minimumHeight = Utils.ROW_COUNT * grille[0][0].getMinimumSize().height; - int preferredWidth = Utils.COLUMN_COUNT * grille[0][0].getPreferredSize().width; - int preferredHeight = Utils.ROW_COUNT * grille[0][0].getPreferredSize().height; - - this.setMinimumSize(new Dimension(minimumWidth, minimumHeight)); - this.setPreferredSize(new Dimension(preferredWidth, preferredHeight)); - } - - public void drawPlayerPlay(int column, int player) { - for (int row = Utils.ROW_COUNT - 1; row >= 0; row--) { - Pion p = grille[column][row]; - if (p.getBackground() != Utils.PLAYER_ONE_COLOR && p.getBackground() != Utils.PLAYER_TWO_COLOR) { - p.setBackground(player == Utils.PLAYER_ONE ? Utils.PLAYER_ONE_COLOR : Utils.PLAYER_TWO_COLOR); - this.switchPlayer(); - break; - } - } - } - - private void switchPlayer() { - this.playerTurn = (playerTurn + 1) % 2; - } - - public int getPlayerTurn() { - return playerTurn; - } - - @Override - protected void paintComponent(Graphics g) { - Graphics g2 = g.create(); - g2.setColor(Color.BLUE); - g2.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 3 * Utils.PAWN_MARGIN, 3 * Utils.PAWN_MARGIN); - } -} \ No newline at end of file diff --git a/premierTests/GrilleMouseListener.java b/premierTests/GrilleMouseListener.java deleted file mode 100644 index 8b993f2..0000000 --- a/premierTests/GrilleMouseListener.java +++ /dev/null @@ -1,17 +0,0 @@ -import java.awt.event.MouseEvent; -import javax.swing.event.MouseInputAdapter; - -public class GrilleMouseListener extends MouseInputAdapter{ - - private Grille grille; - - public GrilleMouseListener(Grille g) { - this.grille = g; - } - - @Override - public void mouseClicked(MouseEvent e) { - int column = (e.getX() * Utils.COLUMN_COUNT / grille.getWidth()); - grille.drawPlayerPlay(column, grille.getPlayerTurn()); - } -} diff --git a/premierTests/Pion.java b/premierTests/Pion.java deleted file mode 100644 index ce76973..0000000 --- a/premierTests/Pion.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.awt.*; -import javax.swing.*; - -public class Pion extends JComponent{ - - public Pion() { - this.setMinimumSize(new Dimension(80,80)); - this.setMaximumSize(new Dimension(150,150)); - this.setPreferredSize(new Dimension(120,120)); - this.setBackground(Color.WHITE); - } - - @Override - protected void paintComponent(Graphics g) { - Graphics g2 = g.create(); - //g2.setColor(Color.BLUE); - //g2.fillRect(0, 0, this.getWidth(), this.getHeight()); - g2.setColor(Color.GRAY); - g2.fillOval((int) (Utils.PAWN_MARGIN * 1.2),(int) (Utils.PAWN_MARGIN * 1.1) , this.getWidth() - 2 * Utils.PAWN_MARGIN, this.getHeight() - 2 * Utils.PAWN_MARGIN + 2); - g2.setColor(this.getBackground()); - g2.fillOval(Utils.PAWN_MARGIN, Utils.PAWN_MARGIN, this.getWidth() - 2 * Utils.PAWN_MARGIN, this.getHeight() - 2 * Utils.PAWN_MARGIN); - } -} \ No newline at end of file diff --git a/premierTests/Puissance4_View.java b/premierTests/Puissance4_View.java deleted file mode 100644 index 0b6cbd9..0000000 --- a/premierTests/Puissance4_View.java +++ /dev/null @@ -1,33 +0,0 @@ -import javax.swing.*; - -import java.awt.*; - -public class Puissance4_View extends JFrame { - public Puissance4_View() { - super("Puissance 4"); - this.setLayout(new GridBagLayout()); - Grille g = new Grille(); - g.addMouseListener(new GrilleMouseListener(g)); - this.setLocation(200, 200); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.gridx = 1; - gbc.gridy = 1; - gbc.fill = GridBagConstraints.NONE; - gbc.anchor = GridBagConstraints.CENTER; - gbc.gridwidth = 1; - gbc.gridheight = 1; - gbc.weightx = 0; - gbc.weighty = 0; - gbc.insets = new Insets(0, 0, 0, 0); - this.add(g, gbc); - this.setMinimumSize(g.getMinimumSize()); - this.pack(); - this.setVisible(true); - g.requestFocusInWindow(); - } - - public static void main(String[] args) { - Puissance4_View v = new Puissance4_View(); - } -} diff --git a/premierTests/Utils.java b/premierTests/Utils.java deleted file mode 100644 index 1ef1449..0000000 --- a/premierTests/Utils.java +++ /dev/null @@ -1,11 +0,0 @@ -import java.awt.Color; - -public class Utils { - public final static Color PLAYER_ONE_COLOR = Color.RED; - public final static Color PLAYER_TWO_COLOR = Color.YELLOW; - public final static int PLAYER_ONE = 0; - public final static int PLAYER_TWO = 1; - public static int PAWN_MARGIN = 10; - public static int COLUMN_COUNT = 7; - public static int ROW_COUNT = 6; -}