First stage: Refactoring MapWithSetArtilleriesGeneric

This commit is contained in:
Сергей Полевой 2022-11-05 16:31:00 +04:00
parent 9c4f1d4327
commit 0ae6527361

View File

@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Iterator;
public class MapWithSetArtilleriesGeneric<T extends IDrawingObject, U extends AbstractMap> {
public final int _pictureWidth;
@ -12,7 +13,7 @@ public class MapWithSetArtilleriesGeneric<T extends IDrawingObject, U extends Ab
public MapWithSetArtilleriesGeneric(int picWidth, int picHeight, U map) {
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setArtilleries = new SetArtilleriesGeneric<T>(width * height);
_setArtilleries = new SetArtilleriesGeneric<>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
@ -36,13 +37,8 @@ public class MapWithSetArtilleriesGeneric<T extends IDrawingObject, U extends Ab
public Image showOnMap() {
shaking();
for (int i = 0; i < _setArtilleries.getCount(); i++)
{
var car = _setArtilleries.get(i);
if (car != null)
{
return _map.createMap(_pictureWidth, _pictureHeight, car);
}
for (T artillery : _setArtilleries.getArtilleries()) {
return _map.createMap(_pictureWidth, _pictureHeight, artillery);
}
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
}
@ -120,14 +116,12 @@ public class MapWithSetArtilleriesGeneric<T extends IDrawingObject, U extends Ab
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _setArtilleries.getCount(); i++)
int index = 0;
for (T artillery : _setArtilleries.getArtilleries())
{
var artillery = _setArtilleries.get(i);
if (artillery != null)
{
artillery.setObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
artillery.drawingObject(g);
}
artillery.setObject(index % width * _placeSizeWidth + 10, (height - 1 - index / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
artillery.drawingObject(g);
index++;
}
}
}