diff --git a/ShipGenericDop.java b/ShipGenericDop.java index 4f847fb..585f5ed 100644 --- a/ShipGenericDop.java +++ b/ShipGenericDop.java @@ -1,7 +1,8 @@ import java.util.Random; +import java.util.ArrayList; public class ShipGenericDop { - private Object[] Ships; - private Object[] Decks; + private ArrayList Ships; + private ArrayList Decks; private int countShips; private int max_countShips; private int countDecks; @@ -12,8 +13,8 @@ public class ShipGenericDop { public ShipGenericDop(int _max_countShips, int _max_countDecks, int pictureWidth, int pictureHeight){ max_countShips = _max_countShips; max_countDecks = _max_countDecks; - Ships = new Object[max_countShips]; - Decks = new Object[max_countDecks]; + Ships = new ArrayList(max_countShips); + Decks = new ArrayList(max_countDecks); countShips = 0; countDecks = 0; _pictureWidth = pictureWidth; @@ -27,7 +28,7 @@ public class ShipGenericDop { if (countShips > max_countShips){ return false; } - Ships[countShips++] = ship; + Ships.add(countShips++, ship); return true; } public boolean AddDeck(U deck){ @@ -37,7 +38,7 @@ public class ShipGenericDop { if (countDecks > max_countDecks){ return false; } - Decks[countDecks++] = deck; + Decks.add(countDecks++, deck); return true; } public DrawingShip getObjectRandomShip(){ @@ -46,11 +47,11 @@ public class ShipGenericDop { } int i = rand.nextInt(countShips); int j = rand.nextInt(countDecks); - if(Ships[i] instanceof EntityContainerShip){ - return new DrawingContainerShip((EntityContainerShip)Ships[i], (IDecksDrawing)Decks[j], _pictureWidth, _pictureHeight); + if(Ships.get(i) instanceof EntityContainerShip){ + return new DrawingContainerShip((EntityContainerShip)Ships.get(i), (IDecksDrawing)Decks.get(j), _pictureWidth, _pictureHeight); } else{ - return new DrawingShip((EntityShip)Ships[i],_pictureWidth, _pictureHeight); + return new DrawingShip((EntityShip)Ships.get(i),_pictureWidth, _pictureHeight); } } }