Ajout de la prise en charge des clics sur la grille #1
@ -35,14 +35,26 @@ public class GridController {
|
||||
if (square.isWall()) {
|
||||
square.setEmpty();
|
||||
} else {
|
||||
try {
|
||||
square.setWall();
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(view, ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
view.repaint();
|
||||
} else if (editMode == Mode.THESEE) {
|
||||
try {
|
||||
model.getThesee().setSquare(square);
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(view, ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
view.repaint();
|
||||
} else if (editMode == Mode.EXIT) {
|
||||
try {
|
||||
square.setExit();
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(view, ex.getMessage(), "Erreur", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
view.repaint();
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,16 @@ public class GridView extends JPanel {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -37,14 +37,17 @@ public class Square {
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 j = 0; j < this.gridModel.getSize(); j++) {
|
||||
try {
|
||||
|
@ -2,7 +2,8 @@ public class Thesee {
|
||||
private Square square;
|
||||
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();
|
||||
this.square = square;
|
||||
if (this.intialSquare == null) this.intialSquare = this.square;
|
||||
|
Loading…
Reference in New Issue
Block a user