Ajout de la fonctionnalité d'import/export de grille #2

Merged
Lyanis SOUIDI merged 6 commits from feature_filemanager into master 2023-04-28 03:23:44 +02:00
4 changed files with 32 additions and 7 deletions
Showing only changes of commit 9b8565d62e - Show all commits

View File

@ -35,14 +35,26 @@ public class GridController {
if (square.isWall()) { if (square.isWall()) {
square.setEmpty(); square.setEmpty();
} else { } else {
try {
square.setWall(); square.setWall();
} catch (Exception ex) {
JOptionPane.showMessageDialog(view, ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
}
} }
view.repaint(); view.repaint();
} else if (editMode == Mode.THESEE) { } else if (editMode == Mode.THESEE) {
try {
model.getThesee().setSquare(square); model.getThesee().setSquare(square);
} catch (Exception ex) {
JOptionPane.showMessageDialog(view, ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
}
view.repaint(); view.repaint();
} else if (editMode == Mode.EXIT) { } else if (editMode == Mode.EXIT) {
try {
square.setExit(); square.setExit();
} catch (Exception ex) {
JOptionPane.showMessageDialog(view, ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
}
view.repaint(); view.repaint();
} }
} }

View File

@ -26,7 +26,16 @@ public class GridView extends JPanel {
} }
public Square click(MouseEvent e) { public Square click(MouseEvent e) {
// TODO: Détection du clic sur une case 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 y = (e.getY() - this.gridStartY) / this.squareSize;
if ((x >= 0) && (x < this.model.getSize()) && (y >= 0) && (y < this.model.getSize())) {
try {
return this.model.getSquare(y, x);
} catch (Exception ex) {
return null;
}
}
return null; return null;
} }

View File

@ -41,14 +41,17 @@ public class Square {
/** /**
* Sets the current square as a wall * Sets the current square as a wall
*/ */
public void setWall() { 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.isExit()) throw new Exception("Vous ne pouvez pas placer un mur sur la même case que la sortie. Déplacez d'abord la sortie puis réessayez.");
this.type = 1; this.type = 1;
} }
/** /**
* 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
*/ */
public void setExit() { 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.");
for (int i = 0; i < this.gridModel.getSize(); i++) { for (int i = 0; i < this.gridModel.getSize(); i++) {
for (int j = 0; j < this.gridModel.getSize(); j++) { for (int j = 0; j < this.gridModel.getSize(); j++) {
try { try {

View File

@ -2,7 +2,8 @@ public class Thesee {
private Square square; private Square square;
private Square intialSquare; private Square intialSquare;
public void setSquare(Square square) { public void setSquare(Square square) throws Exception {
if (square.isExit()) throw new Exception("Vous ne pouvez pas placer Thesee sur la même case que la sortie. Déplacez d'abord la sortie puis réessayez.");
square.setEmpty(); square.setEmpty();
this.square = square; this.square = square;
if (this.intialSquare == null) this.intialSquare = this.square; if (this.intialSquare == null) this.intialSquare = this.square;