mbFinal
This commit is contained in:
parent
9c43a295f5
commit
aeaba7615e
@ -1,7 +1,8 @@
|
||||
import java.util.Random;
|
||||
import java.util.ArrayList;
|
||||
public class ShipGenericDop<T extends EntityShip, U extends IDecksDrawing> {
|
||||
private Object[] Ships;
|
||||
private Object[] Decks;
|
||||
private ArrayList<T> Ships;
|
||||
private ArrayList<U> Decks;
|
||||
private int countShips;
|
||||
private int max_countShips;
|
||||
private int countDecks;
|
||||
@ -12,8 +13,8 @@ public class ShipGenericDop<T extends EntityShip, U extends IDecksDrawing> {
|
||||
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<T>(max_countShips);
|
||||
Decks = new ArrayList<U>(max_countDecks);
|
||||
countShips = 0;
|
||||
countDecks = 0;
|
||||
_pictureWidth = pictureWidth;
|
||||
@ -27,7 +28,7 @@ public class ShipGenericDop<T extends EntityShip, U extends IDecksDrawing> {
|
||||
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<T extends EntityShip, U extends IDecksDrawing> {
|
||||
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<T extends EntityShip, U extends IDecksDrawing> {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user