Compare commits

..

No commits in common. "e60990067a607496e40a9e9932864d9eeebeca12" and "9c4f1d43275f0ee207e8602cb70597525bdde32c" have entirely different histories.

8 changed files with 79 additions and 239 deletions

View File

@ -1,16 +1,12 @@
import java.awt.*;
public class DrawingObjectArtillery implements IDrawingObject {
private DrawingArtillery _artillery;
private DrawingArtillery _artillery = null;
public DrawingObjectArtillery(DrawingArtillery artillery) {
_artillery = artillery;
}
public DrawingArtillery getArtillery() {
return _artillery;
}
public float getStep() {
if (_artillery != null && _artillery.artillery != null) {
return _artillery.artillery.getStep();

View File

@ -90,12 +90,6 @@ public class FormArtillery extends JDialog {
});
}
public FormArtillery(DrawingArtillery artillery) {
this();
_artillery = artillery;
repaint();
}
public DrawingArtillery getSelectedArtillery() {
return selectedArtillery;
}

View File

@ -3,7 +3,7 @@
<grid id="27dc6" binding="paneArtilleries" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="649" height="532"/>
<xy x="20" y="20" width="613" height="400"/>
</constraints>
<properties/>
<border type="none"/>
@ -11,13 +11,13 @@
<grid id="fcfe1" binding="pictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="f232" binding="toolsGroup" layout-manager="GridLayoutManager" row-count="10" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="f232" binding="toolsGroup" layout-manager="GridLayoutManager" row-count="9" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@ -38,9 +38,25 @@
<grid row="0" column="1" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="352bc">
<constraints>
<grid row="5" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="6a0f5" class="javax.swing.JComboBox" binding="comboBoxMapSelector">
<constraints>
<grid row="1" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="Простая карта"/>
<item value="Лесная карта"/>
</model>
</properties>
</component>
<component id="52049" class="javax.swing.JButton" binding="buttonAddArtillery">
<constraints>
<grid row="2" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить артиллерию"/>
@ -48,7 +64,7 @@
</component>
<component id="2f9ed" class="javax.swing.JFormattedTextField" binding="textBoxPosition">
<constraints>
<grid row="3" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="3" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
@ -56,7 +72,7 @@
</component>
<component id="1dbb5" class="javax.swing.JButton" binding="buttonRemoveArtillery">
<constraints>
<grid row="4" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="4" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<actionCommand value=""/>
@ -65,7 +81,7 @@
</component>
<component id="4e6ca" class="javax.swing.JButton" binding="buttonShowStorage">
<constraints>
<grid row="5" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="5" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Посмотреть хранилище"/>
@ -73,7 +89,7 @@
</component>
<component id="51371" class="javax.swing.JButton" binding="buttonShowOnMap">
<constraints>
<grid row="6" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="6" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Посмотреть карту"/>
@ -81,7 +97,7 @@
</component>
<component id="fb3e4" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="8" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="7" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -96,7 +112,7 @@
</component>
<component id="328f6" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="9" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="8" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -110,7 +126,7 @@
</component>
<component id="4f2dc" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -125,7 +141,7 @@
</component>
<component id="bac06" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="9" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="8" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
@ -138,80 +154,6 @@
<text value=""/>
</properties>
</component>
<grid id="7448e" binding="mapsGroup" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="3bd55" class="javax.swing.JLabel" binding="mapsLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Карты"/>
</properties>
</component>
<hspacer id="b4c1d">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="6a0f5" class="javax.swing.JComboBox" binding="comboBoxMapSelector">
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="Простая карта"/>
<item value="Лесная карта"/>
</model>
</properties>
</component>
<component id="a344e" class="javax.swing.JTextField" binding="textFieldMapName">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="b8791" class="javax.swing.JButton" binding="buttonAddMap">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить карту"/>
</properties>
</component>
<component id="89547" class="javax.swing.JList" binding="listBoxMaps">
<constraints>
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="643d3" class="javax.swing.JButton" binding="buttonDeleteMap">
<constraints>
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Удалить карту"/>
</properties>
</component>
</children>
</grid>
<component id="490e6" class="javax.swing.JButton" binding="buttonShowDeleted">
<constraints>
<grid row="7" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Посмотреть удалённую артиллерию"/>
</properties>
</component>
</children>
</grid>
</children>

View File

@ -2,16 +2,14 @@ import javax.swing.*;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Optional;
import java.util.Stack;
public class FormMapWithSetArtilleries extends JFrame {
private JPanel pictureBox;
private JPanel toolsGroup;
private JLabel toolsLabel;
private JComboBox<String> comboBoxMapSelector;
private JComboBox comboBoxMapSelector;
private JButton buttonAddArtillery;
private JPanel paneArtilleries;
private JFormattedTextField textBoxPosition;
@ -22,27 +20,13 @@ public class FormMapWithSetArtilleries extends JFrame {
private JButton buttonLeft;
private JButton buttonRight;
private JButton buttonShowOnMap;
private JLabel mapsLabel;
private JTextField textFieldMapName;
private JButton buttonAddMap;
private JList<String> listBoxMaps;
private JPanel mapsGroup;
private JButton buttonDeleteMap;
private JButton buttonShowDeleted;
private Image bufferedImage;
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>() {{
put("Простая карта", new SimpleMap());
put("Лесная карта", new ForestMap());
}};
private final MapsCollection _mapsCollection;
private final Stack<IDrawingObject> deletedObjects = new Stack<>();
private MapWithSetArtilleriesGeneric<DrawingObjectArtillery, AbstractMap> _mapArtilleriesCollectionGeneric;
public FormMapWithSetArtilleries() {
this.setTitle("Artillery");
this.setContentPane(paneArtilleries);
this.setSize(640, 530);
this.setVisible(true);
try {
textBoxPosition.setFormatterFactory(new DefaultFormatterFactory(new MaskFormatter("##")));
@ -50,46 +34,22 @@ public class FormMapWithSetArtilleries extends JFrame {
e.printStackTrace();
}
_mapsCollection = new MapsCollection(pictureBox.getWidth(), pictureBox.getHeight());
comboBoxMapSelector.addActionListener(e -> {
AbstractMap map = switch (((JComboBox) e.getSource()).getSelectedItem().toString()) {
case "Простая карта" -> new SimpleMap();
case "Лесная карта" -> new ForestMap();
default -> null;
};
comboBoxMapSelector.removeAllItems();
for (var key : _mapsDict.keySet()) {
comboBoxMapSelector.addItem(key);
}
buttonAddMap.addActionListener(e -> {
if (comboBoxMapSelector.getSelectedIndex() == -1 || textFieldMapName.getText() == null || textFieldMapName.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "Не все данные заполнены", "Ошибка", JOptionPane.ERROR_MESSAGE);
return;
}
if (!_mapsDict.containsKey((String)comboBoxMapSelector.getSelectedItem())) {
JOptionPane.showMessageDialog(this, "Нет такой карты", "Ошибка", JOptionPane.ERROR_MESSAGE);
return;
}
_mapsCollection.addMap(textFieldMapName.getText(), _mapsDict.get((String)comboBoxMapSelector.getSelectedItem()));
reloadMaps();
});
buttonDeleteMap.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() == -1) {
return;
}
if (JOptionPane.showConfirmDialog(this, "Удалить карту " + listBoxMaps.getSelectedValue() + "?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
_mapsCollection.deleteMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse(""));
reloadMaps();
}
});
listBoxMaps.addListSelectionListener(e -> {
if (listBoxMaps.getSelectedValue() != null) {
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
repaint();
if (map != null) {
_mapArtilleriesCollectionGeneric = new MapWithSetArtilleriesGeneric<>(pictureBox.getWidth(), pictureBox.getHeight(), map);
} else {
_mapArtilleriesCollectionGeneric = null;
}
});
buttonAddArtillery.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() == -1) {
if (_mapArtilleriesCollectionGeneric == null) {
return;
}
@ -101,11 +61,11 @@ public class FormMapWithSetArtilleries extends JFrame {
dialog.setVisible(true);
if (dialog.getSelectedArtillery() != null) {
DrawingObjectArtillery artillery = new DrawingObjectArtillery(dialog.getSelectedArtillery());
if (_mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).addArtillery(artillery) != -1)
DrawingObjectArtillery car = new DrawingObjectArtillery(dialog.getSelectedArtillery());
if (_mapArtilleriesCollectionGeneric.addArtillery(car) != -1)
{
JOptionPane.showMessageDialog(this, "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
bufferedImage = _mapArtilleriesCollectionGeneric.showSet();
repaint();
}
else
@ -127,11 +87,9 @@ public class FormMapWithSetArtilleries extends JFrame {
int position = Integer.parseInt(text);
IDrawingObject deleted = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).removeArtilleryAt(position);
if (deleted != null) {
deletedObjects.push(deleted);
if (_mapArtilleriesCollectionGeneric.removeArtilleryAt(position) != null) {
JOptionPane.showMessageDialog(this, "Объект удалён", "Успех", JOptionPane.INFORMATION_MESSAGE);
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
bufferedImage = _mapArtilleriesCollectionGeneric.showSet();
repaint();
} else {
JOptionPane.showMessageDialog(this, "Не удалось удалить объект", "Провал", JOptionPane.INFORMATION_MESSAGE);
@ -139,72 +97,47 @@ public class FormMapWithSetArtilleries extends JFrame {
});
buttonShowStorage.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() == -1) {
if (_mapArtilleriesCollectionGeneric == null) {
return;
}
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showSet();
bufferedImage = _mapArtilleriesCollectionGeneric.showSet();
repaint();
});
buttonShowOnMap.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() == -1) {
if (_mapArtilleriesCollectionGeneric == null) {
return;
}
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).showOnMap();
bufferedImage = _mapArtilleriesCollectionGeneric.showOnMap();
repaint();
});
buttonShowDeleted.addActionListener(e -> {
if (!deletedObjects.empty()) {
DrawingObjectArtillery deleted = (DrawingObjectArtillery) deletedObjects.pop();
FormArtillery dialog = new FormArtillery(deleted == null ? null : deleted.getArtillery());
dialog.setSize(800, 500);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}
});
buttonLeft.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() != -1) {
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Left);
if (_mapArtilleriesCollectionGeneric != null) {
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Left);
repaint();
}
});
buttonRight.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() != -1) {
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Right);
if (_mapArtilleriesCollectionGeneric != null) {
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Right);
repaint();
}
});
buttonUp.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() != -1) {
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Up);
if (_mapArtilleriesCollectionGeneric != null) {
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Up);
repaint();
}
});
buttonDown.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() != -1) {
bufferedImage = _mapsCollection.getMap(Optional.ofNullable(listBoxMaps.getSelectedValue()).orElse("")).moveObject(Direction.Down);
if (_mapArtilleriesCollectionGeneric != null) {
bufferedImage = _mapArtilleriesCollectionGeneric.moveObject(Direction.Down);
repaint();
}
});
}
private void reloadMaps() {
int index = listBoxMaps.getSelectedIndex();
listBoxMaps.setListData(_mapsCollection.getKeys().toArray(new String[0]));
int size = listBoxMaps.getModel().getSize();
if (size > 0 && (index == -1 || index >= size)) {
listBoxMaps.setSelectedIndex(0);
} else if (index > -1 && index < size) {
listBoxMaps.setSelectedIndex(index);
}
}
@Override
public void paint(Graphics g) {
super.paint(g);

View File

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

View File

@ -1,33 +0,0 @@
import java.util.HashMap;
import java.util.Set;
public class MapsCollection {
private final HashMap<String, MapWithSetArtilleriesGeneric<IDrawingObject, AbstractMap>> _mapsStorage;
private final int _pictureWidth;
private final int _pictureHeight;
public Set<String> getKeys() {
return _mapsStorage.keySet();
}
public MapsCollection(int pictureWidth, int pictureHeight) {
_mapsStorage = new HashMap<>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void addMap(String name, AbstractMap map) {
if (!_mapsStorage.containsKey(name)) {
_mapsStorage.put(name, new MapWithSetArtilleriesGeneric<>(_pictureWidth, _pictureHeight, map));
}
}
public void deleteMap(String name) {
_mapsStorage.remove(name);
}
public MapWithSetArtilleriesGeneric<IDrawingObject, AbstractMap> getMap(String name) {
return _mapsStorage.getOrDefault(name, null);
}
}

View File

@ -2,7 +2,9 @@ import javax.swing.*;
public class Program {
public static void main(String[] args) {
FormMapWithSetArtilleries form = new FormMapWithSetArtilleries();
FormGallery form = new FormGallery();
form.setSize(320, 240);
form.setVisible(true);
form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}

View File

@ -20,7 +20,7 @@ public class SetArtilleriesGeneric<T> {
}
public int insert(T artillery, int position) {
if (position < 0 || position > getCount() || getCount() == _maxCount) {
if (position < 0 || position >= getCount() || getCount() == _maxCount) {
return -1;
}