From 0fbf323909f99d699f3f3cd996a9372d4cc69d8c Mon Sep 17 00:00:00 2001 From: e206034a <tristan.maisonneuve@etu.univ-nantes.fr> Date: Wed, 23 Jun 2021 15:23:49 +0200 Subject: [PATCH] Fennetre modif compo equip --- src/modele/info1/ships/CreationB.java | 5 ----- src/modele/info1/ships/Ship.java | 4 ++++ src/vue/FenetreConnexion.java | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/modele/info1/ships/CreationB.java b/src/modele/info1/ships/CreationB.java index 162bdba..62f573a 100644 --- a/src/modele/info1/ships/CreationB.java +++ b/src/modele/info1/ships/CreationB.java @@ -50,7 +50,6 @@ public class CreationB { switch (taille) { case 1: if (pays[0]!=0) { - pays[0]--; try { Submarine s = new Submarine("s", co[0]); return s; @@ -61,7 +60,6 @@ public class CreationB { } case 2: if (pays[1]!=0) { - pays[1]--; try { Destroyer d = new Destroyer("d", co[0], co[1]); return d; @@ -72,7 +70,6 @@ public class CreationB { } case 3: if (pays[2]!=0) { - pays[2]--; try { Cruiser c = new Cruiser("c", co[0], co[1]); return c; @@ -83,7 +80,6 @@ public class CreationB { } case 4: if (pays[3]!=0) { - pays[3]--; try { Battleship b = new Battleship("b", co[0], co[1]); return b; @@ -94,7 +90,6 @@ public class CreationB { } case 5: if (pays[4]!=0) { - pays[4]--; try { AircraftCarrier a = new AircraftCarrier("a", co[0], co[1]); return a; diff --git a/src/modele/info1/ships/Ship.java b/src/modele/info1/ships/Ship.java index 64235d2..fd2689e 100644 --- a/src/modele/info1/ships/Ship.java +++ b/src/modele/info1/ships/Ship.java @@ -105,6 +105,10 @@ public abstract class Ship implements IShip { return -1; } + public ShipCategory gettheCategory(){ + return getCategory(); + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/vue/FenetreConnexion.java b/src/vue/FenetreConnexion.java index ff093ea..cb3c5dd 100644 --- a/src/vue/FenetreConnexion.java +++ b/src/vue/FenetreConnexion.java @@ -5,6 +5,7 @@ import info1.network.Player; import info1.ships.BadCoordException; import info1.ships.CoordsBadShipException; import info1.ships.ICoord; +import info1.ships.ShipCategory; import modele.info1.ships.Bouttons; import modele.info1.ships.Coord; import modele.info1.ships.CreationB; @@ -14,6 +15,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.Arrays; import java.util.List; import java.util.function.BiPredicate; @@ -100,6 +102,20 @@ public class FenetreConnexion extends JFrame { final CreationB c = new CreationB(co[0],co[1],pays); try {if(c.TestCreation()!=null){ if(flotte.add(c.TestCreation())==0){ + c.TestCreation().gettheCategory(); + ShipCategory s = c.TestCreation().gettheCategory(); + if(s==ShipCategory.SUBMARINE){ + pays[0]--; + } if (s==ShipCategory.DESTROYER) { + pays[1]--; + } if (s==ShipCategory.CRUISER) { + pays[2]--; + } if (s==ShipCategory.BATTLESHIP) { + pays[3]--; + } if (s==ShipCategory.AIRCRAFT_CARRIER) { + pays[4]--; + } + System.out.println(Arrays.toString(pays)); System.out.println(flotte.getShips()); List<ICoord> listec = c.TestCreation().getCoords(); for(int i=0;i<100;i++){ @@ -199,6 +215,7 @@ public class FenetreConnexion extends JFrame { bouttons[i].getButton().setEnabled(true); } flotte = new NavyFleet(); + System.out.println(Arrays.toString(pays)); } }); @@ -214,6 +231,7 @@ public class FenetreConnexion extends JFrame { bouttons[i].getButton().setEnabled(true); } flotte = new NavyFleet(); + System.out.println(Arrays.toString(pays)); } }); -- GitLab