From d2e4de1c2dd4880975c43de9984fab8bcfaf7481 Mon Sep 17 00:00:00 2001 From: Oscar Bauer <oscar.bauer@etu.univ-amu.fr> Date: Thu, 12 Dec 2024 13:53:24 +0100 Subject: [PATCH] Q4 - version1 --- .../CCI_Java/src/tp1/version1/MainGui.java | 7 - .../src/tp1/version1/Minesweeper.java | 3 - .../src/tp1/version1/MinesweeperFrame.java | 19 -- .../src/tp1/version1/MinesweeperPanel.java | 41 ---- .../CCI_Java/src/tp1/version2/MainGui.java | 11 - .../src/tp1/version2/Minesweeper.java | 3 - .../src/tp1/version2/MinesweeperFrame.java | 19 -- .../src/tp1/version2/MinesweeperPanel.java | 36 --- CCI_Java/CCI_Java/src/tp2/v1/MainGui.java | 7 - CCI_Java/CCI_Java/src/tp2/v1/Minesweeper.java | 9 - .../CCI_Java/src/tp2/v1/MinesweeperFrame.java | 25 -- .../CCI_Java/src/tp2/v1/MinesweeperPanel.java | 68 ------ .../src/tp2/v1/MinesweeperPanelDamier.java | 64 ----- CCI_Java/CCI_Java/src/tp2/v1/fiddling.java | 12 - CCI_Java/CCI_Java/src/tp4/v1/Cell.java | 76 ------ CCI_Java/CCI_Java/src/tp4/v1/MainGui.java | 7 - CCI_Java/CCI_Java/src/tp4/v1/Minesweeper.java | 57 ----- .../CCI_Java/src/tp4/v1/MinesweeperFrame.java | 71 ------ .../CCI_Java/src/tp4/v1/MinesweeperPanel.java | 181 -------------- .../src/tp4/v1/MinesweeperPanelable.java | 20 -- .../src/tp4/v1/PanelMouseListener.java | 44 ---- CCI_Java/CCI_Java/src/tp5/v1/Cell.java | 85 ------- CCI_Java/CCI_Java/src/tp5/v1/MainGui.java | 7 - CCI_Java/CCI_Java/src/tp5/v1/Minesweeper.java | 57 ----- .../CCI_Java/src/tp5/v1/MinesweeperFrame.java | 71 ------ .../CCI_Java/src/tp5/v1/MinesweeperPanel.java | 182 -------------- .../src/tp5/v1/MinesweeperPanelable.java | 20 -- .../src/tp5/v1/PanelMouseListener.java | 48 ---- .../src/tp5/v1/TestArrayListOfCell.java | 42 ---- .../src/tp5/v1/TestArrayListOfCell2.java | 30 --- CCI_Java/CCI_Java/src/tp5/v1/TestCell.java | 17 -- CCI_Java/CCI_Java/src/tp5/v2/Cell.java | 85 ------- CCI_Java/CCI_Java/src/tp5/v2/MainGui.java | 7 - CCI_Java/CCI_Java/src/tp5/v2/Minesweeper.java | 57 ----- .../CCI_Java/src/tp5/v2/MinesweeperFrame.java | 71 ------ .../CCI_Java/src/tp5/v2/MinesweeperPanel.java | 195 --------------- .../src/tp5/v2/MinesweeperPanelable.java | 20 -- .../src/tp5/v2/PanelMouseListener.java | 48 ---- .../src/tp5/v2/TestArrayListOfCell.java | 42 ---- .../src/tp5/v2/TestArrayListOfCell2.java | 30 --- CCI_Java/CCI_Java/src/tp5/v2/TestCell.java | 17 -- CCI_Java/CCI_Java/src/tp6/v1/Cell.java | 102 -------- CCI_Java/CCI_Java/src/tp6/v1/MainGui.java | 7 - CCI_Java/CCI_Java/src/tp6/v1/Minesweeper.java | 53 ---- .../CCI_Java/src/tp6/v1/MinesweeperFrame.java | 71 ------ .../CCI_Java/src/tp6/v1/MinesweeperPanel.java | 183 -------------- .../src/tp6/v1/MinesweeperPanelable.java | 17 -- .../src/tp6/v1/PanelMouseListener.java | 48 ---- CCI_Java/CCI_Java/src/tp6/v2/Cell.java | 102 -------- CCI_Java/CCI_Java/src/tp6/v2/MainGui.java | 7 - CCI_Java/CCI_Java/src/tp6/v2/Minesweeper.java | 102 -------- .../CCI_Java/src/tp6/v2/MinesweeperFrame.java | 71 ------ .../CCI_Java/src/tp6/v2/MinesweeperPanel.java | 183 -------------- .../src/tp6/v2/MinesweeperPanelable.java | 17 -- .../src/tp6/v2/PanelMouseListener.java | 43 ---- CCI_Java/CCI_Java/src/tp6/v3/Cell.java | 143 ----------- CCI_Java/CCI_Java/src/tp6/v3/MainGui.java | 7 - CCI_Java/CCI_Java/src/tp6/v3/Minesweeper.java | 199 --------------- .../CCI_Java/src/tp6/v3/MinesweeperFrame.java | 81 ------ .../CCI_Java/src/tp6/v3/MinesweeperPanel.java | 230 ------------------ .../src/tp6/v3/MinesweeperPanelable.java | 22 -- .../src/tp6/v3/PanelMouseListener.java | 50 ---- CCI_Java/CCI_Java/src/tp6/v3/Position.java | 29 --- CCI_Java/CCI_Java/src/version1/Direction.java | 5 + CCI_Java/CCI_Java/src/version1/MainFrame.java | 7 + CCI_Java/CCI_Java/src/version1/Position.java | 16 ++ CCI_Java/CCI_Java/src/version1/SnakeGame.java | 5 + .../CCI_Java/src/version1/SnakeGameFrame.java | 19 ++ .../CCI_Java/src/version1/SnakeGamePanel.java | 97 ++++++++ .../CCI_Java/src/version1/TestDirection.java | 15 ++ .../CCI_Java/src/version1/TestPosition.java | 11 + 71 files changed, 175 insertions(+), 3678 deletions(-) delete mode 100644 CCI_Java/CCI_Java/src/tp1/version1/MainGui.java delete mode 100644 CCI_Java/CCI_Java/src/tp1/version1/Minesweeper.java delete mode 100644 CCI_Java/CCI_Java/src/tp1/version1/MinesweeperFrame.java delete mode 100644 CCI_Java/CCI_Java/src/tp1/version1/MinesweeperPanel.java delete mode 100644 CCI_Java/CCI_Java/src/tp1/version2/MainGui.java delete mode 100644 CCI_Java/CCI_Java/src/tp1/version2/Minesweeper.java delete mode 100644 CCI_Java/CCI_Java/src/tp1/version2/MinesweeperFrame.java delete mode 100644 CCI_Java/CCI_Java/src/tp1/version2/MinesweeperPanel.java delete mode 100644 CCI_Java/CCI_Java/src/tp2/v1/MainGui.java delete mode 100644 CCI_Java/CCI_Java/src/tp2/v1/Minesweeper.java delete mode 100644 CCI_Java/CCI_Java/src/tp2/v1/MinesweeperFrame.java delete mode 100644 CCI_Java/CCI_Java/src/tp2/v1/MinesweeperPanel.java delete mode 100644 CCI_Java/CCI_Java/src/tp2/v1/MinesweeperPanelDamier.java delete mode 100644 CCI_Java/CCI_Java/src/tp2/v1/fiddling.java delete mode 100644 CCI_Java/CCI_Java/src/tp4/v1/Cell.java delete mode 100644 CCI_Java/CCI_Java/src/tp4/v1/MainGui.java delete mode 100644 CCI_Java/CCI_Java/src/tp4/v1/Minesweeper.java delete mode 100644 CCI_Java/CCI_Java/src/tp4/v1/MinesweeperFrame.java delete mode 100644 CCI_Java/CCI_Java/src/tp4/v1/MinesweeperPanel.java delete mode 100644 CCI_Java/CCI_Java/src/tp4/v1/MinesweeperPanelable.java delete mode 100644 CCI_Java/CCI_Java/src/tp4/v1/PanelMouseListener.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/Cell.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/MainGui.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/Minesweeper.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/MinesweeperFrame.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/MinesweeperPanel.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/MinesweeperPanelable.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/PanelMouseListener.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/TestArrayListOfCell.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/TestArrayListOfCell2.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v1/TestCell.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/Cell.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/MainGui.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/Minesweeper.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/MinesweeperFrame.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/MinesweeperPanel.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/MinesweeperPanelable.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/PanelMouseListener.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/TestArrayListOfCell.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/TestArrayListOfCell2.java delete mode 100644 CCI_Java/CCI_Java/src/tp5/v2/TestCell.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v1/Cell.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v1/MainGui.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v1/Minesweeper.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v1/MinesweeperFrame.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v1/MinesweeperPanel.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v1/MinesweeperPanelable.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v1/PanelMouseListener.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v2/Cell.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v2/MainGui.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v2/Minesweeper.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v2/MinesweeperFrame.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v2/MinesweeperPanel.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v2/MinesweeperPanelable.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v2/PanelMouseListener.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v3/Cell.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v3/MainGui.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v3/Minesweeper.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v3/MinesweeperFrame.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v3/MinesweeperPanel.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v3/MinesweeperPanelable.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v3/PanelMouseListener.java delete mode 100644 CCI_Java/CCI_Java/src/tp6/v3/Position.java create mode 100644 CCI_Java/CCI_Java/src/version1/Direction.java create mode 100644 CCI_Java/CCI_Java/src/version1/MainFrame.java create mode 100644 CCI_Java/CCI_Java/src/version1/Position.java create mode 100644 CCI_Java/CCI_Java/src/version1/SnakeGame.java create mode 100644 CCI_Java/CCI_Java/src/version1/SnakeGameFrame.java create mode 100644 CCI_Java/CCI_Java/src/version1/SnakeGamePanel.java create mode 100644 CCI_Java/CCI_Java/src/version1/TestDirection.java create mode 100644 CCI_Java/CCI_Java/src/version1/TestPosition.java diff --git a/CCI_Java/CCI_Java/src/tp1/version1/MainGui.java b/CCI_Java/CCI_Java/src/tp1/version1/MainGui.java deleted file mode 100644 index 986534c..0000000 --- a/CCI_Java/CCI_Java/src/tp1/version1/MainGui.java +++ /dev/null @@ -1,7 +0,0 @@ -package tp1.version1; - -public class MainGui { - public static void main(String[] args) { - new MinesweeperFrame(); - } -} diff --git a/CCI_Java/CCI_Java/src/tp1/version1/Minesweeper.java b/CCI_Java/CCI_Java/src/tp1/version1/Minesweeper.java deleted file mode 100644 index f1c3e3d..0000000 --- a/CCI_Java/CCI_Java/src/tp1/version1/Minesweeper.java +++ /dev/null @@ -1,3 +0,0 @@ -package tp1.version1; -public class Minesweeper { -} diff --git a/CCI_Java/CCI_Java/src/tp1/version1/MinesweeperFrame.java b/CCI_Java/CCI_Java/src/tp1/version1/MinesweeperFrame.java deleted file mode 100644 index 3fc922a..0000000 --- a/CCI_Java/CCI_Java/src/tp1/version1/MinesweeperFrame.java +++ /dev/null @@ -1,19 +0,0 @@ -package tp1.version1; - -import javax.swing.JFrame; -import javax.swing.WindowConstants; - -@SuppressWarnings("serial") -public class MinesweeperFrame extends JFrame { - Minesweeper minesweeper; - MinesweeperPanel minesweeperPanel; - - public MinesweeperFrame() { - this.minesweeper = new Minesweeper(); - this.minesweeperPanel = new MinesweeperPanel(minesweeper); - add(minesweeperPanel); - pack(); - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setVisible(true); - } -} diff --git a/CCI_Java/CCI_Java/src/tp1/version1/MinesweeperPanel.java b/CCI_Java/CCI_Java/src/tp1/version1/MinesweeperPanel.java deleted file mode 100644 index 4b4b328..0000000 --- a/CCI_Java/CCI_Java/src/tp1/version1/MinesweeperPanel.java +++ /dev/null @@ -1,41 +0,0 @@ -package tp1.version1; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; - -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanel extends JPanel { - Minesweeper minesweeper; - - public MinesweeperPanel(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - g.setColor(Color.RED); - g.drawLine(getWidth()/2, getHeight()/2, getWidth(), getHeight()); - - g.setColor(Color.BLUE); - g.drawLine(getWidth(), 0, getWidth() / 2, getHeight() / 2); - - g.setColor(Color.BLACK); - g.drawLine(0, 0, getWidth() / 2, getHeight() / 2); - - g.setColor(Color.CYAN); - g.drawLine(0, getHeight(), getWidth() / 2, getHeight() / 2); - - g.setColor(Color.LIGHT_GRAY); - g.fillRect(200, 200, 30, 30); - - g.setColor(Color.GRAY); - g.drawRect(200, 200, 30, 30); - - - } -} diff --git a/CCI_Java/CCI_Java/src/tp1/version2/MainGui.java b/CCI_Java/CCI_Java/src/tp1/version2/MainGui.java deleted file mode 100644 index 252af4b..0000000 --- a/CCI_Java/CCI_Java/src/tp1/version2/MainGui.java +++ /dev/null @@ -1,11 +0,0 @@ -package tp1.version2; - -public class MainGui { - public static void main(String[] args) { - new MinesweeperFrame(); - - - - - } -} diff --git a/CCI_Java/CCI_Java/src/tp1/version2/Minesweeper.java b/CCI_Java/CCI_Java/src/tp1/version2/Minesweeper.java deleted file mode 100644 index e77c805..0000000 --- a/CCI_Java/CCI_Java/src/tp1/version2/Minesweeper.java +++ /dev/null @@ -1,3 +0,0 @@ -package tp1.version2; -public class Minesweeper { -} diff --git a/CCI_Java/CCI_Java/src/tp1/version2/MinesweeperFrame.java b/CCI_Java/CCI_Java/src/tp1/version2/MinesweeperFrame.java deleted file mode 100644 index 828c644..0000000 --- a/CCI_Java/CCI_Java/src/tp1/version2/MinesweeperFrame.java +++ /dev/null @@ -1,19 +0,0 @@ -package tp1.version2; - -import javax.swing.JFrame; -import javax.swing.WindowConstants; - -@SuppressWarnings("serial") -public class MinesweeperFrame extends JFrame { - Minesweeper minesweeper; - MinesweeperPanel minesweeperPanel; - - public MinesweeperFrame() { - this.minesweeper = new Minesweeper(); - this.minesweeperPanel = new MinesweeperPanel(minesweeper); - add(minesweeperPanel); - pack(); - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setVisible(true); - } -} diff --git a/CCI_Java/CCI_Java/src/tp1/version2/MinesweeperPanel.java b/CCI_Java/CCI_Java/src/tp1/version2/MinesweeperPanel.java deleted file mode 100644 index 370908c..0000000 --- a/CCI_Java/CCI_Java/src/tp1/version2/MinesweeperPanel.java +++ /dev/null @@ -1,36 +0,0 @@ -package tp1.version2; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; - -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanel extends JPanel { - Minesweeper minesweeper; - - public MinesweeperPanel(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - g.setColor(Color.RED); - g.drawLine(0, 0, getWidth(), getHeight()); - - g.setColor(Color.BLUE); - g.drawLine(500, 0, getWidth() / 2, getHeight() / 2); - - g.setColor(Color.BLACK); - g.drawRect(100, 200, 30, 50); - - g.setColor(Color.LIGHT_GRAY); - g.fillRect(200, 200, 30, 30); - - g.setColor(Color.GRAY); - g.drawRect(200, 200, 30, 30); - } -} diff --git a/CCI_Java/CCI_Java/src/tp2/v1/MainGui.java b/CCI_Java/CCI_Java/src/tp2/v1/MainGui.java deleted file mode 100644 index 08ae859..0000000 --- a/CCI_Java/CCI_Java/src/tp2/v1/MainGui.java +++ /dev/null @@ -1,7 +0,0 @@ -package tp2.v1; - -public class MainGui { - public static void main(String[] args) { - new MinesweeperFrame(); - } -} diff --git a/CCI_Java/CCI_Java/src/tp2/v1/Minesweeper.java b/CCI_Java/CCI_Java/src/tp2/v1/Minesweeper.java deleted file mode 100644 index 059a25a..0000000 --- a/CCI_Java/CCI_Java/src/tp2/v1/Minesweeper.java +++ /dev/null @@ -1,9 +0,0 @@ -package tp2.v1; - -public class Minesweeper { - int nbColumns; - int nbLines; - int score; - int selectedLine; - int selectedColumn; -} diff --git a/CCI_Java/CCI_Java/src/tp2/v1/MinesweeperFrame.java b/CCI_Java/CCI_Java/src/tp2/v1/MinesweeperFrame.java deleted file mode 100644 index b01ee91..0000000 --- a/CCI_Java/CCI_Java/src/tp2/v1/MinesweeperFrame.java +++ /dev/null @@ -1,25 +0,0 @@ -package tp2.v1; - -import javax.swing.JFrame; -import javax.swing.WindowConstants; -@SuppressWarnings("serial") -public class MinesweeperFrame extends JFrame { -Minesweeper minesweeper; -MinesweeperPanel minesweeperPanel; -public MinesweeperFrame() { -this.minesweeper = new Minesweeper(); - -this.minesweeper.nbColumns = 15; -this.minesweeper.nbLines = 20; -this.minesweeper.score = 30; -this.minesweeper.selectedLine = 3; -this.minesweeper.selectedColumn = 8; - -this.minesweeperPanel = new MinesweeperPanel(minesweeper); -add(minesweeperPanel); -pack(); -setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); -setVisible(true); - - -}} \ No newline at end of file diff --git a/CCI_Java/CCI_Java/src/tp2/v1/MinesweeperPanel.java b/CCI_Java/CCI_Java/src/tp2/v1/MinesweeperPanel.java deleted file mode 100644 index 5701c68..0000000 --- a/CCI_Java/CCI_Java/src/tp2/v1/MinesweeperPanel.java +++ /dev/null @@ -1,68 +0,0 @@ -package tp2.v1; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanel extends JPanel { - Minesweeper minesweeper; - int spaceHor; - int spaceVert; - - public MinesweeperPanel(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - // grand rect - - int spaceBorder = 20; - int nbColumns = this.minesweeper.nbColumns; - int nbRows = this.minesweeper.nbLines; - - int carreWidth = (getWidth() - (spaceBorder * 2)) - ((getWidth() - (spaceBorder * 2)) % nbColumns); - int carreHeight = (getHeight() - (spaceBorder * 2)) - ((getHeight() - (spaceBorder * 2)) % nbRows); - - this.spaceHor = carreWidth / nbColumns; - this.spaceVert = carreHeight / nbRows; - - int lineEndH = carreHeight + spaceBorder; - int lineEndV = carreWidth + spaceBorder; - - // creating collumns - int posH = spaceBorder; - g.setColor(Color.BLACK); - g.drawLine(spaceBorder, spaceBorder, spaceBorder, lineEndH); - - for (int idx = 1; idx <= nbColumns; idx++) { - posH = (idx * spaceHor) + spaceBorder; - g.setColor(Color.BLACK); - g.drawLine(posH, spaceBorder, posH, lineEndH); - } - - // creating rows - int posV = spaceBorder; - g.setColor(Color.BLACK); - g.drawLine(spaceBorder, spaceBorder, lineEndV, spaceBorder); - - for (int idx = 1; idx <= nbRows; idx++) { - posV = (idx * spaceVert) + spaceBorder; - g.setColor(Color.BLACK); - g.drawLine(spaceBorder, posV, lineEndV, posV); - } - - // show score - - g.setColor(Color.darkGray); - g.setFont(new Font("Ariel", Font.BOLD, spaceBorder - 3)); - g.drawString("Score : " + this.minesweeper.score, (getWidth() / 2) - 40, (spaceBorder - 3)); - - } -} diff --git a/CCI_Java/CCI_Java/src/tp2/v1/MinesweeperPanelDamier.java b/CCI_Java/CCI_Java/src/tp2/v1/MinesweeperPanelDamier.java deleted file mode 100644 index 5c0ac8e..0000000 --- a/CCI_Java/CCI_Java/src/tp2/v1/MinesweeperPanelDamier.java +++ /dev/null @@ -1,64 +0,0 @@ -package tp2.v1; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanelDamier extends JPanel { - Minesweeper minesweeper; - - public MinesweeperPanelDamier(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - g.setColor(Color.RED); - g.drawLine(0, 0, getWidth(), getHeight()); - g.setColor(Color.BLUE); - g.drawLine(getWidth(), getHeight(), getWidth() / 2, getHeight() / 2); - -// grand rect - int widthHouse = getWidth() / 3; - int heightHouse = getHeight() / 3; - int xMid = getWidth() / 2; - int yMid = getHeight() / 2; - int unten = yMid + (heightHouse / 2) ; - int oben = yMid - heightHouse / 2; - int links = xMid - widthHouse / 2; - int rechts = xMid + (widthHouse / 2); - // house - g.setColor(Color.YELLOW); - g.fillRect(links, - oben, - widthHouse, - heightHouse); - g.setColor(Color.BLACK); - g.drawRect(links, - oben, - widthHouse, - heightHouse); - - g.setColor(Color.BLACK); - g.drawLine(links, oben, rechts - widthHouse / 2, oben - heightHouse / 2); - g.setColor(Color.BLACK); - g.drawLine(rechts, oben, links + widthHouse / 2, oben - heightHouse / 2); -////port -// g.setColor(Color.LIGHT_GRAY); -// g.fillRect(200, 200, 30, 30); -// g.setColor(Color.GRAY); -// g.drawRect(200, 200, 30, 30); - -// g.setColor(Color.BLUE); - g.setColor(Color.RED); - g.drawLine(links, oben, rechts, oben); - - // Oval getWidth() getHeight() - g.setColor(Color.RED); - g.drawOval(0, 100, 10, 10); - } -} diff --git a/CCI_Java/CCI_Java/src/tp2/v1/fiddling.java b/CCI_Java/CCI_Java/src/tp2/v1/fiddling.java deleted file mode 100644 index 043a6f8..0000000 --- a/CCI_Java/CCI_Java/src/tp2/v1/fiddling.java +++ /dev/null @@ -1,12 +0,0 @@ -package tp2.v1; - -public class fiddling { - - public static void main(String[] args) { - // TODO Auto-generated method stub - int x = 20%9; - System.out.println(x); - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp4/v1/Cell.java b/CCI_Java/CCI_Java/src/tp4/v1/Cell.java deleted file mode 100644 index d86ea83..0000000 --- a/CCI_Java/CCI_Java/src/tp4/v1/Cell.java +++ /dev/null @@ -1,76 +0,0 @@ -package tp4.v1; - -import java.awt.Color; - -public class Cell { - boolean isRevealed; - boolean isMine; - boolean isSelected; - Color color; - int row; - int column; - boolean active; - - public Cell(boolean isMine, int row, int column) { - this.isRevealed = false; - this.isSelected = false; - this.color = Color.GRAY; - this.isMine = isMine; - this.row = row; - this.column = column; - this.active = true; - } - - private void refreshColor() { - - if (this.isSelected) - this.color = Color.RED; - else if (!this.isRevealed) - this.color = Color.DARK_GRAY; - else - this.color = Color.lightGray; - } - - public void setSelected(boolean isSelected) { - this.isSelected = isSelected; - } - - public void setRevealed(boolean status) { - this.isRevealed = status; - this.active = false; - - if (status && !this.isMine) - this.color = Color.DARK_GRAY; - } - - public void setMine(boolean isMine) { - this.isMine = isMine; - } - - public boolean getIsSelected() { - return isSelected; - } - - public Color getColor() { - if (active) - refreshColor(); - return color; - } - - public void setColor(Color color) { - this.color = color; - } - - public boolean isRevealed() { - return isRevealed; - } - - public boolean getIsMine() { - return isMine; - } - - public void setActive(boolean active) { - this.active = active; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp4/v1/MainGui.java b/CCI_Java/CCI_Java/src/tp4/v1/MainGui.java deleted file mode 100644 index 44f1303..0000000 --- a/CCI_Java/CCI_Java/src/tp4/v1/MainGui.java +++ /dev/null @@ -1,7 +0,0 @@ -package tp4.v1; - -public class MainGui { - public static void main(String[] args) { - new MinesweeperFrame(); - } -} diff --git a/CCI_Java/CCI_Java/src/tp4/v1/Minesweeper.java b/CCI_Java/CCI_Java/src/tp4/v1/Minesweeper.java deleted file mode 100644 index 50b537c..0000000 --- a/CCI_Java/CCI_Java/src/tp4/v1/Minesweeper.java +++ /dev/null @@ -1,57 +0,0 @@ -package tp4.v1; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class Minesweeper { - int nbColumns; - int nbLines; - int score; - int selectedLine; - int selectedColumn; - - double difficulte = 0.25; - Color colorSweeper = Color.RED; - - ArrayList<List<Cell>> board; - - public Minesweeper() { - this.nbColumns = 10; - this.nbLines = 10; - this.score = this.nbColumns * this.nbLines; - this.selectedLine = 0; - this.selectedColumn = 0; - this.board = new ArrayList<List<Cell>>(); - - - for (int row = 0; row < this.nbLines; row++) { - this.board.add(new ArrayList<Cell>()); - for (int column = 0; column < this.nbColumns; column++) { - boolean isMine = ((int) (Math.random() + difficulte)) == 1; - Cell cell = new Cell(isMine, row, column); - if (isMine) - score--; - this.board.get(row).add(cell); - } - } - } - - public double getDifficulte() { - return difficulte; - } - - public void setDifficulte(double difficulte) { - this.difficulte = difficulte; - } - - public Color getColorSweeper() { - return colorSweeper; - } - - public void setColorSweeper(Color color) { - this.colorSweeper = color; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp4/v1/MinesweeperFrame.java b/CCI_Java/CCI_Java/src/tp4/v1/MinesweeperFrame.java deleted file mode 100644 index 415d4f8..0000000 --- a/CCI_Java/CCI_Java/src/tp4/v1/MinesweeperFrame.java +++ /dev/null @@ -1,71 +0,0 @@ -package tp4.v1; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.WindowConstants; - -@SuppressWarnings("serial") -public class MinesweeperFrame extends JFrame { - Minesweeper minesweeper; - MinesweeperPanel minesweeperPanel; - static JMenuBar mb; - - static JMenu menu, size, difficulte, color; - -// static JMenuItem size, difficulte, color; - static JMenuItem size1, size2, size3, diff1, diff2, diff3, color1, color2, color3 ; - static JFrame f; - - public MinesweeperFrame() { - - mb = new JMenuBar(); - - - menu = new JMenu("menu"); - size = new JMenu("size in pixel"); - difficulte = new JMenu("Mines/no mines"); - color = new JMenu("Color"); - - size1 = new JMenuItem("500"); - size2 = new JMenuItem("700"); - size3 = new JMenuItem("1000"); - - size.add(size1); - size.add(size2); - size.add(size3); - - diff1 = new JMenuItem("50/50"); - diff2 = new JMenuItem("25/75"); - diff3 = new JMenuItem("75/25"); - - difficulte.add(diff1); - difficulte.add(diff2); - difficulte.add(diff3); - - color1 = new JMenuItem("red"); - color2 = new JMenuItem("blue"); - color3 = new JMenuItem("black"); - - color.add(color1); - color.add(color2); - color.add(color3); - - menu.add(size); - menu.add(difficulte); - menu.add(color); - - mb.add(menu); - setJMenuBar(mb); - this.minesweeper = new Minesweeper(); - - this.minesweeperPanel = new MinesweeperPanel(minesweeper); - add(minesweeperPanel); - - pack(); - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setVisible(true); - - } -} \ No newline at end of file diff --git a/CCI_Java/CCI_Java/src/tp4/v1/MinesweeperPanel.java b/CCI_Java/CCI_Java/src/tp4/v1/MinesweeperPanel.java deleted file mode 100644 index cd0eb40..0000000 --- a/CCI_Java/CCI_Java/src/tp4/v1/MinesweeperPanel.java +++ /dev/null @@ -1,181 +0,0 @@ -package tp4.v1; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.event.MouseEvent; -import java.util.Scanner; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanel extends JPanel implements MinesweeperPanelable { - Minesweeper minesweeper; - int spaceHor; - int spaceVert; - int nbColumns; - int nbRows; - int selCol; - int selLine; - int carreWidth; - int carreHeight; - int spaceBorder; - - static JMenuBar mb; - - static JMenu menu; - - static JMenuItem size, difficulte, color; - - static JFrame f; - - public MinesweeperPanel(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - addMouseListener(new PanelMouseListener(this)); - addMouseMotionListener(new PanelMouseListener(this)); - spaceBorder = 20; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - this.nbColumns = this.minesweeper.nbColumns; - this.nbRows = this.minesweeper.nbLines; - - this.carreWidth = (getWidth() - (getBoardBorder() * 2)) - ((getWidth() - (getBoardBorder() * 2)) % nbColumns); - this.carreHeight = (getHeight() - (getBoardBorder() * 2)) - ((getHeight() - (getBoardBorder() * 2)) % nbRows); - - this.spaceHor = carreWidth / nbColumns; - this.spaceVert = carreHeight / nbRows; - - int lineEndH = carreHeight + getBoardBorder(); - int lineEndV = carreWidth + getBoardBorder(); - - for (int idxRow = 0; idxRow < this.minesweeper.board.size(); idxRow++) { - for (int idxCol = 0; idxCol < this.minesweeper.board.get(idxRow).size(); idxCol++) { - Cell tmp = this.minesweeper.board.get(idxRow).get(idxCol); - drawCell(g, idxRow, idxCol); - tmp.setSelected(false); - } - } - - // show score - g.setColor(Color.darkGray); - g.setFont(new Font("Ariel", Font.BOLD, spaceBorder - 3)); - g.drawString("Score : " + this.minesweeper.score, (getWidth() / 2) - 40, (spaceBorder - 3)); - - } - - public void drawCell(Graphics g, int line, int column) { - - g.setColor(Color.BLACK); - g.drawRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - Cell tmp = this.minesweeper.board.get(line).get(column); - g.setColor(tmp.getColor()); - g.fillRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - - if (tmp.isRevealed && tmp.isMine) { - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(getCellX(column) + (getCellWidth() / 2) - (sizeBomb / 2), - getCellX(line) + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } - } - - public void drawCell(Graphics g, Cell tmp) { - - g.setColor(Color.BLACK); - g.drawRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - - g.setColor(tmp.getColor()); - g.fillRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - - if (tmp.isRevealed && tmp.isMine) { - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(getCellX(tmp.column) + (getCellWidth() / 2) - (sizeBomb / 2), - getCellX(tmp.row) + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } - } - - public int getColumn(int x) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - if (condX) { - int posCarre = x - getBoardBorder(); - this.selCol = posCarre / getCellWidth(); - return this.selCol; - } - return -1; - } - - public int getLine(int y) { - - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condY) { - int posCarre = y - getBoardBorder(); - this.selLine = posCarre / spaceVert; - return this.selLine; - } - return -1; - - } - - public int getBoardBorder() { - return this.spaceBorder; - } - - @Override - public boolean isBlackCell(int line, int column) { - return this.minesweeper.board.get(line).get(column).getColor() == Color.DARK_GRAY; - } - - @Override - public boolean isGrayCell(int line, int column) { - return this.minesweeper.board.get(line).get(column).getColor() == Color.GRAY; - } - - public boolean isRedCell(int line, int column) { - return this.minesweeper.board.get(line).get(column).getColor() == Color.RED; - } - - boolean isMine(int line, int column) { - return this.minesweeper.board.get(line).get(column).isMine; - } - - public int getCellX(int column) { - return (getBoardBorder() + (column * getCellWidth())); - } - - public int getCellY(int line) { - return (getBoardBorder() + (line * getCellHeight())); - } - - public int getCellWidth() { - return this.spaceHor; - } - - public int getCellHeight() { - return this.spaceVert; - } - - public boolean isOutOfBounds(int x, int y) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condX && condY) - return true; - return false; - } - - @Override - public void drawMinesweeper(Graphics g) { - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp4/v1/MinesweeperPanelable.java b/CCI_Java/CCI_Java/src/tp4/v1/MinesweeperPanelable.java deleted file mode 100644 index cef899e..0000000 --- a/CCI_Java/CCI_Java/src/tp4/v1/MinesweeperPanelable.java +++ /dev/null @@ -1,20 +0,0 @@ -package tp4.v1; - -import java.awt.Graphics; - -public interface MinesweeperPanelable { - - public int getBoardBorder(); - public boolean isBlackCell(int line, int column); - public boolean isGrayCell(int line, int column); - public boolean isRedCell(int line, int column); - public int getCellX(int column); - public int getCellY(int line); - public int getCellWidth(); - public int getCellHeight(); - public void drawCell(Graphics g, int line, int column); - public int getColumn(int x); - public int getLine(int y); - void drawMinesweeper(Graphics g); - -} diff --git a/CCI_Java/CCI_Java/src/tp4/v1/PanelMouseListener.java b/CCI_Java/CCI_Java/src/tp4/v1/PanelMouseListener.java deleted file mode 100644 index 5deb822..0000000 --- a/CCI_Java/CCI_Java/src/tp4/v1/PanelMouseListener.java +++ /dev/null @@ -1,44 +0,0 @@ -package tp4.v1; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -public class PanelMouseListener extends MouseAdapter { - MinesweeperPanel panel; - - public PanelMouseListener(MinesweeperPanel panel) { - this.panel = panel; - } - - @Override - public void mouseClicked(MouseEvent e) { - -// System.out.println("Click Line = " + panel.minesweeper.selectedLine); -// System.out.println("Click Column = " + panel.minesweeper.selectedColumn); - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - panel.minesweeper.board.get(line).get(column).isRevealed = true; -// panel.minesweeper.score--; - panel.repaint(); - } - - @Override - public void mouseMoved(MouseEvent e) { - -// panel.minesweeper.selectedLine = panel.getLine(e.getY()); -// panel.minesweeper.selectedColumn = panel.getColumn(e.getX()); - - try { - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - if (!panel.isOutOfBounds(line, column)) { - panel.minesweeper.board.get(line).get(column).setSelected(true); - panel.repaint(); - } - } catch (Exception e2) { - // TODO: handle exception -// e2.printStackTrace(); - } - - - } -} diff --git a/CCI_Java/CCI_Java/src/tp5/v1/Cell.java b/CCI_Java/CCI_Java/src/tp5/v1/Cell.java deleted file mode 100644 index 3a58f97..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/Cell.java +++ /dev/null @@ -1,85 +0,0 @@ -package tp5.v1; - -import java.awt.Color; - -public class Cell { - boolean isRevealed; - boolean isMine; - boolean isSelected; - Color color; - int row; - int column; - boolean active; - - public Cell(boolean isMine, int row, int column) { - this.isRevealed = false; - this.isSelected = false; - this.color = Color.GRAY; - this.isMine = isMine; - this.row = row; - this.column = column; - this.active = true; - } - - private void refreshColor() { - - if (this.isSelected) - this.color = Color.RED; - else if (!this.isRevealed) - this.color = Color.DARK_GRAY; - else - this.color = Color.lightGray; - } - - public void setSelected(boolean isSelected) { - this.isSelected = isSelected; - } - - public void setRevealed(boolean status) { - this.isRevealed = status; - this.active = false; - - if (status && !this.isMine) - this.color = Color.DARK_GRAY; - } - - public void setMine(boolean isMine) { - this.isMine = isMine; - } - - public boolean getIsSelected() { - return isSelected; - } - - public Color getColor() { - if (active) - refreshColor(); - return color; - } - - public void setColor(Color color) { - this.color = color; - } - - public boolean isRevealed() { - return isRevealed; - } - - public boolean getIsMine() { - return isMine; - } - - public void setActive(boolean active) { - this.active = active; - } - - @Override - public String toString() { - if(!isRevealed) - return "C"; - else if (isMine) - return "B"; - return "V"; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v1/MainGui.java b/CCI_Java/CCI_Java/src/tp5/v1/MainGui.java deleted file mode 100644 index 2856de7..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/MainGui.java +++ /dev/null @@ -1,7 +0,0 @@ -package tp5.v1; - -public class MainGui { - public static void main(String[] args) { - new MinesweeperFrame(); - } -} diff --git a/CCI_Java/CCI_Java/src/tp5/v1/Minesweeper.java b/CCI_Java/CCI_Java/src/tp5/v1/Minesweeper.java deleted file mode 100644 index dfee230..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/Minesweeper.java +++ /dev/null @@ -1,57 +0,0 @@ -package tp5.v1; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class Minesweeper { - int nbColumns; - int nbLines; - int score; - int selectedLine; - int selectedColumn; - - double difficulte = 0.25; - Color colorSweeper = Color.RED; - - ArrayList<List<Cell>> board; - - public Minesweeper() { - this.nbColumns = 10; - this.nbLines = 10; - this.score = this.nbColumns * this.nbLines; - this.selectedLine = 0; - this.selectedColumn = 0; - this.board = new ArrayList<List<Cell>>(); - - - for (int row = 0; row < this.nbLines; row++) { - this.board.add(new ArrayList<Cell>()); - for (int column = 0; column < this.nbColumns; column++) { - boolean isMine = ((int) (Math.random() + difficulte)) == 1; - Cell cell = new Cell(isMine, row, column); - if (isMine) - score--; - this.board.get(row).add(cell); - } - } - } - - public double getDifficulte() { - return difficulte; - } - - public void setDifficulte(double difficulte) { - this.difficulte = difficulte; - } - - public Color getColorSweeper() { - return colorSweeper; - } - - public void setColorSweeper(Color color) { - this.colorSweeper = color; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v1/MinesweeperFrame.java b/CCI_Java/CCI_Java/src/tp5/v1/MinesweeperFrame.java deleted file mode 100644 index 64170d5..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/MinesweeperFrame.java +++ /dev/null @@ -1,71 +0,0 @@ -package tp5.v1; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.WindowConstants; - -@SuppressWarnings("serial") -public class MinesweeperFrame extends JFrame { - Minesweeper minesweeper; - MinesweeperPanel minesweeperPanel; - static JMenuBar mb; - - static JMenu menu, size, difficulte, color; - -// static JMenuItem size, difficulte, color; - static JMenuItem size1, size2, size3, diff1, diff2, diff3, color1, color2, color3 ; - static JFrame f; - - public MinesweeperFrame() { - - mb = new JMenuBar(); - - - menu = new JMenu("menu"); - size = new JMenu("size in pixel"); - difficulte = new JMenu("Mines/no mines"); - color = new JMenu("Color"); - - size1 = new JMenuItem("500"); - size2 = new JMenuItem("700"); - size3 = new JMenuItem("1000"); - - size.add(size1); - size.add(size2); - size.add(size3); - - diff1 = new JMenuItem("50/50"); - diff2 = new JMenuItem("25/75"); - diff3 = new JMenuItem("75/25"); - - difficulte.add(diff1); - difficulte.add(diff2); - difficulte.add(diff3); - - color1 = new JMenuItem("red"); - color2 = new JMenuItem("blue"); - color3 = new JMenuItem("black"); - - color.add(color1); - color.add(color2); - color.add(color3); - - menu.add(size); - menu.add(difficulte); - menu.add(color); - - mb.add(menu); - setJMenuBar(mb); - this.minesweeper = new Minesweeper(); - - this.minesweeperPanel = new MinesweeperPanel(minesweeper); - add(minesweeperPanel); - - pack(); - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setVisible(true); - - } -} \ No newline at end of file diff --git a/CCI_Java/CCI_Java/src/tp5/v1/MinesweeperPanel.java b/CCI_Java/CCI_Java/src/tp5/v1/MinesweeperPanel.java deleted file mode 100644 index 1f80744..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/MinesweeperPanel.java +++ /dev/null @@ -1,182 +0,0 @@ -package tp5.v1; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.event.MouseEvent; -import java.util.Scanner; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanel extends JPanel implements MinesweeperPanelable { - Minesweeper minesweeper; - int spaceHor; - int spaceVert; - int nbColumns; - int nbRows; - int selCol; - int selLine; - int carreWidth; - int carreHeight; - int spaceBorder; - - static JMenuBar mb; - - static JMenu menu; - - static JMenuItem size, difficulte, color; - - static JFrame f; - - public MinesweeperPanel(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - addMouseListener(new PanelMouseListener(this)); - addMouseMotionListener(new PanelMouseListener(this)); - spaceBorder = 20; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - this.nbColumns = this.minesweeper.nbColumns; - this.nbRows = this.minesweeper.nbLines; - - this.carreWidth = (getWidth() - (getBoardBorder() * 2)) - ((getWidth() - (getBoardBorder() * 2)) % nbColumns); - this.carreHeight = (getHeight() - (getBoardBorder() * 2)) - ((getHeight() - (getBoardBorder() * 2)) % nbRows); - - this.spaceHor = carreWidth / nbColumns; - this.spaceVert = carreHeight / nbRows; - - int lineEndH = carreHeight + getBoardBorder(); - int lineEndV = carreWidth + getBoardBorder(); - - for (int idxRow = 0; idxRow < this.minesweeper.board.size(); idxRow++) { - for (int idxCol = 0; idxCol < this.minesweeper.board.get(idxRow).size(); idxCol++) { - Cell tmp = this.minesweeper.board.get(idxRow).get(idxCol); -// drawCell(g, idxRow, idxCol); - drawCell(g, tmp); - tmp.setSelected(false); - } - } - - // show score - g.setColor(Color.darkGray); - g.setFont(new Font("Ariel", Font.BOLD, spaceBorder - 3)); - g.drawString("Score : " + this.minesweeper.score, (getWidth() / 2) - 40, (spaceBorder - 3)); - - } - - public void drawCell(Graphics g, int line, int column) { - - g.setColor(Color.BLACK); - g.drawRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - Cell tmp = this.minesweeper.board.get(line).get(column); - g.setColor(tmp.getColor()); - g.fillRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - - if (tmp.isRevealed && tmp.isMine) { - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(getCellX(column) + (getCellWidth() / 2) - (sizeBomb / 2), - getCellX(line) + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } - } - - public void drawCell(Graphics g, Cell tmp) { - - g.setColor(Color.BLACK); - g.drawRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - - g.setColor(tmp.getColor()); - g.fillRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - - if (tmp.isRevealed && tmp.isMine) { - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(getCellX(tmp.column) + (getCellWidth() / 2) - (sizeBomb / 2), - getCellX(tmp.row) + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } - } - - public int getColumn(int x) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - if (condX) { - int posCarre = x - getBoardBorder(); - this.selCol = posCarre / getCellWidth(); - return this.selCol; - } - return -1; - } - - public int getLine(int y) { - - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condY) { - int posCarre = y - getBoardBorder(); - this.selLine = posCarre / spaceVert; - return this.selLine; - } - return -1; - - } - - public int getBoardBorder() { - return this.spaceBorder; - } - - @Override - public boolean isBlackCell(int line, int column) { - return this.minesweeper.board.get(line).get(column).getColor() == Color.DARK_GRAY; - } - - @Override - public boolean isGrayCell(int line, int column) { - return this.minesweeper.board.get(line).get(column).getColor() == Color.GRAY; - } - - public boolean isRedCell(int line, int column) { - return this.minesweeper.board.get(line).get(column).getColor() == Color.RED; - } - - boolean isMine(int line, int column) { - return this.minesweeper.board.get(line).get(column).isMine; - } - - public int getCellX(int column) { - return (getBoardBorder() + (column * getCellWidth())); - } - - public int getCellY(int line) { - return (getBoardBorder() + (line * getCellHeight())); - } - - public int getCellWidth() { - return this.spaceHor; - } - - public int getCellHeight() { - return this.spaceVert; - } - - public boolean isOutOfBounds(int x, int y) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condX && condY) - return true; - return false; - } - - @Override - public void drawMinesweeper(Graphics g) { - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v1/MinesweeperPanelable.java b/CCI_Java/CCI_Java/src/tp5/v1/MinesweeperPanelable.java deleted file mode 100644 index e9e929a..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/MinesweeperPanelable.java +++ /dev/null @@ -1,20 +0,0 @@ -package tp5.v1; - -import java.awt.Graphics; - -public interface MinesweeperPanelable { - - public int getBoardBorder(); - public boolean isBlackCell(int line, int column); - public boolean isGrayCell(int line, int column); - public boolean isRedCell(int line, int column); - public int getCellX(int column); - public int getCellY(int line); - public int getCellWidth(); - public int getCellHeight(); - public void drawCell(Graphics g, int line, int column); - public int getColumn(int x); - public int getLine(int y); - void drawMinesweeper(Graphics g); - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v1/PanelMouseListener.java b/CCI_Java/CCI_Java/src/tp5/v1/PanelMouseListener.java deleted file mode 100644 index 599ae95..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/PanelMouseListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package tp5.v1; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -public class PanelMouseListener extends MouseAdapter { - MinesweeperPanel panel; - - public PanelMouseListener(MinesweeperPanel panel) { - this.panel = panel; - } - - @Override - public void mouseClicked(MouseEvent e) { - -// System.out.println("Click Line = " + panel.minesweeper.selectedLine); -// System.out.println("Click Column = " + panel.minesweeper.selectedColumn); - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - Cell tmpCell = panel.minesweeper.board.get(line).get(column); - tmpCell.isRevealed = true; - if (!tmpCell.isMine) - panel.minesweeper.score--; - -// panel.minesweeper.score--; - panel.repaint(); - } - - @Override - public void mouseMoved(MouseEvent e) { - -// panel.minesweeper.selectedLine = panel.getLine(e.getY()); -// panel.minesweeper.selectedColumn = panel.getColumn(e.getX()); - - try { - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - if (!panel.isOutOfBounds(line, column)) { - panel.minesweeper.board.get(line).get(column).setSelected(true); - panel.repaint(); - } - } catch (Exception e2) { - // TODO: handle exception -// e2.printStackTrace(); - } - - - } -} diff --git a/CCI_Java/CCI_Java/src/tp5/v1/TestArrayListOfCell.java b/CCI_Java/CCI_Java/src/tp5/v1/TestArrayListOfCell.java deleted file mode 100644 index 3f3acc3..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/TestArrayListOfCell.java +++ /dev/null @@ -1,42 +0,0 @@ -package tp5.v1; - -import java.util.ArrayList; - -public class TestArrayListOfCell { - - public static void main(String[] args) { - Cell cell0 = new Cell(false, 1, 1); - Cell cell1 = new Cell(true, 1, 1); - Cell cell2 = new Cell(false, 1, 1); - Cell cell3 = new Cell(true, 1, 1); - - cell2.setRevealed(true); - cell3.setRevealed(true); - -// ArrayList<Cell> cells = new ArrayList<Cell>(); - ArrayList<ArrayList<Cell>> board = new ArrayList<ArrayList<Cell>>(); - - for (int column = 0; column < 4; column++) { - - Cell cell = new Cell(((int) (Math.random() + 0.5)) == 1, 1, 1); - cell.isRevealed = ((int) (Math.random() + 0.5)) == 1; - - } - - - for (int row = 0; row < 2; row++) { - board.add(new ArrayList<Cell>()); - for (int column = 0; column < 3; column++) { - Cell cell = new Cell(((int) (Math.random() + 0.5)) == 1, row, column); - cell.isRevealed = ((int) (Math.random() + 0.5)) == 1; - - board.get(row).add(cell); - } - } - System.out.println(board); -// for (Cell tmp : cells) -// System.out.println(tmp); - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v1/TestArrayListOfCell2.java b/CCI_Java/CCI_Java/src/tp5/v1/TestArrayListOfCell2.java deleted file mode 100644 index 8b4a175..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/TestArrayListOfCell2.java +++ /dev/null @@ -1,30 +0,0 @@ -package tp5.v1; - -import java.util.ArrayList; - -public class TestArrayListOfCell2 { - - public static void main(String[] args) { - Cell cell0 = new Cell(false, 1, 1); - Cell cell1 = new Cell(true, 1, 1); - Cell cell2 = new Cell(false, 1, 1); - Cell cell3 = new Cell(true, 1, 1); - - cell2.setRevealed(true); - cell3.setRevealed(true); - - ArrayList<Cell> cells = new ArrayList<Cell>(); - - for (int column = 0; column < 4; column++) { - - Cell cell = new Cell(((int) (Math.random() + 0.5)) == 1, 1, 1); - cell.isRevealed = ((int) (Math.random() + 0.5)) == 1; - cells.add(cell); - } - System.out.println(cells); -// for (Cell tmp : cells) -// System.out.println(tmp); - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v1/TestCell.java b/CCI_Java/CCI_Java/src/tp5/v1/TestCell.java deleted file mode 100644 index 94f9b0f..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v1/TestCell.java +++ /dev/null @@ -1,17 +0,0 @@ -package tp5.v1; - -public class TestCell { - - public static void main(String[] args) { - Cell cell0 = new Cell(false, 1, 1); - Cell cell1 = new Cell(true, 1, 1); - Cell cell2 = new Cell(false, 1, 1); - Cell cell3 = new Cell(true, 1, 1); - - cell2.setRevealed(true); - cell3.setRevealed(true); - System.out.println(cell0.toString() + cell1 + cell2 + cell3); - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v2/Cell.java b/CCI_Java/CCI_Java/src/tp5/v2/Cell.java deleted file mode 100644 index c4fbeed..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/Cell.java +++ /dev/null @@ -1,85 +0,0 @@ -package tp5.v2; - -import java.awt.Color; - -public class Cell { - boolean isRevealed; - boolean isMine; - boolean isSelected; - Color color; - int row; - int column; - boolean active; - - public Cell(boolean isMine, int row, int column) { - this.isRevealed = false; - this.isSelected = false; - this.color = Color.GRAY; - this.isMine = isMine; - this.row = row; - this.column = column; - this.active = true; - } - - private void refreshColor() { - - if (this.isSelected) - this.color = Color.RED; - else if (!this.isRevealed) - this.color = Color.DARK_GRAY; - else if (!this.isRevealed) - this.color = Color.lightGray; - } - - public void setSelected(boolean isSelected) { - this.isSelected = isSelected; - } - - public void setRevealed(boolean status) { - this.isRevealed = status; - this.active = false; - - if (status && !this.isMine) - this.color = Color.DARK_GRAY; - } - - public void setMine(boolean isMine) { - this.isMine = isMine; - } - - public boolean getIsSelected() { - return isSelected; - } - - public Color getColor() { - if (active) - refreshColor(); - return color; - } - - public void setColor(Color color) { - this.color = color; - } - - public boolean isRevealed() { - return isRevealed; - } - - public boolean getIsMine() { - return isMine; - } - - public void setActive(boolean active) { - this.active = active; - } - - @Override - public String toString() { - if(!isRevealed) - return "C"; - else if (isMine) - return "B"; - return "V"; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v2/MainGui.java b/CCI_Java/CCI_Java/src/tp5/v2/MainGui.java deleted file mode 100644 index 0f4a8bf..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/MainGui.java +++ /dev/null @@ -1,7 +0,0 @@ -package tp5.v2; - -public class MainGui { - public static void main(String[] args) { - new MinesweeperFrame(); - } -} diff --git a/CCI_Java/CCI_Java/src/tp5/v2/Minesweeper.java b/CCI_Java/CCI_Java/src/tp5/v2/Minesweeper.java deleted file mode 100644 index 700f26e..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/Minesweeper.java +++ /dev/null @@ -1,57 +0,0 @@ -package tp5.v2; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class Minesweeper { - int nbColumns; - int nbLines; - int score; - int selectedLine; - int selectedColumn; - - double difficulte = 0.25; - Color colorSweeper = Color.RED; - - ArrayList<List<Cell>> board; - - public Minesweeper() { - this.nbColumns = 10; - this.nbLines = 10; - this.score = this.nbColumns * this.nbLines; - this.selectedLine = 0; - this.selectedColumn = 0; - this.board = new ArrayList<List<Cell>>(); - - - for (int row = 0; row < this.nbLines; row++) { - this.board.add(new ArrayList<Cell>()); - for (int column = 0; column < this.nbColumns; column++) { - boolean isMine = ((int) (Math.random() + difficulte)) == 1; - Cell cell = new Cell(isMine, row, column); - if (isMine) - score--; - this.board.get(row).add(cell); - } - } - } - - public double getDifficulte() { - return difficulte; - } - - public void setDifficulte(double difficulte) { - this.difficulte = difficulte; - } - - public Color getColorSweeper() { - return colorSweeper; - } - - public void setColorSweeper(Color color) { - this.colorSweeper = color; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v2/MinesweeperFrame.java b/CCI_Java/CCI_Java/src/tp5/v2/MinesweeperFrame.java deleted file mode 100644 index 542c867..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/MinesweeperFrame.java +++ /dev/null @@ -1,71 +0,0 @@ -package tp5.v2; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.WindowConstants; - -@SuppressWarnings("serial") -public class MinesweeperFrame extends JFrame { - Minesweeper minesweeper; - MinesweeperPanel minesweeperPanel; - static JMenuBar mb; - - static JMenu menu, size, difficulte, color; - -// static JMenuItem size, difficulte, color; - static JMenuItem size1, size2, size3, diff1, diff2, diff3, color1, color2, color3 ; - static JFrame f; - - public MinesweeperFrame() { - - mb = new JMenuBar(); - - - menu = new JMenu("menu"); - size = new JMenu("size in pixel"); - difficulte = new JMenu("Mines/no mines"); - color = new JMenu("Color"); - - size1 = new JMenuItem("500"); - size2 = new JMenuItem("700"); - size3 = new JMenuItem("1000"); - - size.add(size1); - size.add(size2); - size.add(size3); - - diff1 = new JMenuItem("50/50"); - diff2 = new JMenuItem("25/75"); - diff3 = new JMenuItem("75/25"); - - difficulte.add(diff1); - difficulte.add(diff2); - difficulte.add(diff3); - - color1 = new JMenuItem("red"); - color2 = new JMenuItem("blue"); - color3 = new JMenuItem("black"); - - color.add(color1); - color.add(color2); - color.add(color3); - - menu.add(size); - menu.add(difficulte); - menu.add(color); - - mb.add(menu); - setJMenuBar(mb); - this.minesweeper = new Minesweeper(); - - this.minesweeperPanel = new MinesweeperPanel(minesweeper); - add(minesweeperPanel); - - pack(); - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setVisible(true); - - } -} \ No newline at end of file diff --git a/CCI_Java/CCI_Java/src/tp5/v2/MinesweeperPanel.java b/CCI_Java/CCI_Java/src/tp5/v2/MinesweeperPanel.java deleted file mode 100644 index 0b330ee..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/MinesweeperPanel.java +++ /dev/null @@ -1,195 +0,0 @@ -package tp5.v2; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.event.MouseEvent; -import java.util.Scanner; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanel extends JPanel implements MinesweeperPanelable { - Minesweeper minesweeper; - int spaceHor; - int spaceVert; - int nbColumns; - int nbRows; - int selCol; - int selLine; - int carreWidth; - int carreHeight; - int spaceBorder; - - static JMenuBar mb; - - static JMenu menu; - - static JMenuItem size, difficulte, color; - - static JFrame f; - - public MinesweeperPanel(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - addMouseListener(new PanelMouseListener(this)); - addMouseMotionListener(new PanelMouseListener(this)); - spaceBorder = 20; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - this.nbColumns = this.minesweeper.nbColumns; - this.nbRows = this.minesweeper.nbLines; - - this.carreWidth = (getWidth() - (getBoardBorder() * 2)) - ((getWidth() - (getBoardBorder() * 2)) % nbColumns); - this.carreHeight = (getHeight() - (getBoardBorder() * 2)) - ((getHeight() - (getBoardBorder() * 2)) % nbRows); - - this.spaceHor = carreWidth / nbColumns; - this.spaceVert = carreHeight / nbRows; - - int lineEndH = carreHeight + getBoardBorder(); - int lineEndV = carreWidth + getBoardBorder(); - - for (int idxRow = 0; idxRow < this.minesweeper.board.size(); idxRow++) { - for (int idxCol = 0; idxCol < this.minesweeper.board.get(idxRow).size(); idxCol++) { - Cell tmp = this.minesweeper.board.get(idxRow).get(idxCol); -// drawCell(g, idxRow, idxCol); - drawCell(g, tmp); - tmp.setSelected(false); - } - } - - // show score - g.setColor(Color.darkGray); - g.setFont(new Font("Ariel", Font.BOLD, spaceBorder - 3)); - g.drawString("Score : " + this.minesweeper.score, (getWidth() / 2) - 40, (spaceBorder - 3)); - - } - - public void drawCell(Graphics g, int line, int column) { - - g.setColor(Color.BLACK); - g.drawRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - Cell tmp = this.minesweeper.board.get(line).get(column); - g.setColor(tmp.getColor()); - g.fillRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - - if (tmp.isRevealed && tmp.isMine) { - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(getCellX(column) + (getCellWidth() / 2) - (sizeBomb / 2), - getCellX(line) + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } - } - - public void drawCell(Graphics g, Cell tmp) { - - g.setColor(Color.BLACK); - g.drawRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - - - - - if (tmp.isSelected) { - g.setColor(Color.RED); - g.fillRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - } else if (tmp.toString().equals("B")) { - g.setColor(Color.RED); - g.fillRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - g.setColor(Color.WHITE); - g.drawRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(getCellX(tmp.column) + (getCellWidth() / 2) - (sizeBomb / 2), - getCellX(tmp.row) + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } else if (tmp.toString().equals("C")) { - g.setColor(Color.DARK_GRAY); - g.fillRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - } else { - g.setColor(Color.GRAY); - g.fillRect(getCellX(tmp.column), getCellY(tmp.row), getCellWidth(), getCellHeight()); - } - } - - public int getColumn(int x) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - if (condX) { - int posCarre = x - getBoardBorder(); - this.selCol = posCarre / getCellWidth(); - return this.selCol; - } - return -1; - } - - public int getLine(int y) { - - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condY) { - int posCarre = y - getBoardBorder(); - this.selLine = posCarre / spaceVert; - return this.selLine; - } - return -1; - - } - - public int getBoardBorder() { - return this.spaceBorder; - } - - @Override - public boolean isBlackCell(int line, int column) { - return this.minesweeper.board.get(line).get(column).getColor() == Color.DARK_GRAY; - } - - @Override - public boolean isGrayCell(int line, int column) { - return this.minesweeper.board.get(line).get(column).getColor() == Color.GRAY; - } - - public boolean isRedCell(int line, int column) { - return this.minesweeper.board.get(line).get(column).getColor() == Color.RED; - } - - boolean isMine(int line, int column) { - return this.minesweeper.board.get(line).get(column).isMine; - } - - public int getCellX(int column) { - return (getBoardBorder() + (column * getCellWidth())); - } - - public int getCellY(int line) { - return (getBoardBorder() + (line * getCellHeight())); - } - - public int getCellWidth() { - return this.spaceHor; - } - - public int getCellHeight() { - return this.spaceVert; - } - - public boolean isOutOfBounds(int x, int y) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condX && condY) - return true; - return false; - } - - @Override - public void drawMinesweeper(Graphics g) { - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v2/MinesweeperPanelable.java b/CCI_Java/CCI_Java/src/tp5/v2/MinesweeperPanelable.java deleted file mode 100644 index 74a930c..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/MinesweeperPanelable.java +++ /dev/null @@ -1,20 +0,0 @@ -package tp5.v2; - -import java.awt.Graphics; - -public interface MinesweeperPanelable { - - public int getBoardBorder(); - public boolean isBlackCell(int line, int column); - public boolean isGrayCell(int line, int column); - public boolean isRedCell(int line, int column); - public int getCellX(int column); - public int getCellY(int line); - public int getCellWidth(); - public int getCellHeight(); - public void drawCell(Graphics g, int line, int column); - public int getColumn(int x); - public int getLine(int y); - void drawMinesweeper(Graphics g); - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v2/PanelMouseListener.java b/CCI_Java/CCI_Java/src/tp5/v2/PanelMouseListener.java deleted file mode 100644 index 73f993c..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/PanelMouseListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package tp5.v2; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -public class PanelMouseListener extends MouseAdapter { - MinesweeperPanel panel; - - public PanelMouseListener(MinesweeperPanel panel) { - this.panel = panel; - } - - @Override - public void mouseClicked(MouseEvent e) { - -// System.out.println("Click Line = " + panel.minesweeper.selectedLine); -// System.out.println("Click Column = " + panel.minesweeper.selectedColumn); - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - Cell tmpCell = panel.minesweeper.board.get(line).get(column); - tmpCell.isRevealed = true; - if (!tmpCell.isMine) - panel.minesweeper.score--; - -// panel.minesweeper.score--; - panel.repaint(); - } - - @Override - public void mouseMoved(MouseEvent e) { - -// panel.minesweeper.selectedLine = panel.getLine(e.getY()); -// panel.minesweeper.selectedColumn = panel.getColumn(e.getX()); - - try { - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - if (!panel.isOutOfBounds(line, column)) { - panel.minesweeper.board.get(line).get(column).setSelected(true); - panel.repaint(); - } - } catch (Exception e2) { - // TODO: handle exception -// e2.printStackTrace(); - } - - - } -} diff --git a/CCI_Java/CCI_Java/src/tp5/v2/TestArrayListOfCell.java b/CCI_Java/CCI_Java/src/tp5/v2/TestArrayListOfCell.java deleted file mode 100644 index 50f95fd..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/TestArrayListOfCell.java +++ /dev/null @@ -1,42 +0,0 @@ -package tp5.v2; - -import java.util.ArrayList; - -public class TestArrayListOfCell { - - public static void main(String[] args) { - Cell cell0 = new Cell(false, 1, 1); - Cell cell1 = new Cell(true, 1, 1); - Cell cell2 = new Cell(false, 1, 1); - Cell cell3 = new Cell(true, 1, 1); - - cell2.setRevealed(true); - cell3.setRevealed(true); - -// ArrayList<Cell> cells = new ArrayList<Cell>(); - ArrayList<ArrayList<Cell>> board = new ArrayList<ArrayList<Cell>>(); - - for (int column = 0; column < 4; column++) { - - Cell cell = new Cell(((int) (Math.random() + 0.5)) == 1, 1, 1); - cell.isRevealed = ((int) (Math.random() + 0.5)) == 1; - - } - - - for (int row = 0; row < 2; row++) { - board.add(new ArrayList<Cell>()); - for (int column = 0; column < 3; column++) { - Cell cell = new Cell(((int) (Math.random() + 0.5)) == 1, row, column); - cell.isRevealed = ((int) (Math.random() + 0.5)) == 1; - - board.get(row).add(cell); - } - } - System.out.println(board); -// for (Cell tmp : cells) -// System.out.println(tmp); - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v2/TestArrayListOfCell2.java b/CCI_Java/CCI_Java/src/tp5/v2/TestArrayListOfCell2.java deleted file mode 100644 index 48e2f62..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/TestArrayListOfCell2.java +++ /dev/null @@ -1,30 +0,0 @@ -package tp5.v2; - -import java.util.ArrayList; - -public class TestArrayListOfCell2 { - - public static void main(String[] args) { - Cell cell0 = new Cell(false, 1, 1); - Cell cell1 = new Cell(true, 1, 1); - Cell cell2 = new Cell(false, 1, 1); - Cell cell3 = new Cell(true, 1, 1); - - cell2.setRevealed(true); - cell3.setRevealed(true); - - ArrayList<Cell> cells = new ArrayList<Cell>(); - - for (int column = 0; column < 4; column++) { - - Cell cell = new Cell(((int) (Math.random() + 0.5)) == 1, 1, 1); - cell.isRevealed = ((int) (Math.random() + 0.5)) == 1; - cells.add(cell); - } - System.out.println(cells); -// for (Cell tmp : cells) -// System.out.println(tmp); - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp5/v2/TestCell.java b/CCI_Java/CCI_Java/src/tp5/v2/TestCell.java deleted file mode 100644 index d0d763f..0000000 --- a/CCI_Java/CCI_Java/src/tp5/v2/TestCell.java +++ /dev/null @@ -1,17 +0,0 @@ -package tp5.v2; - -public class TestCell { - - public static void main(String[] args) { - Cell cell0 = new Cell(false, 1, 1); - Cell cell1 = new Cell(true, 1, 1); - Cell cell2 = new Cell(false, 1, 1); - Cell cell3 = new Cell(true, 1, 1); - - cell2.setRevealed(true); - cell3.setRevealed(true); - System.out.println(cell0.toString() + cell1 + cell2 + cell3); - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v1/Cell.java b/CCI_Java/CCI_Java/src/tp6/v1/Cell.java deleted file mode 100644 index 495b294..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v1/Cell.java +++ /dev/null @@ -1,102 +0,0 @@ -package tp6.v1; - -import java.awt.Color; - -public class Cell { - private boolean isRevealed; - private boolean isMine; - boolean isSelected; - Color color; - private int row; - private int column; - private boolean active; - - public Cell(boolean isMine, int row, int column) { - this.isRevealed = false; - this.isSelected = false; - this.color = Color.GRAY; - this.isMine = isMine; - this.row = row; - this.column = column; - this.active = true; - } - - private void refreshColor() { - - if (this.isSelected) - this.color = Color.RED; - else if (!this.isRevealed) - this.color = Color.DARK_GRAY; - else if (!this.isRevealed) - this.color = Color.lightGray; - } - - public void setSelected(boolean isSelected) { - this.isSelected = isSelected; - } - - public void setRevealed(boolean status) { - this.isRevealed = status; - this.active = false; - - if (status && !this.isMine) - this.color = Color.DARK_GRAY; - } - - public void reveal() { - this.isRevealed = true; - } - - public boolean getIsRevealed() { - return isRevealed; - } - - public void setMine(boolean isMine) { - this.isMine = isMine; - } - - public boolean getIsSelected() { - return isSelected; - } - - public Color getColor() { - if (!isRevealed) - refreshColor(); - return color; - } - - public void setColor(Color color) { - this.color = color; - } - - public boolean isRevealed() { - return isRevealed; - } - - public boolean getIsMine() { - return isMine; - } - - public void setActive(boolean active) { - this.active = active; - } - - public int getColumn() { - return column; - } - - public int getRow() { - return row; - } - - @Override - public String toString() { - if(!isRevealed) - return "C"; - else if (isMine) - return "B"; - return "V"; - } - - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v1/MainGui.java b/CCI_Java/CCI_Java/src/tp6/v1/MainGui.java deleted file mode 100644 index b123416..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v1/MainGui.java +++ /dev/null @@ -1,7 +0,0 @@ -package tp6.v1; - -public class MainGui { - public static void main(String[] args) { - new MinesweeperFrame(); - } -} diff --git a/CCI_Java/CCI_Java/src/tp6/v1/Minesweeper.java b/CCI_Java/CCI_Java/src/tp6/v1/Minesweeper.java deleted file mode 100644 index 6c63c35..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v1/Minesweeper.java +++ /dev/null @@ -1,53 +0,0 @@ -package tp6.v1; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class Minesweeper { - int nbColumns; - int nbLines; - int score; - - double difficulte = 0.25; - Color colorSweeper = Color.RED; - - ArrayList<List<Cell>> board; - - public Minesweeper() { - this.nbColumns = 10; - this.nbLines = 10; - this.score = this.nbColumns * this.nbLines; - this.board = new ArrayList<List<Cell>>(); - - - for (int row = 0; row < this.nbLines; row++) { - this.board.add(new ArrayList<Cell>()); - for (int column = 0; column < this.nbColumns; column++) { - boolean isMine = ((int) (Math.random() + difficulte)) == 1; - Cell cell = new Cell(isMine, row, column); - if (isMine) - score--; - this.board.get(row).add(cell); - } - } - } - - public double getDifficulte() { - return difficulte; - } - - public void setDifficulte(double difficulte) { - this.difficulte = difficulte; - } - - public Color getColorSweeper() { - return colorSweeper; - } - - public void setColorSweeper(Color color) { - this.colorSweeper = color; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v1/MinesweeperFrame.java b/CCI_Java/CCI_Java/src/tp6/v1/MinesweeperFrame.java deleted file mode 100644 index 576161c..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v1/MinesweeperFrame.java +++ /dev/null @@ -1,71 +0,0 @@ -package tp6.v1; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.WindowConstants; - -@SuppressWarnings("serial") -public class MinesweeperFrame extends JFrame { - Minesweeper minesweeper; - MinesweeperPanel minesweeperPanel; - static JMenuBar mb; - - static JMenu menu, size, difficulte, color; - -// static JMenuItem size, difficulte, color; - static JMenuItem size1, size2, size3, diff1, diff2, diff3, color1, color2, color3 ; - static JFrame f; - - public MinesweeperFrame() { - - mb = new JMenuBar(); - - - menu = new JMenu("menu"); - size = new JMenu("size in pixel"); - difficulte = new JMenu("Mines/no mines"); - color = new JMenu("Color"); - - size1 = new JMenuItem("500"); - size2 = new JMenuItem("700"); - size3 = new JMenuItem("1000"); - - size.add(size1); - size.add(size2); - size.add(size3); - - diff1 = new JMenuItem("50/50"); - diff2 = new JMenuItem("25/75"); - diff3 = new JMenuItem("75/25"); - - difficulte.add(diff1); - difficulte.add(diff2); - difficulte.add(diff3); - - color1 = new JMenuItem("red"); - color2 = new JMenuItem("blue"); - color3 = new JMenuItem("black"); - - color.add(color1); - color.add(color2); - color.add(color3); - - menu.add(size); - menu.add(difficulte); - menu.add(color); - - mb.add(menu); - setJMenuBar(mb); - this.minesweeper = new Minesweeper(); - - this.minesweeperPanel = new MinesweeperPanel(minesweeper); - add(minesweeperPanel); - - pack(); - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setVisible(true); - - } -} \ No newline at end of file diff --git a/CCI_Java/CCI_Java/src/tp6/v1/MinesweeperPanel.java b/CCI_Java/CCI_Java/src/tp6/v1/MinesweeperPanel.java deleted file mode 100644 index 026bf64..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v1/MinesweeperPanel.java +++ /dev/null @@ -1,183 +0,0 @@ -package tp6.v1; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.event.MouseEvent; -import java.util.Scanner; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanel extends JPanel implements MinesweeperPanelable { - Minesweeper minesweeper; - int spaceHor; - int spaceVert; - int nbColumns; - int nbRows; - int selCol; - int selLine; - int carreWidth; - int carreHeight; - int spaceBorder; - - static JMenuBar mb; - - static JMenu menu; - - static JMenuItem size, difficulte, color; - - static JFrame f; - - public MinesweeperPanel(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - addMouseListener(new PanelMouseListener(this)); - addMouseMotionListener(new PanelMouseListener(this)); - spaceBorder = 20; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - this.nbColumns = this.minesweeper.nbColumns; - this.nbRows = this.minesweeper.nbLines; - - this.carreWidth = (getWidth() - (getBoardBorder() * 2)) - ((getWidth() - (getBoardBorder() * 2)) % nbColumns); - this.carreHeight = (getHeight() - (getBoardBorder() * 2)) - ((getHeight() - (getBoardBorder() * 2)) % nbRows); - - this.spaceHor = carreWidth / nbColumns; - this.spaceVert = carreHeight / nbRows; - - int lineEndH = carreHeight + getBoardBorder(); - int lineEndV = carreWidth + getBoardBorder(); - - for (int idxRow = 0; idxRow < this.minesweeper.board.size(); idxRow++) { - for (int idxCol = 0; idxCol < this.minesweeper.board.get(idxRow).size(); idxCol++) { - Cell tmp = this.minesweeper.board.get(idxRow).get(idxCol); -// drawCell(g, idxRow, idxCol); - drawCell(g, tmp); - tmp.setSelected(false); - } - } - - // show score - g.setColor(Color.darkGray); - g.setFont(new Font("Ariel", Font.BOLD, spaceBorder - 3)); - g.drawString("Score : " + this.minesweeper.score, (getWidth() / 2) - 40, (spaceBorder - 3)); - - } - - public void drawCell(Graphics g, int line, int column) { - - g.setColor(Color.BLACK); - g.drawRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - Cell tmp = this.minesweeper.board.get(line).get(column); - g.setColor(tmp.getColor()); - g.fillRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - - if (tmp.getIsRevealed() && tmp.getIsMine()) { - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(getCellX(column) + (getCellWidth() / 2) - (sizeBomb / 2), - getCellX(line) + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } - } - - public void drawCell(Graphics g, Cell tmp) { - - g.setColor(Color.BLACK); - int xTmp = getCellX(tmp.getColumn()); - int yTmp = getCellY(tmp.getRow()); - g.drawRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - - - - - if (tmp.isSelected) { - g.setColor(Color.RED); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - } else if (tmp.toString().equals("B")) { - g.setColor(Color.RED); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - g.setColor(Color.WHITE); - g.drawRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(xTmp + (getCellWidth() / 2) - (sizeBomb / 2), - yTmp + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } else if (tmp.toString().equals("C")) { - g.setColor(Color.DARK_GRAY); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - } else { - g.setColor(Color.GRAY); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - } - } - - public int getColumn(int x) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - if (condX) { - int posCarre = x - getBoardBorder(); - this.selCol = posCarre / getCellWidth(); - return this.selCol; - } - return -1; - } - - public int getLine(int y) { - - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condY) { - int posCarre = y - getBoardBorder(); - this.selLine = posCarre / spaceVert; - return this.selLine; - } - return -1; - - } - - public int getBoardBorder() { - return this.spaceBorder; - } - - boolean isMine(int line, int column) { - return this.minesweeper.board.get(line).get(column).getIsMine(); - } - - public int getCellX(int column) { - return (getBoardBorder() + (column * getCellWidth())); - } - - public int getCellY(int line) { - return (getBoardBorder() + (line * getCellHeight())); - } - - public int getCellWidth() { - return this.spaceHor; - } - - public int getCellHeight() { - return this.spaceVert; - } - - public boolean isOutOfBounds(int x, int y) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condX && condY) - return true; - return false; - } - - @Override - public void drawMinesweeper(Graphics g) { - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v1/MinesweeperPanelable.java b/CCI_Java/CCI_Java/src/tp6/v1/MinesweeperPanelable.java deleted file mode 100644 index 8078ab9..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v1/MinesweeperPanelable.java +++ /dev/null @@ -1,17 +0,0 @@ -package tp6.v1; - -import java.awt.Graphics; - -public interface MinesweeperPanelable { - - public int getBoardBorder(); - public int getCellX(int column); - public int getCellY(int line); - public int getCellWidth(); - public int getCellHeight(); - public void drawCell(Graphics g, int line, int column); - public int getColumn(int x); - public int getLine(int y); - void drawMinesweeper(Graphics g); - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v1/PanelMouseListener.java b/CCI_Java/CCI_Java/src/tp6/v1/PanelMouseListener.java deleted file mode 100644 index 72edd64..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v1/PanelMouseListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package tp6.v1; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -public class PanelMouseListener extends MouseAdapter { - MinesweeperPanel panel; - - public PanelMouseListener(MinesweeperPanel panel) { - this.panel = panel; - } - - @Override - public void mouseClicked(MouseEvent e) { - -// System.out.println("Click Line = " + panel.minesweeper.selectedLine); -// System.out.println("Click Column = " + panel.minesweeper.selectedColumn); - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - Cell tmpCell = panel.minesweeper.board.get(line).get(column); - tmpCell.reveal(); - if (!tmpCell.getIsMine()) - panel.minesweeper.score--; - -// panel.minesweeper.score--; - panel.repaint(); - } - - @Override - public void mouseMoved(MouseEvent e) { - -// panel.minesweeper.selectedLine = panel.getLine(e.getY()); -// panel.minesweeper.selectedColumn = panel.getColumn(e.getX()); - - try { - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - if (!panel.isOutOfBounds(line, column)) { - panel.minesweeper.board.get(line).get(column).setSelected(true); - panel.repaint(); - } - } catch (Exception e2) { - // TODO: handle exception -// e2.printStackTrace(); - } - - - } -} diff --git a/CCI_Java/CCI_Java/src/tp6/v2/Cell.java b/CCI_Java/CCI_Java/src/tp6/v2/Cell.java deleted file mode 100644 index e69f6af..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v2/Cell.java +++ /dev/null @@ -1,102 +0,0 @@ -package tp6.v2; - -import java.awt.Color; - -public class Cell { - private boolean isRevealed; - private boolean isMine; - boolean isSelected; - Color color; - private int row; - private int column; - private boolean active; - - public Cell(boolean isMine, int row, int column) { - this.isRevealed = false; - this.isSelected = false; - this.color = Color.GRAY; - this.isMine = isMine; - this.row = row; - this.column = column; - this.active = true; - } - - private void refreshColor() { - - if (this.isSelected) - this.color = Color.RED; - else if (!this.isRevealed) - this.color = Color.DARK_GRAY; - else if (!this.isRevealed) - this.color = Color.lightGray; - } - - public void setSelected(boolean isSelected) { - this.isSelected = isSelected; - } - - public void setRevealed(boolean status) { - this.isRevealed = status; - this.active = false; - - if (status && !this.isMine) - this.color = Color.DARK_GRAY; - } - - public void reveal() { - this.isRevealed = true; - } - - public boolean getIsRevealed() { - return isRevealed; - } - - public void setMine(boolean isMine) { - this.isMine = isMine; - } - - public boolean getIsSelected() { - return isSelected; - } - - public Color getColor() { - if (!isRevealed) - refreshColor(); - return color; - } - - public void setColor(Color color) { - this.color = color; - } - - public boolean isRevealed() { - return isRevealed; - } - - public boolean getIsMine() { - return isMine; - } - - public void setActive(boolean active) { - this.active = active; - } - - public int getColumn() { - return column; - } - - public int getRow() { - return row; - } - - @Override - public String toString() { - if(!isRevealed) - return "C"; - else if (isMine) - return "B"; - return "V"; - } - - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v2/MainGui.java b/CCI_Java/CCI_Java/src/tp6/v2/MainGui.java deleted file mode 100644 index 9d75d4b..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v2/MainGui.java +++ /dev/null @@ -1,7 +0,0 @@ -package tp6.v2; - -public class MainGui { - public static void main(String[] args) { - new MinesweeperFrame(); - } -} diff --git a/CCI_Java/CCI_Java/src/tp6/v2/Minesweeper.java b/CCI_Java/CCI_Java/src/tp6/v2/Minesweeper.java deleted file mode 100644 index e483450..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v2/Minesweeper.java +++ /dev/null @@ -1,102 +0,0 @@ -package tp6.v2; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class Minesweeper { - private int nbColumns; - private int nbLines; - private int score; - - double difficulte = 0.33; - Color colorSweeper = Color.RED; - - private ArrayList<List<Cell>> board; - - public Minesweeper() { - this.nbColumns = 10; - this.nbLines = 10; - this.score = 0; - this.board = new ArrayList<List<Cell>>(); - - for (int row = 0; row < this.nbLines; row++) { - this.board.add(new ArrayList<Cell>()); - for (int column = 0; column < this.nbColumns; column++) { - boolean isMine = ((int) (Math.random() + difficulte)) == 1; - Cell cell = new Cell(isMine, row, column); - this.board.get(row).add(cell); - } - } - } - - public double getDifficulte() { - return difficulte; - } - - public void setDifficulte(double difficulte) { - this.difficulte = difficulte; - } - - public Color getColorSweeper() { - return colorSweeper; - } - - public void setColorSweeper(Color color) { - this.colorSweeper = color; - } - - public int getNbColumns() { - return nbColumns; - } - - public int getNbLines() { - return nbLines; - } - - public int getScore() { - return score; - } - - public void increaseScore() { - score++; - } - - public boolean isRevealed(int line, int column) { -// if (isValidPositionLC(line, column)) - return board.get(line).get(column).getIsRevealed(); -// return false; - } - - public boolean isMine(int line, int column) { -// if (isValidPositionLC(line, column)) - return board.get(line).get(column).getIsMine(); -// return false; - } - - public void reveal(int line, int column) { - board.get(line).get(column).reveal(); - } - - public Cell getCell(int line, int column) { - return board.get(line).get(column); - } - - public void select(int line, int column) { - board.get(line).get(column).setSelected(true); - } - - public void deselect(int line, int column) { - board.get(line).get(column).setSelected(false); - } - - public boolean isValidPositionLC(int line, int column) { - boolean lineCheck = line <= nbLines && line > 0; - boolean columnCheck = column <= nbColumns && column > 0; - if (lineCheck && columnCheck) - return true; - return false; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v2/MinesweeperFrame.java b/CCI_Java/CCI_Java/src/tp6/v2/MinesweeperFrame.java deleted file mode 100644 index 9640fab..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v2/MinesweeperFrame.java +++ /dev/null @@ -1,71 +0,0 @@ -package tp6.v2; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.WindowConstants; - -@SuppressWarnings("serial") -public class MinesweeperFrame extends JFrame { - Minesweeper minesweeper; - MinesweeperPanel minesweeperPanel; - static JMenuBar mb; - - static JMenu menu, size, difficulte, color; - -// static JMenuItem size, difficulte, color; - static JMenuItem size1, size2, size3, diff1, diff2, diff3, color1, color2, color3 ; - static JFrame f; - - public MinesweeperFrame() { - - mb = new JMenuBar(); - - - menu = new JMenu("menu"); - size = new JMenu("size in pixel"); - difficulte = new JMenu("Mines/no mines"); - color = new JMenu("Color"); - - size1 = new JMenuItem("500"); - size2 = new JMenuItem("700"); - size3 = new JMenuItem("1000"); - - size.add(size1); - size.add(size2); - size.add(size3); - - diff1 = new JMenuItem("50/50"); - diff2 = new JMenuItem("25/75"); - diff3 = new JMenuItem("75/25"); - - difficulte.add(diff1); - difficulte.add(diff2); - difficulte.add(diff3); - - color1 = new JMenuItem("red"); - color2 = new JMenuItem("blue"); - color3 = new JMenuItem("black"); - - color.add(color1); - color.add(color2); - color.add(color3); - - menu.add(size); - menu.add(difficulte); - menu.add(color); - - mb.add(menu); - setJMenuBar(mb); - this.minesweeper = new Minesweeper(); - - this.minesweeperPanel = new MinesweeperPanel(minesweeper); - add(minesweeperPanel); - - pack(); - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setVisible(true); - - } -} \ No newline at end of file diff --git a/CCI_Java/CCI_Java/src/tp6/v2/MinesweeperPanel.java b/CCI_Java/CCI_Java/src/tp6/v2/MinesweeperPanel.java deleted file mode 100644 index 9c7f0ea..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v2/MinesweeperPanel.java +++ /dev/null @@ -1,183 +0,0 @@ -package tp6.v2; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.event.MouseEvent; -import java.util.Scanner; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanel extends JPanel implements MinesweeperPanelable { - Minesweeper minesweeper; - int spaceHor; - int spaceVert; - int nbColumns; - int nbRows; - int selCol; - int selLine; - int carreWidth; - int carreHeight; - int spaceBorder; - - static JMenuBar mb; - - static JMenu menu; - - static JMenuItem size, difficulte, color; - - static JFrame f; - - public MinesweeperPanel(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - addMouseListener(new PanelMouseListener(this)); - addMouseMotionListener(new PanelMouseListener(this)); - spaceBorder = 20; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - this.nbColumns = this.minesweeper.getNbColumns(); - this.nbRows = this.minesweeper.getNbLines(); - - this.carreWidth = (getWidth() - (getBoardBorder() * 2)) - ((getWidth() - (getBoardBorder() * 2)) % nbColumns); - this.carreHeight = (getHeight() - (getBoardBorder() * 2)) - ((getHeight() - (getBoardBorder() * 2)) % nbRows); - - this.spaceHor = carreWidth / nbColumns; - this.spaceVert = carreHeight / nbRows; - - int lineEndH = carreHeight + getBoardBorder(); - int lineEndV = carreWidth + getBoardBorder(); - - for (int idxRow = 0; idxRow < this.minesweeper.getNbLines(); idxRow++) { - for (int idxCol = 0; idxCol < this.minesweeper.getNbColumns(); idxCol++) { - Cell tmp = this.minesweeper.getCell(idxRow, idxCol); -// drawCell(g, idxRow, idxCol); - drawCell(g, tmp); - tmp.setSelected(false); - } - } - - // show score - g.setColor(Color.darkGray); - g.setFont(new Font("Ariel", Font.BOLD, spaceBorder - 3)); - g.drawString("Score : " + this.minesweeper.getScore(), (getWidth() / 2) - 40, (spaceBorder - 3)); - - } - - public void drawCell(Graphics g, int line, int column) { - - g.setColor(Color.BLACK); - g.drawRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - Cell tmp = this.minesweeper.getCell(line, column); - g.setColor(tmp.getColor()); - g.fillRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); - - if (tmp.getIsRevealed() && tmp.getIsMine()) { - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(getCellX(column) + (getCellWidth() / 2) - (sizeBomb / 2), - getCellX(line) + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } - } - - public void drawCell(Graphics g, Cell tmp) { - - g.setColor(Color.BLACK); - int xTmp = getCellX(tmp.getColumn()); - int yTmp = getCellY(tmp.getRow()); - g.drawRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - - - - - if (tmp.isSelected) { - g.setColor(Color.RED); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - } else if (tmp.toString().equals("B")) { - g.setColor(Color.RED); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - g.setColor(Color.WHITE); - g.drawRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - int sizeBomb = 25; - g.setColor(Color.BLACK); - g.fillOval(xTmp + (getCellWidth() / 2) - (sizeBomb / 2), - yTmp + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); - } else if (tmp.toString().equals("C")) { - g.setColor(Color.DARK_GRAY); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - } else { - g.setColor(Color.GRAY); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - } - } - - public int getColumn(int x) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - if (condX) { - int posCarre = x - getBoardBorder(); - this.selCol = posCarre / getCellWidth(); - return this.selCol; - } - return -1; - } - - public int getLine(int y) { - - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condY) { - int posCarre = y - getBoardBorder(); - this.selLine = posCarre / spaceVert; - return this.selLine; - } - return -1; - - } - - public int getBoardBorder() { - return this.spaceBorder; - } - -// boolean isMine(int line, int column) { -// return this.minesweeper.isMine(line, column); -// } - - public int getCellX(int column) { - return (getBoardBorder() + (column * getCellWidth())); - } - - public int getCellY(int line) { - return (getBoardBorder() + (line * getCellHeight())); - } - - public int getCellWidth() { - return this.spaceHor; - } - - public int getCellHeight() { - return this.spaceVert; - } - - public boolean isValidPositionPx(int x, int y) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condX && condY) - return true; - return false; - } - - @Override - public void drawMinesweeper(Graphics g) { - - } - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v2/MinesweeperPanelable.java b/CCI_Java/CCI_Java/src/tp6/v2/MinesweeperPanelable.java deleted file mode 100644 index b3ff9d3..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v2/MinesweeperPanelable.java +++ /dev/null @@ -1,17 +0,0 @@ -package tp6.v2; - -import java.awt.Graphics; - -public interface MinesweeperPanelable { - - public int getBoardBorder(); - public int getCellX(int column); - public int getCellY(int line); - public int getCellWidth(); - public int getCellHeight(); - public void drawCell(Graphics g, int line, int column); - public int getColumn(int x); - public int getLine(int y); - void drawMinesweeper(Graphics g); - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v2/PanelMouseListener.java b/CCI_Java/CCI_Java/src/tp6/v2/PanelMouseListener.java deleted file mode 100644 index 7d688c3..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v2/PanelMouseListener.java +++ /dev/null @@ -1,43 +0,0 @@ -package tp6.v2; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -public class PanelMouseListener extends MouseAdapter { - MinesweeperPanel panel; - - public PanelMouseListener(MinesweeperPanel panel) { - this.panel = panel; - } - - @Override - public void mouseClicked(MouseEvent e) { - -// System.out.println("Click Line = " + panel.minesweeper.selectedLine); -// System.out.println("Click Column = " + panel.minesweeper.selectedColumn); - - if (panel.isValidPositionPx(e.getX(), e.getY())) { - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - panel.minesweeper.reveal(line, column); - if (!panel.minesweeper.isMine(line, column)) - panel.minesweeper.increaseScore(); - panel.repaint(); - } - } - - @Override - public void mouseMoved(MouseEvent e) { - -// panel.minesweeper.selectedLine = panel.getLine(e.getY()); -// panel.minesweeper.selectedColumn = panel.getColumn(e.getX()); - - if (panel.isValidPositionPx(e.getX(), e.getY())) { - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - panel.minesweeper.select(line, column); - panel.repaint(); - } - - } -} diff --git a/CCI_Java/CCI_Java/src/tp6/v3/Cell.java b/CCI_Java/CCI_Java/src/tp6/v3/Cell.java deleted file mode 100644 index 36cf46a..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v3/Cell.java +++ /dev/null @@ -1,143 +0,0 @@ -package tp6.v3; - -import java.awt.Color; -import java.util.ArrayList; - -public class Cell { - private boolean isRevealed; - private boolean isMine; - private boolean isSelected; -// Color color; - private int row; - private int column; - private boolean active; - private int nbNeighboringBombes; - private boolean isFlagged; - private ArrayList<Cell> neighbors; - - public Cell(boolean isMine, int row, int column) { - this.isRevealed = false; - this.isSelected = false; -// this.color = Color.GRAY; - this.isMine = isMine; - this.row = row; - this.column = column; - this.active = true; - this.isFlagged = false; - this.nbNeighboringBombes = 0; - this.neighbors = new ArrayList<Cell>(); - } - -// private void refreshColor() { -// -// if (this.isSelected) -// this.color = Color.RED; -// else if (!this.isRevealed) -// this.color = Color.DARK_GRAY; -// else if (!this.isRevealed) -// this.color = Color.lightGray; -// } - - public void addNeighbor(Cell cell) { - neighbors.add(cell); - if (cell.isMine) - nbNeighboringBombes++; - } - - public void setSelected(boolean isSelected) { - this.isSelected = isSelected; - } - - public void setRevealed(boolean status) { - this.isRevealed = status; - this.active = false; - -// if (status && !this.isMine) -// this.color = Color.DARK_GRAY; - - } - - public void reveal() { - this.isRevealed = true; - if(nbNeighboringBombes == 0) { - for(Cell neighbor : neighbors) { - if(!neighbor.isFlagged && !neighbor.isMine && !neighbor.isRevealed) - neighbor.reveal(); - } - } - } - - public boolean getIsRevealed() { - return isRevealed; - } - - public void setMine(boolean isMine) { - this.isMine = isMine; - } - - public void setNeighbors(int neighbors) { - this.nbNeighboringBombes = neighbors; - } - - public int getNeighbors() { - return nbNeighboringBombes; - } - - public boolean getIsSelected() { - return isSelected; - } - -// public Color getColor() { -// if (!isRevealed) -// refreshColor(); -// return color; -// } -// -// public void setColor(Color color) { -// this.color = color; -// } - - public boolean isRevealed() { - return isRevealed; - } - - public boolean getIsMine() { - return isMine; - } - - public void setActive(boolean active) { - this.active = active; - } - - public int getColumn() { - return column; - } - - public int getRow() { - return row; - } - - @Override - public String toString() { - if (isFlagged) - return "F"; - else if (!isRevealed) - return "C"; - else if (isMine) - return "B"; - return "V"; - } - - public void setFlagged(boolean isFlagged) { - this.isFlagged = isFlagged; - } - - public boolean isFlagged() { - return this.isFlagged; - } - - public boolean isSelected() { - return isSelected; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v3/MainGui.java b/CCI_Java/CCI_Java/src/tp6/v3/MainGui.java deleted file mode 100644 index 4fe44e4..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v3/MainGui.java +++ /dev/null @@ -1,7 +0,0 @@ -package tp6.v3; - -public class MainGui { - public static void main(String[] args) { - new MinesweeperFrame(); - } -} diff --git a/CCI_Java/CCI_Java/src/tp6/v3/Minesweeper.java b/CCI_Java/CCI_Java/src/tp6/v3/Minesweeper.java deleted file mode 100644 index 57bb959..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v3/Minesweeper.java +++ /dev/null @@ -1,199 +0,0 @@ -package tp6.v3; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class Minesweeper { - private int nbColumns; - private int nbLines; - private int score; - private boolean gameWin; - private boolean gameOver; - private int nbMines; - private int nbBlanks; - private int nbRevealed; - - double difficulty; - Color colorSweeper = Color.RED; - - private ArrayList<ArrayList<Cell>> board; - - public Minesweeper() { - resetGame(0.25); - - } - - public void resetGame(double difficulty) { - this.nbColumns = 15; - this.nbLines = 15; -// this.nbColumns = 3; -// this.nbLines = 3; - this.difficulty = difficulty; - this.score = 0; - - this.gameOver = false; - this.gameWin = false; - this.nbMines = 0; - this.nbRevealed = 0; - - this.board = new ArrayList<ArrayList<Cell>>(); - for (int row = 0; row < this.nbLines; row++) { - this.board.add(new ArrayList<Cell>()); - for (int column = 0; column < this.nbColumns; column++) { - boolean isMine = ((int) (Math.random() + difficulty)) == 1; - Cell cell = new Cell(isMine, row + 1, column + 1); - this.board.get(row).add(cell); - if (isMine) - nbMines++; - } - } - - this.nbBlanks = (nbLines * nbColumns) - nbMines; - setNeighbors(); - } - - private void setNeighbors() { - for (ArrayList<Cell> row : board) - for (Cell cell : row) { - addAllNeighbors(cell); - } - } - - private void addAllNeighbors(Cell cell) { - int res = 0; - for (int row = cell.getRow() - 1; row <= (cell.getRow() + 1); row++) { - for (int col = cell.getColumn() - 1; col <= (cell.getColumn() + 1); col++) { - - if (isValidPositionLC(row, col) && !(row == cell.getRow() && col == cell.getColumn())) - // && isMine(row, col) && !(row == cell.getRow()) && !(col == cell.getRow()) - cell.addNeighbor(getCell(row, col)); - } - } - } -// public double getDifficulte() { -// return difficulte; -// } -// -// public void setDifficulte(double difficulte) { -// this.difficulte = difficulte; -// } - -// public Color getColorSweeper() { -// return colorSweeper; -// } -// -// public void setColorSweeper(Color color) { -// this.colorSweeper = color; -// } - - public int getNbColumns() { - return nbColumns; - } - - public int getNbLines() { - return nbLines; - } - - public int getScore() { - return score; - } - - public void increaseScore() { - score++; - } - - public boolean isRevealed(int line, int column) { - if (isValidPositionLC(line, column)) - return getCell(line, column).getIsRevealed(); - return false; - } - - public boolean isMine(int line, int column) { - if (isValidPositionLC(line, column)) - return getCell(line, column).getIsMine(); - return false; - } - - public void reveal(int line, int column) { - boolean isIt = isMine(line, column); - if (isIt) { - gameOver = true; - for (ArrayList<Cell> row : board) { - for (Cell cell : row) - cell.reveal(); - } - } - getCell(line, column).reveal(); - nbRevealed++; - if (nbRevealed == nbBlanks) { - gameWin = true; - } - } - - public Cell getCell(int line, int column) { - if (isValidPositionLC(line, column)) - return board.get(line - 1).get(column - 1); - return null; - } - - public void select(int line, int column) { - getCell(line, column).setSelected(true); - } - -// public void deselect(int line, int column) { -// board.get(line).get(column).setSelected(false); -// } - - public boolean isGameOver() { - return gameOver; - } - - public boolean isValidPositionLC(int line, int column) { - boolean lineCheck = line <= nbLines && line > 0; - boolean columnCheck = column <= nbColumns && column > 0; - if (lineCheck && columnCheck) - return true; - return false; - } - - public boolean isOver() { - return gameOver || gameWin; - } - - public boolean isWin() { - return gameWin; - } - - public void updateScore() { - int nbRevealedTmp = 0; - for (ArrayList<Cell> row : board) - for (Cell cell : row) - if (cell.isRevealed()) - nbRevealedTmp++; - nbRevealed = nbRevealedTmp; - score = nbRevealed; - if (nbRevealed == nbBlanks) - gameWin = true; - } - - public void flag(int line, int column) { - // TODO Auto-generated method stub - if (getCell(line, column).isFlagged()) - getCell(line, column).setFlagged(false); - else { - getCell(line, column).setFlagged(true); - } - - } - - public boolean isFlagged(int line, int column) { - return getCell(line, column).isFlagged(); - } - - public double getDifficulty() { - return this.difficulty; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v3/MinesweeperFrame.java b/CCI_Java/CCI_Java/src/tp6/v3/MinesweeperFrame.java deleted file mode 100644 index 5bebefd..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v3/MinesweeperFrame.java +++ /dev/null @@ -1,81 +0,0 @@ -package tp6.v3; - -import java.awt.Color; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.WindowConstants; - -@SuppressWarnings("serial") -public class MinesweeperFrame extends JFrame { - Minesweeper minesweeper; - MinesweeperPanel minesweeperPanel; - static JMenuBar mb; - - static JMenu menu, size, difficulte, color; - -// static JMenuItem size, difficulte, color; - static JMenuItem size1, size2, size3, diff1, diff2, diff3, color1, color2, color3 ; - static JFrame f; - - public MinesweeperFrame() { - - mb = new JMenuBar(); - - - menu = new JMenu("menu"); -// size = new JMenu("size in pixel"); - difficulte = new JMenu("difficulty"); - color = new JMenu("color"); - -// size1 = new JMenuItem("500"); -// size2 = new JMenuItem("700"); -// size3 = new JMenuItem("1000"); -// -// size.add(size1); -// size.add(size2); -// size.add(size3); - - diff1 = new JMenuItem("20% bombs"); - diff1.addActionListener(e -> this.minesweeper.resetGame(0.20)); - diff2 = new JMenuItem("35% bombs"); - diff2.addActionListener(e -> this.minesweeper.resetGame(0.35)); - diff3 = new JMenuItem("50% bombs"); - diff3.addActionListener(e -> this.minesweeper.resetGame(0.50)); - - - - difficulte.add(diff1); - difficulte.add(diff2); - difficulte.add(diff3); - - color1 = new JMenuItem("red"); - color1.addActionListener(e -> this.minesweeperPanel.setColorSweeper(Color.RED)); - color2 = new JMenuItem("blue"); - color2.addActionListener(e -> this.minesweeperPanel.setColorSweeper(Color.BLUE)); - color3 = new JMenuItem("yellow"); - color3.addActionListener(e -> this.minesweeperPanel.setColorSweeper(Color.YELLOW)); - - color.add(color1); - color.add(color2); - color.add(color3); - -// menu.add(size); - menu.add(difficulte); - menu.add(color); - - mb.add(menu); - setJMenuBar(mb); - this.minesweeper = new Minesweeper(); - - this.minesweeperPanel = new MinesweeperPanel(minesweeper); - add(minesweeperPanel); - - pack(); - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - setVisible(true); - - } -} \ No newline at end of file diff --git a/CCI_Java/CCI_Java/src/tp6/v3/MinesweeperPanel.java b/CCI_Java/CCI_Java/src/tp6/v3/MinesweeperPanel.java deleted file mode 100644 index 4470a28..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v3/MinesweeperPanel.java +++ /dev/null @@ -1,230 +0,0 @@ -package tp6.v3; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class MinesweeperPanel extends JPanel { - Minesweeper minesweeper; - int spaceHor; - int spaceVert; - int nbColumns; - int nbRows; - int selCol; - int selLine; - int carreWidth; - int carreHeight; - int spaceBorder; - private Color colorSweeper; - - static JMenuBar mb; - - static JMenu menu; - - static JMenuItem size, difficulte, color; - - static JFrame f; - - public MinesweeperPanel(Minesweeper minesweeper) { - this.minesweeper = minesweeper; - setPreferredSize(new Dimension(500, 500)); - addMouseListener(new PanelMouseListener(this)); - addMouseMotionListener(new PanelMouseListener(this)); - spaceBorder = 20; - this.colorSweeper = Color.RED; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - if (!this.minesweeper.isOver()) - this.minesweeper.updateScore(); - this.nbColumns = this.minesweeper.getNbColumns(); - this.nbRows = this.minesweeper.getNbLines(); - - this.carreWidth = (getWidth() - (getBoardBorder() * 2)) - ((getWidth() - (getBoardBorder() * 2)) % nbColumns); - this.carreHeight = (getHeight() - (getBoardBorder() * 2)) - ((getHeight() - (getBoardBorder() * 2)) % nbRows); - - this.spaceHor = carreWidth / nbColumns; - this.spaceVert = carreHeight / nbRows; - - for (int idxRow = 1; idxRow <= this.minesweeper.getNbLines(); idxRow++) { - for (int idxCol = 1; idxCol <= this.minesweeper.getNbColumns(); idxCol++) { - Cell tmp = this.minesweeper.getCell(idxRow, idxCol); -// drawCell(g, idxRow, idxCol); - drawCell(g, tmp); - tmp.setSelected(false); - } - } - - // show score - String banner = "Difficulty : " + this.minesweeper.getDifficulty() + " Score : " - + this.minesweeper.getScore(); - int fontSize = spaceBorder - 6; - Font font = new Font("Ariel", Font.BOLD, fontSize); - FontMetrics metricsBanner = g.getFontMetrics(font); - - int xBanner = (getWidth() - metricsBanner.stringWidth(banner)) / 2; - g.setColor(Color.darkGray); - g.setFont(font); - g.drawString(banner, xBanner, (spaceBorder - 3)); - - if (this.minesweeper.isGameOver()) - drawGameOver(g); - else if (this.minesweeper.isWin()) - drawWin(g); - } - - private void drawWin(Graphics g) { - int fontSize = (getHeight() + getWidth()) / (2 * 3 * 2); - Font font = new Font("Ariel", Font.BOLD, fontSize); - FontMetrics metrics = g.getFontMetrics(font); - - g.setColor(Color.CYAN); - g.fillRect(0, fontSize * 2, getWidth(), fontSize * 2);// fontSize * 2 - String gg = "GG, U WIN!"; - int xGame = (getWidth() - metrics.stringWidth(gg)) / 2; - String score = "Score : " + this.minesweeper.getScore(); - int xScore = (getWidth() - metrics.stringWidth(score)) / 2; - g.setColor(Color.BLACK); - g.setFont(font); - g.drawString(gg, xGame, fontSize * 3); - g.drawString(score, xScore, (fontSize * 4) - getHeight() / 22); - System.out.println("You've won! Choose a difficulty to restart the game."); - - } - - private void drawGameOver(Graphics g) { - - int fontSize = (getHeight() + getWidth()) / (2 * 3 * 2); - Font font = new Font("Ariel", Font.BOLD, fontSize); - FontMetrics metrics = g.getFontMetrics(font); - - g.setColor(Color.CYAN); - g.fillRect(0, fontSize * 2, getWidth(), fontSize * 2);// fontSize * 2 - String gg = "GAME OVER!"; - int xGame = (getWidth() - metrics.stringWidth(gg)) / 2; - String score = "Score : " + this.minesweeper.getScore(); - int xScore = (getWidth() - metrics.stringWidth(score)) / 2; - g.setColor(Color.BLACK); - g.setFont(font); - g.drawString(gg, xGame, fontSize * 3); - g.drawString(score, xScore, (fontSize * 4) - getHeight() / 22); - System.out.println("You've lost! Choose a difficulty to restart the game."); - - } - -// @Deprecated -// public void drawCell(Graphics g, int line, int column) { -// -// g.setColor(Color.BLACK); -// g.drawRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); -// Cell tmp = this.minesweeper.getCell(line, column); -// g.setColor(tmp.getColor()); -// g.fillRect(getCellX(column), getCellY(line), getCellWidth(), getCellHeight()); -// -// if (tmp.getIsRevealed() && tmp.getIsMine()) { -// int sizeBomb = 25; -// g.setColor(Color.BLACK); -// g.fillOval(getCellX(column) + (getCellWidth() / 2) - (sizeBomb / 2), -// getCellX(line) + (getCellHeight() / 2) - (sizeBomb / 2), sizeBomb, sizeBomb); -// } -// } - - public void drawCell(Graphics g, Cell tmp) { - - g.setColor(Color.BLACK); - int xTmp = getCellX(tmp.getColumn()); - int yTmp = getCellY(tmp.getRow()); - g.drawRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - - if (tmp.isFlagged()) { - g.setColor(Color.DARK_GRAY); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - g.setColor(Color.WHITE); - g.drawRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - int sizeBomb = (getCellWidth() + getCellHeight()) / 5; - g.setColor(Color.GREEN); - g.fillOval(xTmp + (getCellWidth() / 2) - (sizeBomb / 2), yTmp + (getCellHeight() / 2) - (sizeBomb / 2), - sizeBomb, sizeBomb); - } else if (tmp.isSelected()) { - g.setColor(colorSweeper); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - } else if (tmp.toString().equals("B")) { - g.setColor(Color.RED); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - g.setColor(Color.WHITE); - g.drawRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - int sizeBomb = (getCellWidth() + getCellHeight()) / 5; - g.setColor(Color.BLACK); - g.fillOval(xTmp + (getCellWidth() / 2) - (sizeBomb / 2), yTmp + (getCellHeight() / 2) - (sizeBomb / 2), - sizeBomb, sizeBomb); - } else if (tmp.toString().equals("C")) { - g.setColor(Color.DARK_GRAY); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - } else { - g.setColor(Color.GRAY); - g.fillRect(xTmp, yTmp, getCellWidth(), getCellHeight()); - if (tmp.getNeighbors() != 0) { - g.setColor(Color.BLACK); - g.setFont(new Font("Ariel", Font.BOLD, getCellHeight() / 2)); - g.drawString(String.valueOf(tmp.getNeighbors()), xTmp + 15, (yTmp + getCellHeight() - 10)); - } - } - } - - public int getColumn(int x) { - int posCarre = x - getBoardBorder(); - this.selCol = posCarre / getCellWidth(); - return this.selCol + 1; - } - - public int getLine(int y) { - int posCarre = y - getBoardBorder(); - this.selLine = posCarre / spaceVert; - return this.selLine + 1; - } - - public int getBoardBorder() { - return this.spaceBorder; - } - - public int getCellX(int column) { - return (getBoardBorder() + ((column - 1) * getCellWidth())); - } - - public int getCellY(int line) { - return (getBoardBorder() + ((line - 1) * getCellHeight())); - } - - public int getCellWidth() { - return this.spaceHor; - } - - public int getCellHeight() { - return this.spaceVert; - } - - public boolean isValidPositionPx(int x, int y) { - boolean condX = x > getBoardBorder() && x < (getBoardBorder() + (this.nbColumns * getCellWidth())); - boolean condY = y > getBoardBorder() && y < (getBoardBorder() + (this.nbRows * getCellHeight())); - if (condX && condY) - return true; - return false; - } - - public void setColorSweeper(Color colorSweeper) { - this.colorSweeper = colorSweeper; - } - -} diff --git a/CCI_Java/CCI_Java/src/tp6/v3/MinesweeperPanelable.java b/CCI_Java/CCI_Java/src/tp6/v3/MinesweeperPanelable.java deleted file mode 100644 index 77f40ee..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v3/MinesweeperPanelable.java +++ /dev/null @@ -1,22 +0,0 @@ -package tp6.v3; - -import java.awt.Graphics; - -public interface MinesweeperPanelable { - - public int getBoardBorder(); - - public int getCellX(int column); - - public int getCellY(int line); - - public int getCellWidth(); - - public int getCellHeight(); - - public void drawCell(Graphics g, int line, int column); - - public int getColumn(int x); - - public int getLine(int y); -} diff --git a/CCI_Java/CCI_Java/src/tp6/v3/PanelMouseListener.java b/CCI_Java/CCI_Java/src/tp6/v3/PanelMouseListener.java deleted file mode 100644 index 3a3e28b..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v3/PanelMouseListener.java +++ /dev/null @@ -1,50 +0,0 @@ -package tp6.v3; - -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.SwingUtilities; - -public class PanelMouseListener extends MouseAdapter { - MinesweeperPanel panel; - - public PanelMouseListener(MinesweeperPanel panel) { - this.panel = panel; - } - - @Override - public void mouseClicked(MouseEvent e) { - -// System.out.println("Click Line = " + panel.minesweeper.selectedLine); -// System.out.println("Click Column = " + panel.minesweeper.selectedColumn); - - if (panel.isValidPositionPx(e.getX(), e.getY()) && !panel.minesweeper.isOver()) { - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - if (SwingUtilities.isLeftMouseButton(e) && !panel.minesweeper.isFlagged(line, column)) { - panel.minesweeper.reveal(line, column); - if (!panel.minesweeper.isMine(line, column)) - panel.minesweeper.increaseScore(); - } else if (SwingUtilities.isRightMouseButton(e)) { - panel.minesweeper.flag(line, column); - } - - panel.repaint(); - } - } - - @Override - public void mouseMoved(MouseEvent e) { - -// panel.minesweeper.selectedLine = panel.getLine(e.getY()); -// panel.minesweeper.selectedColumn = panel.getColumn(e.getX()); - - if (panel.isValidPositionPx(e.getX(), e.getY()) && !panel.minesweeper.isOver()) { - int line = panel.getLine(e.getY()); - int column = panel.getColumn(e.getX()); - panel.minesweeper.select(line, column); - panel.repaint(); - } - - } -} diff --git a/CCI_Java/CCI_Java/src/tp6/v3/Position.java b/CCI_Java/CCI_Java/src/tp6/v3/Position.java deleted file mode 100644 index 04dd892..0000000 --- a/CCI_Java/CCI_Java/src/tp6/v3/Position.java +++ /dev/null @@ -1,29 +0,0 @@ -package tp6.v3; - -import java.util.ArrayList; - -public class Position { - - private int line; - private int column; - private ArrayList<Position> neighbors; - - public Position(int line, int column) { - super(); - this.line = line; - this.column = column; - this.neighbors = new ArrayList<Position>(); - - setNeighbors(); - } - - private void setNeighbors() { - for (int ln = line - 1; ln < line + 1; ln++) { - for (int cmn = column - 1; cmn < column + 1; cmn++) { - if (ln != line && cmn != column) - this.neighbors.add(new Position(ln, cmn)); - } - } - } - -} diff --git a/CCI_Java/CCI_Java/src/version1/Direction.java b/CCI_Java/CCI_Java/src/version1/Direction.java new file mode 100644 index 0000000..a23aa39 --- /dev/null +++ b/CCI_Java/CCI_Java/src/version1/Direction.java @@ -0,0 +1,5 @@ +package version1; + +public enum Direction { + NORTH, SOUTH, EAST, WEST +} diff --git a/CCI_Java/CCI_Java/src/version1/MainFrame.java b/CCI_Java/CCI_Java/src/version1/MainFrame.java new file mode 100644 index 0000000..ee44f68 --- /dev/null +++ b/CCI_Java/CCI_Java/src/version1/MainFrame.java @@ -0,0 +1,7 @@ +package version1; + +public class MainFrame { + public static void main(String[] args) { + new SnakeGameFrame().setVisible(true); + } +} diff --git a/CCI_Java/CCI_Java/src/version1/Position.java b/CCI_Java/CCI_Java/src/version1/Position.java new file mode 100644 index 0000000..db627de --- /dev/null +++ b/CCI_Java/CCI_Java/src/version1/Position.java @@ -0,0 +1,16 @@ +package version1; + +public class Position { + public final int line; + public final int column; + + public Position(int line, int column) { + this.line = line; + this.column = column; + } + + @Override + public String toString() { + return "(" + column + "," + line + ")"; + } +} diff --git a/CCI_Java/CCI_Java/src/version1/SnakeGame.java b/CCI_Java/CCI_Java/src/version1/SnakeGame.java new file mode 100644 index 0000000..69e2902 --- /dev/null +++ b/CCI_Java/CCI_Java/src/version1/SnakeGame.java @@ -0,0 +1,5 @@ +package version1; + +public class SnakeGame { + +} diff --git a/CCI_Java/CCI_Java/src/version1/SnakeGameFrame.java b/CCI_Java/CCI_Java/src/version1/SnakeGameFrame.java new file mode 100644 index 0000000..5e8e15d --- /dev/null +++ b/CCI_Java/CCI_Java/src/version1/SnakeGameFrame.java @@ -0,0 +1,19 @@ +package version1; + + +import java.awt.Dimension; + +import javax.swing.JFrame; +import javax.swing.WindowConstants; + +@SuppressWarnings("serial") + +public class SnakeGameFrame extends JFrame { + + public SnakeGameFrame() { + setTitle("Snake"); + setSize(new Dimension(400, 400)); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + add(new SnakeGamePanel()); + } +} diff --git a/CCI_Java/CCI_Java/src/version1/SnakeGamePanel.java b/CCI_Java/CCI_Java/src/version1/SnakeGamePanel.java new file mode 100644 index 0000000..209f0a0 --- /dev/null +++ b/CCI_Java/CCI_Java/src/version1/SnakeGamePanel.java @@ -0,0 +1,97 @@ +package version1; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.Timer; +import java.util.TimerTask; + +import javax.swing.JPanel; + +@SuppressWarnings("serial") +public class SnakeGamePanel extends JPanel { + private final SnakeGame snakeGame = new SnakeGame(); + private final Timer timer = new Timer(); + private static final int MIN_BORDER_SIZE = 40; + + public SnakeGamePanel() { + initializeKeyListener(); + initializeTimer(); + } + + @Override + public void paint(Graphics g) { + for (int line = 0; line < SnakeGame.GRID_LINES; line++) + for (int column = 0; column < SnakeGame.GRID_COLUMNS; column++) + paintPosition(g, line, column); + } + + private void paintPosition(Graphics g, int line, int column) { + int x = getX(column); + int y = getY(line); + + g.setColor(getColorAt(line, column)); + g.fillRect(x, y, getCellSize(), getCellSize()); + + g.setColor(Color.LIGHT_GRAY); + g.drawRect(x, y, getCellSize(), getCellSize()); + } + + private Color getColorAt(int line, int column) { + if (snakeGame.isSnakeAt(new Position(line, column))) + return snakeGame.isGameOver() ? Color.MAGENTA : Color.GREEN; + return snakeGame.isAppleAt(new Position(line, column)) ? Color.RED : Color.BLUE; + } + + public int getCellSize() { + int cellMaximumHeight = (getHeight() - (2 * MIN_BORDER_SIZE)) / SnakeGame.GRID_LINES; + int cellMaximumWidth = (getWidth() - (2 * MIN_BORDER_SIZE)) / SnakeGame.GRID_COLUMNS; + return Math.min(cellMaximumWidth, cellMaximumHeight); + } + + private int getXBorder() { + return (getWidth() - (SnakeGame.GRID_COLUMNS * getCellSize())) / 2; + } + + private int getYBorder() { + return (getHeight() - (SnakeGame.GRID_LINES * getCellSize())) / 2; + } + + private int getX(int column) { + return getXBorder() + column * getCellSize(); + } + + private int getY(int line) { + return getYBorder() + line * getCellSize(); + } + + private void initializeKeyListener() { + setFocusable(true); + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_UP) + snakeGame.changeDirection(Direction.SOUTH); + else if (e.getKeyCode() == KeyEvent.VK_DOWN) + snakeGame.changeDirection(Direction.NORTH); + else if (e.getKeyCode() == KeyEvent.VK_LEFT) + snakeGame.changeDirection(Direction.WEST); + else if (e.getKeyCode() == KeyEvent.VK_RIGHT) + snakeGame.changeDirection(Direction.EAST); + else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) + snakeGame.initialize(); + } + }); + } + + private void initializeTimer() { + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + snakeGame.advance(); + repaint(); + } + }, 1000, 200); + } +} \ No newline at end of file diff --git a/CCI_Java/CCI_Java/src/version1/TestDirection.java b/CCI_Java/CCI_Java/src/version1/TestDirection.java new file mode 100644 index 0000000..f46a98b --- /dev/null +++ b/CCI_Java/CCI_Java/src/version1/TestDirection.java @@ -0,0 +1,15 @@ +package version1; + +public class TestDirection { + + public static void main(String[] args) { + Direction direction1 = null; + System.out.println("Direction initiale : " + direction1); + direction1 = Direction.NORTH; + System.out.println("Nouvelle direction : " + direction1); + System.out.println(direction1 == Direction.NORTH); + System.out.println(direction1 == Direction.EAST); + } + + +} diff --git a/CCI_Java/CCI_Java/src/version1/TestPosition.java b/CCI_Java/CCI_Java/src/version1/TestPosition.java new file mode 100644 index 0000000..30853da --- /dev/null +++ b/CCI_Java/CCI_Java/src/version1/TestPosition.java @@ -0,0 +1,11 @@ +package version1; + +public class TestPosition { + + public static void main(String[] args) { + + Position pos1 = new Position(3, 4); + System.out.println(pos1); + } + +} -- GitLab