Mise à jour du JavaDoc

This commit is contained in:
Lyanis SOUIDI 2023-05-01 23:33:05 +02:00
parent 83349af79a
commit 0f7aa1529f
Signed by: Lyanis SOUIDI
GPG Key ID: 251ADD56CFE6A854
15 changed files with 334 additions and 1 deletions

View File

@ -9,6 +9,9 @@ import java.awt.*;
* @author Lyanis Souidi * @author Lyanis Souidi
*/ */
public class AutoSimulationView extends JPanel { public class AutoSimulationView extends JPanel {
/**
* The automatic simulation model
*/
public final AutoSimulation model; public final AutoSimulation model;
/** /**
@ -22,6 +25,10 @@ public class AutoSimulationView extends JPanel {
this.setPreferredSize(new Dimension(700, 500)); this.setPreferredSize(new Dimension(700, 500));
} }
/**
* Paint the view
* @param g The graphics
*/
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);

View File

@ -1,13 +1,28 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
/**
* Class containing custom settings for JButtons used in the application.
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/
public class Button extends JButton { public class Button extends JButton {
/**
* Constructor
* @param text The text of the button
*/
public Button (String text) { public Button (String text) {
super(text); super(text);
setFont(new Font("Arial", Font.BOLD, 15)); setFont(new Font("Arial", Font.BOLD, 15));
setBackground(new Color(96, 175, 255)); setBackground(new Color(96, 175, 255));
} }
/**
* Constructor
* @param text The text of the button
* @param dimension The dimension of the button
*/
public Button(String text, Dimension dimension) { public Button(String text, Dimension dimension) {
super(text); super(text);
setPreferredSize(dimension); setPreferredSize(dimension);

View File

@ -1,10 +1,27 @@
/**
* Class used to edit the grid model
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/
public class Editor { public class Editor {
/**
* The grid model
*/
private final Grid gridModel; private final Grid gridModel;
/**
* Constructor
* @param gridModel The grid model
*/
public Editor(Grid gridModel) { public Editor(Grid gridModel) {
this.gridModel = gridModel; this.gridModel = gridModel;
} }
/**
* Get the grid model
* @return The grid model
*/
public Grid getGrid() { public Grid getGrid() {
return this.gridModel; return this.gridModel;
} }

View File

@ -6,18 +6,68 @@ import java.awt.event.MouseEvent;
import java.io.File; import java.io.File;
import java.util.Random; import java.util.Random;
/**
* Controller for the grid editor
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/
public class EditorController extends GridController { public class EditorController extends GridController {
/**
* The editor model
*/
private final Editor model; private final Editor model;
/**
* The editor view
*/
private final EditorView view; private final EditorView view;
/**
* Enum for the edit mode
*/
private enum Mode { DISABLED, WALL, THESEE, EXIT } private enum Mode { DISABLED, WALL, THESEE, EXIT }
/**
* The edit mode
*/
private Mode editMode = Mode.DISABLED; private Mode editMode = Mode.DISABLED;
/**
* If the grid has been edited
*/
private boolean edited = false; private boolean edited = false;
/**
* Button used to place Thésée in the grid
*/
private final Button editTheseeButton = new Button("Modifier Thésée"); private final Button editTheseeButton = new Button("Modifier Thésée");
/**
* Button used to place the exit in the grid
*/
private final Button editExitButton = new Button("Modifier Sortie"); private final Button editExitButton = new Button("Modifier Sortie");
/**
* Button used to edit the walls in the grid
*/
private final Button editWallButton = new Button("Modifier Murs"); private final Button editWallButton = new Button("Modifier Murs");
/**
* Button used to export the grid
*/
private final Button exportButton = new Button("Exporter"); private final Button exportButton = new Button("Exporter");
/**
* Button used to start the simulation
*/
private final Button startButton = new Button("Démarrer"); private final Button startButton = new Button("Démarrer");
/**
* Constructor
* @param model The editor model
* @param view The editor view
*/
public EditorController(Editor model, EditorView view) { public EditorController(Editor model, EditorView view) {
super(model.getGrid(), view); super(model.getGrid(), view);
this.model = model; this.model = model;

View File

@ -1,11 +1,27 @@
import java.awt.*; import java.awt.*;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
/**
* This the view for the editor
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/
public class EditorView extends GridView { public class EditorView extends GridView {
/**
* Constructor
* @param window the window
*/
public EditorView(Window window) { public EditorView(Window window) {
super(window); super(window);
this.setBackground(new Color(193, 190, 180)); this.setBackground(new Color(193, 190, 180));
} }
/**
* Get the square at the mouse position
* @param e the mouse event
* @return the square at the mouse position, or null if there is no square at this position
*/
public Square click(MouseEvent e) { public Square click(MouseEvent e) {
if ((e.getX() < this.gridStartX) || (e.getX() > (this.gridStartX + this.gridSize)) || (e.getY() < this.gridStartY) || (e.getY() > (this.gridStartY + this.gridSize))) return null; if ((e.getX() < this.gridStartX) || (e.getX() > (this.gridStartX + this.gridSize)) || (e.getY() < this.gridStartY) || (e.getY() > (this.gridStartY + this.gridSize))) return null;
int x = (e.getX() - this.gridStartX) / this.squareSize; int x = (e.getX() - this.gridStartX) / this.squareSize;

View File

@ -1,4 +1,15 @@
/**
* GridController
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/
public class GridController { public class GridController {
/**
* Constructor
* @param model The grid
* @param view The grid's view
*/
public GridController(Grid model, GridView view) { public GridController(Grid model, GridView view) {
view.setGrid(model); view.setGrid(model);
new TheseeController(model.getThesee(), view); new TheseeController(model.getThesee(), view);

View File

@ -1,17 +1,51 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
/**
* Manages the display of the grid
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/
public class GridView extends JPanel { public class GridView extends JPanel {
/**
* The window
*/
public final Window window; public final Window window;
/**
* The grid model
*/
protected Grid model; protected Grid model;
/**
* The grid size in pixels
*/
protected int gridSize; protected int gridSize;
/**
* The grid x start position in pixels
*/
protected int gridStartX; protected int gridStartX;
/**
* The grid y start position in pixels
*/
protected int gridStartY; protected int gridStartY;
/**
* The size of one square in pixels
*/
protected int squareSize; protected int squareSize;
/**
* The font used to display the characters
*/
private Font font; private Font font;
/** /**
* Manages the display of the grid * Constructor
* @param window The window
*/ */
public GridView(Window window) { public GridView(Window window) {
super(); super();
@ -20,10 +54,17 @@ public class GridView extends JPanel {
this.setPreferredSize(new Dimension(700, 500)); this.setPreferredSize(new Dimension(700, 500));
} }
/**
* Sets the grid model
* @param model The grid model
*/
public void setGrid(Grid model) { public void setGrid(Grid model) {
this.model = model; this.model = model;
} }
/**
* Calculates the proportions of the grid
*/
private void calculateProportions() { private void calculateProportions() {
this.gridSize = Math.min((getHeight() - 50), getWidth()) - 10; this.gridSize = Math.min((getHeight() - 50), getWidth()) - 10;
this.gridStartX = (getWidth() - this.gridSize) / 2; this.gridStartX = (getWidth() - this.gridSize) / 2;
@ -32,6 +73,10 @@ public class GridView extends JPanel {
this.font = new Font("Arial", Font.PLAIN, (int) (this.squareSize * 0.75)); this.font = new Font("Arial", Font.PLAIN, (int) (this.squareSize * 0.75));
} }
/**
* Paints the grid
* @param g The graphics
*/
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);

View File

@ -3,9 +3,19 @@ import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
/**
* The home view
*/
public class HomeView extends JPanel { public class HomeView extends JPanel {
/**
* The window
*/
public final Window window; public final Window window;
/**
* Constructor
* @param window the window
*/
public HomeView(Window window) { public HomeView(Window window) {
this.window = window; this.window = window;
@ -32,6 +42,10 @@ public class HomeView extends JPanel {
add(panelBoutons, BorderLayout.CENTER); add(panelBoutons, BorderLayout.CENTER);
} }
/**
* Creates the title
* @return the title
*/
private static JLabel getTitre() { private static JLabel getTitre() {
JLabel texte = new JLabel("Choisissez votre type de grille", SwingConstants.CENTER); JLabel texte = new JLabel("Choisissez votre type de grille", SwingConstants.CENTER);
texte.setPreferredSize(new Dimension(800, 50)); texte.setPreferredSize(new Dimension(800, 50));
@ -40,6 +54,10 @@ public class HomeView extends JPanel {
return texte; return texte;
} }
/**
* Creates the button to choose a grid
* @return the button
*/
private Button choisirGrille() { private Button choisirGrille() {
Button choisirGrille = new Button("Générer une grille", new Dimension(250, 50)); Button choisirGrille = new Button("Générer une grille", new Dimension(250, 50));
@ -92,6 +110,10 @@ public class HomeView extends JPanel {
return choisirGrille; return choisirGrille;
} }
/**
* Creates the button to import a grid
* @return the button
*/
private Button importerGrille() { private Button importerGrille() {
Button importerGrille = new Button("Importer une grille", new Dimension(250, 50)); Button importerGrille = new Button("Importer une grille", new Dimension(250, 50));
@ -124,6 +146,7 @@ public class HomeView extends JPanel {
/** /**
* Shows a warning message if the grid size is too big * Shows a warning message if the grid size is too big
* @param size the size of the grid * @param size the size of the grid
* @param parentComponent the parent component
* @return true if the user wants to continue, false otherwise * @return true if the user wants to continue, false otherwise
*/ */
public static boolean sizeWarning(JComponent parentComponent, int size) { public static boolean sizeWarning(JComponent parentComponent, int size) {
@ -133,6 +156,10 @@ public class HomeView extends JPanel {
return choice != 0; return choice != 0;
} }
/**
* Paints the background
* @param g The graphics
*/
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);

View File

@ -1,6 +1,14 @@
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.File;
/**
* The main class used to launch the application
*/
public class Main { public class Main {
/**
* The main method
* @param args the command line arguments
*/
public static void main(String[] args) { public static void main(String[] args) {
Window window = new Window(); Window window = new Window();

View File

@ -67,6 +67,9 @@ public class ManualSimulationController {
} }
} }
/**
* Makes the next move of the simulation
*/
private void move() { private void move() {
if (model.getSimulation().isEnded()) return; if (model.getSimulation().isEnded()) return;
this.algo.nextMove(); this.algo.nextMove();

View File

@ -23,6 +23,10 @@ public class ManualSimulationView extends GridView {
super.setGrid(this.model.getGrid()); super.setGrid(this.model.getGrid());
} }
/**
* Add the moves counter to the view
* @param g The graphics
*/
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);

View File

@ -1,11 +1,50 @@
/**
* Represents a square in the grid
* @see Grid
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/
public class Square { public class Square {
/**
* The row of the square in the grid
*/
private final int row; private final int row;
/**
* The column of the square in the grid
*/
private final int column; private final int column;
/**
* The type of the square
* 0: empty
* 1: wall
* 2: exit
*/
private int type = 0; private int type = 0;
/**
* Whether the square has been visited or not
*/
private boolean isVisited = false; private boolean isVisited = false;
/**
* Whether the square is accessible from Thésée's position or not
*/
private boolean isAccessible = false; private boolean isAccessible = false;
/**
* The grid model
*/
private final Grid gridModel; private final Grid gridModel;
/**
* Constructor
* @param gridModel The grid model
* @param row The row of the square in the grid
* @param column The column of the square in the grid
*/
public Square(Grid gridModel, int row, int column) { public Square(Grid gridModel, int row, int column) {
this.gridModel = gridModel; this.gridModel = gridModel;
this.row = row; this.row = row;
@ -28,12 +67,17 @@ public class Square {
return this.type == 2; return this.type == 2;
} }
/**
* Checks if the current square is Thésée's position
* @return true if the current square is Thésée's position, false otherwise
*/
public boolean isThesee() { public boolean isThesee() {
return this.gridModel.getThesee().getSquare() == this; return this.gridModel.getThesee().getSquare() == this;
} }
/** /**
* Sets the current square as a wall * Sets the current square as a wall
* @throws Exception If the current square is Thésée's position or the exit
*/ */
public void setWall() throws Exception { public void setWall() throws Exception {
if (this.gridModel.getThesee().getSquare() == this) throw new Exception("Vous ne pouvez pas placer un mur sur la même case que Thésée. Déplacez d'abord Thésée puis réessayez."); if (this.gridModel.getThesee().getSquare() == this) throw new Exception("Vous ne pouvez pas placer un mur sur la même case que Thésée. Déplacez d'abord Thésée puis réessayez.");
@ -43,6 +87,7 @@ public class Square {
/** /**
* Removes the existing exit from the grid (if it exists) and sets the current square as an exit * Removes the existing exit from the grid (if it exists) and sets the current square as an exit
* @throws Exception If the current square is Thésée's position
*/ */
public void setExit() throws Exception { public void setExit() throws Exception {
if (this.gridModel.getThesee().getSquare() == this) throw new Exception("Vous ne pouvez pas placer la sortie sur la même case que Thésée. Déplacez d'abord Thésée puis réessayez."); if (this.gridModel.getThesee().getSquare() == this) throw new Exception("Vous ne pouvez pas placer la sortie sur la même case que Thésée. Déplacez d'abord Thésée puis réessayez.");
@ -63,30 +108,58 @@ public class Square {
this.type = 0; this.type = 0;
} }
/**
* Get the row of the square in the grid
* @return The row of the square in the grid
*/
public int getRow() { public int getRow() {
return this.row; return this.row;
} }
/**
* Get the column of the square in the grid
* @return The column of the square in the grid
*/
public int getColumn() { public int getColumn() {
return this.column; return this.column;
} }
/**
* Get the grid model
* @return The grid model
*/
public Grid getGrid() { public Grid getGrid() {
return this.gridModel; return this.gridModel;
} }
/**
* Checks if the square has been visited or not
* @return true if the current square has been visited, false otherwise
*/
public boolean isVisited() { public boolean isVisited() {
return this.isVisited; return this.isVisited;
} }
/**
* Change the square visited status
* @param isVisited Whether the current square has been visited or not
*/
public void setVisited(boolean isVisited) { public void setVisited(boolean isVisited) {
this.isVisited = isVisited; this.isVisited = isVisited;
} }
/**
* Checks if the square is accessible from Thésée's position or not
* @return true if the current square is accessible from Thésée's position, false otherwise
*/
public boolean isAccessible() { public boolean isAccessible() {
return this.isAccessible; return this.isAccessible;
} }
/**
* Change the square accessibility status
* @param isAccessible Whether the current square is accessible from Thésée's position or not
*/
public void setAccessible(boolean isAccessible) { public void setAccessible(boolean isAccessible) {
this.isAccessible = isAccessible; this.isAccessible = isAccessible;
} }

View File

@ -1,8 +1,18 @@
/** /**
* Represents Thésée in the labyrinth. * Represents Thésée in the labyrinth.
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/ */
public class Thesee { public class Thesee {
/**
* The square where Thésée is.
*/
private Square square; private Square square;
/**
* The initial square where Thésée is.
*/
private Square intialSquare; private Square intialSquare;
/** /**

View File

@ -1,12 +1,34 @@
/**
* The controller of Thésée.
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/
public class TheseeController { public class TheseeController {
/**
* The model of Thésée
*/
private final Thesee model; private final Thesee model;
/**
* The view of Thésée
*/
private GridView gridView; private GridView gridView;
/**
* Constructor (with view)
* @param model The model of Thésée
* @param gridView The view of Thésée
*/
public TheseeController(Thesee model, GridView gridView) { public TheseeController(Thesee model, GridView gridView) {
this.model = model; this.model = model;
this.gridView = gridView; this.gridView = gridView;
} }
/**
* Constructor (without view)
* @param model The model of Thésée
*/
public TheseeController(Thesee model) { public TheseeController(Thesee model) {
this.model = model; this.model = model;
} }

View File

@ -2,9 +2,26 @@ import javax.swing.JFrame;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Toolkit; import java.awt.Toolkit;
/**
* Window class that extends JFrame with custom settings for the program.
* @version 1.0
* @author Amir Daouadi
* @author Lyanis Souidi
*/
public class Window extends JFrame { public class Window extends JFrame {
/**
* The title of the program.
*/
private static final String programTitle = "Labyrinthe"; private static final String programTitle = "Labyrinthe";
/**
* The title of the current page.
*/
private String pageTitle = ""; private String pageTitle = "";
/**
* Constructor
*/
public Window() { public Window() {
super(programTitle); super(programTitle);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
@ -15,10 +32,18 @@ public class Window extends JFrame {
this.setMinimumSize(new Dimension(800, 850)); this.setMinimumSize(new Dimension(800, 850));
} }
/**
* Get the title of the current page.
* @return The title of the current page.
*/
public String getPageTitle() { public String getPageTitle() {
return this.pageTitle; return this.pageTitle;
} }
/**
* Set the title of the current page.
* @param title The title of the current page.
*/
public void setPageTitle(String title) { public void setPageTitle(String title) {
this.pageTitle = title; this.pageTitle = title;
this.setTitle(this.pageTitle + " - " + Window.programTitle); this.setTitle(this.pageTitle + " - " + Window.programTitle);