diff --git a/src/info1/controller/ModeleController.java b/src/info1/controller/ModeleController.java index 6fbf2542344921e2c3752bef83971754e3bb4530..b7e87d14fa28a74002df10cea425e479cf042704 100644 --- a/src/info1/controller/ModeleController.java +++ b/src/info1/controller/ModeleController.java @@ -6,6 +6,7 @@ import info1.network.Game; import info1.network.Network; import info1.network.Player; import info1.ships.BadCoordException; +import info1.ships.Coord; import info1.ships.ICoord; import info1.ships.INavyFleet; import info1.view.Accueil; @@ -142,6 +143,159 @@ public class ModeleController implements MouseMotionListener, MouseListener, Act } else if (res == 10) { //Pour mettre tout le bateau en rouge car coulé// plateau.setBateauCoule(coord); + ICoord temp = coord; + List<ICoord> coordContiguAtemp = new ArrayList<>(); + coordContiguAtemp.add(temp); + + //Pour l'horizontale droit + int x = temp.getX()+1; + if(x<=10) { + ICoord tmp = new Coord(x, temp.getY()); + while (x <= 10 && coord_touchees.contains(tmp)) { + if (x == 10) { + coordContiguAtemp.add(tmp); + x++; + } else { + coordContiguAtemp.add(tmp); + x++; + tmp = new Coord(x, temp.getY()); + } + } + } + + //Horizontale gauche + x = temp.getX()-1; + if(x>=1) { + ICoord tmp = new Coord(x, temp.getY()); + while (x >= 1 && coord_touchees.contains(tmp)) { + if (x == 1) { + coordContiguAtemp.add(tmp); + x--; + } else { + coordContiguAtemp.add(tmp); + x--; + tmp = new Coord(x,temp.getY()); + } + } + } + + //Verticale bas + int y = temp.getY()+1; + if(y <= 10) { + ICoord tmp = new Coord(temp.getX(), y); + while (y <= 10 && coord_touchees.contains(tmp)) { + if (y == 10) { + coordContiguAtemp.add(tmp); + y++; + } else { + coordContiguAtemp.add(tmp); + y++; + tmp = new Coord(temp.getX(),y); + } + } + } + + //Verticale Haut + + y = temp.getY()-1; + if(y >= 1) { + ICoord tmp = new Coord(temp.getX(), y); + while (y >= 1 && coord_touchees.contains(tmp)) { + if (y == 1) { + coordContiguAtemp.add(tmp); + y--; + } else { + coordContiguAtemp.add(tmp); + y--; + tmp = new Coord(temp.getX(),y); + } + } + } + + //Pour L'horizontale gauche + /* + x = temp.getX(); + tmp = new Coord(temp.getX()-1,temp.getY()); + while(x>=0 && coord_touchees.contains(tmp)){ + coordContiguAtemp.add(temp); + x--; + tmp = new Coord(tmp.getX()-1, temp.getY()); + } + */ + for(ICoord c : coordContiguAtemp){ + plateau.setBateauCoule(c); + } + + + /* + for(ICoord c: coord_touchees){ + boolean tempChanger = false; + //Verticale haut + if(c.getY()==temp.getY() && temp.getX()+1==c.getX()) { + plateau.setBateauCoule(c); + tempChanger = true; + temp = c; + System.out.println('X'); + } + //Horizontale droit + if(c.getX()==temp.getX() && (temp.getY()+1)==c.getY() && !tempChanger) { + plateau.setBateauCoule(c); + temp = c; + System.out.println('Y'); + } + } + + temp=coord; + for(ICoord c: coord_touchees){ + boolean tempChanger = false; + if(c.getY()==temp.getY() && temp.getX()-1==c.getX()) { + plateau.setBateauCoule(c); + temp=c; + tempChanger = true; + }if(c.getX()==temp.getX() && ((temp.getY()-1))==c.getY() && !tempChanger) { + plateau.setBateauCoule(c); + temp=c; + } + } + */ + + + + /*char axe = '0'; + List<ICoord> axeX = new ArrayList<>(); + List<ICoord> axeY = new ArrayList<>(); + for(ICoord c: coord_touchees){ + if(c.getY()==coord.getY()){ + axeY.add(c); + if (coord.getX()+1==c.getX() || coord.getX()-1==c.getX()) { + plateau.setBateauCoule(c); + axe = 'Y'; + } + }if(c.getX()==coord.getX()){ + axeX.add(c); + if((coord.getY()+10)%10==c.getY() || (((coord.getY()-10)%10)+10)==c.getY()) { + plateau.setBateauCoule(c); + axe = 'X'; + } + } + }*/ + /*if(axe=='Y'){ + axeY.sort(Comparator.comparingInt(ICoord::getX)); + for(ICoord c: axeY){ + if() + } + }if(axe=='X'){ + axeX.sort(new Comparator<ICoord>() { + @Override + public int compare(ICoord o1, ICoord o2) { + return o1.getY(); + } + }); + for(ICoord c: axeY){ + + } + }*/ + plateau.modifierAffichage("C'est coulé !"); plateau.setScore(score++); }else if (res==100){