Commit 619359a3 authored by Hugo DACLON's avatar Hugo DACLON
Browse files

correction bug "overlapping boats"

parent 2fab5a31
......@@ -160,31 +160,39 @@ public class CreationFlotte extends JPanel {// JPanel {
}
public void creerBateau(Coord cell) throws BadCoordException, CoordsBadShipException {
Ship ship;
Ship newShip;
map.resetCell(selectedCell);
switch (getDistanceBateau(cell)) {
case 1:
ship = new Submarine("Sous-Marin", selectedCell.toString());
newShip = new Submarine("Sous-Marin", selectedCell.toString());
break;
case 2:
ship = new Destroyer("Destroyer", selectedCell.toString(), cell.toString());
newShip = new Destroyer("Destroyer", selectedCell.toString(), cell.toString());
break;
case 3:
ship = new Cruiser("Sous-Marin", selectedCell.toString(), cell.toString());
newShip = new Cruiser("Sous-Marin", selectedCell.toString(), cell.toString());
break;
case 4:
ship = new Battleship("Sous-Marin", selectedCell.toString(), cell.toString());
newShip = new Battleship("Sous-Marin", selectedCell.toString(), cell.toString());
break;
case 5:
ship = new AircraftCarrier("Sous-Marin", selectedCell.toString(), cell.toString());
newShip = new AircraftCarrier("Sous-Marin", selectedCell.toString(), cell.toString());
break;
default:
selectedCell = null;
throw new CoordsBadShipException();
}
for (IShip flotteShip : appli.getFlotte().getShips()) {
for (ICoord c : newShip.getCoords()) {
if (flotteShip.getCoords().contains(c)) {
selectedCell = null;
throw new CoordsBadShipException();
}
}
}
selectedCell = null;
appli.getFlotte().add(ship);
map.ajouterBateau(ship);
appli.getFlotte().add(newShip);
map.ajouterBateau(newShip);
}
private boolean isVertical(Coord cell) {
......
......@@ -21,7 +21,7 @@ public class AjouterBateau implements MouseListener {
}
@Override
public void mouseClicked(MouseEvent arg0) {//TODO : régler problèmes création d'un bateau par dessus un autres (besion d'un foreach coord c de newship > ship s de getflotte.getShips > throw CoordsBadShipException si s.getCoords.contains c) puis si il reste du temps chercher à diminuer le couût de ce "test"
public void mouseClicked(MouseEvent arg0) {
//* --------Partie 1 Selection d'une Cellule--------
char x = ((char)(arg0.getX()/50));
x+='A';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment