Merge branch 'FourthLabWork' into UpdateFourthLabWork
This commit is contained in:
commit
515c1d7f04
1
.gitignore
vendored
1
.gitignore
vendored
@ -34,3 +34,4 @@ dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
|
||||
/.vs/PIbd-22_DozorovaAA_ArmoredVehicle_Hard/v17/.suo
|
||||
|
BIN
.vs/slnx.sqlite
BIN
.vs/slnx.sqlite
Binary file not shown.
@ -136,24 +136,28 @@ public abstract class AbstractMap {
|
||||
}
|
||||
int x = random.nextInt(0, 10);
|
||||
int y = random.nextInt(0, 10);
|
||||
drawingObject.SetObject(x, y, width, height);
|
||||
|
||||
HashMap<String, Float> hashMap = drawingObject.GetCurrentPosition();
|
||||
float left = hashMap.get("Left");
|
||||
float right = hashMap.get("Right");
|
||||
float top = hashMap.get("Top");
|
||||
float bottom = hashMap.get("Bottom");
|
||||
|
||||
for (int i = (int)(x / size_x); i <= (int) (right / size_x); i++)
|
||||
{
|
||||
for (int j = (int)(y / size_y); j <= (int) (bottom / size_y); j++)
|
||||
int beginI = (int)(x / size_x);
|
||||
int endI = (int)(hashMap.get("Right") / size_x);
|
||||
|
||||
int beginJ = (int)(y / size_y);
|
||||
int endJ = (int)(hashMap.get("Bottom") / size_y);
|
||||
|
||||
for (int i = beginI; i <= endI; i++)
|
||||
{
|
||||
if (map[i][j] == _barrier)
|
||||
for(int j = beginJ; j <= endJ; j++)
|
||||
{
|
||||
return false;
|
||||
if(map[i][j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
drawingObject.SetObject(x, y, width, height);
|
||||
return true;
|
||||
}
|
||||
private Image DrawMapWithObject()
|
||||
|
@ -24,7 +24,7 @@
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="PicturePanel" pref="336" max="32767" attributes="0"/>
|
||||
<Component id="PicturePanel" pref="457" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="InstrumentPanel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
@ -72,18 +72,13 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="22" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="MapComboBox" pref="165" max="32767" attributes="0"/>
|
||||
<Component id="AddMachineButton" max="32767" attributes="0"/>
|
||||
<Component id="TextBoxPosition" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="DeleteButton" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="StoreButton" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="StoreButton" alignment="0" pref="177" max="32767" attributes="0"/>
|
||||
<Component id="MapButton" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
@ -108,15 +103,51 @@
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="49" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="MapNameTextField" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="DeleteMapButton" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="AddMapButton" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="MapComboBox" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jScrollPane1" min="-2" pref="167" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="21" max="-2" attributes="0"/>
|
||||
<Component id="MapNameTextField" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="MapComboBox" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="AddMapButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="9" max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" min="-2" pref="113" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="DeleteMapButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="AddMachineButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="TextBoxPosition" min="-2" max="-2" attributes="0"/>
|
||||
@ -126,7 +157,7 @@
|
||||
<Component id="StoreButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="MapButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="28" max="32767" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="25" max="-2" attributes="0"/>
|
||||
<Component id="UpButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
@ -265,6 +296,43 @@
|
||||
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new java.awt.Button()"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="java.awt.TextField" name="MapNameTextField">
|
||||
</Component>
|
||||
<Component class="java.awt.Button" name="AddMapButton">
|
||||
<Properties>
|
||||
<Property name="label" type="java.lang.String" value="Добавить карту"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="AddMapButtonMouseClicked"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="java.awt.Button" name="DeleteMapButton">
|
||||
<Properties>
|
||||
<Property name="label" type="java.lang.String" value="Удалить карту"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="DeleteMapButtonMouseClicked"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JList" name="MapList">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
|
||||
<StringArray count="0"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
|
@ -3,19 +3,31 @@ import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.HashMap;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
|
||||
public class FormMapWithSetMachine extends javax.swing.JFrame {
|
||||
private Image img;
|
||||
private MapWithSetArmoredCarsGeneric<DrawingObject, AbstractMap> _mapCollectionGeneric;
|
||||
private MapsCollection _mapCollection;
|
||||
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>() {{
|
||||
put("Простая карта", new SimpleMap());
|
||||
put("Вертикальная карта", new VerticalMap());
|
||||
put("Горизонтальная карта", new HorizontalMap());
|
||||
}};
|
||||
public FormMapWithSetMachine() {
|
||||
initComponents();
|
||||
LeftButton.setLabel("<");
|
||||
RightButton.setLabel(">");
|
||||
UpButton.setLabel("/\\");
|
||||
DownButton.setLabel("\\/");
|
||||
MapComboBox.removeAllItems();
|
||||
for (String elem : _mapsDict.keySet()) {
|
||||
MapComboBox.addItem(elem);
|
||||
}
|
||||
_mapCollection = new MapsCollection(PicturePanel.getWidth(), PicturePanel.getHeight());
|
||||
}
|
||||
|
||||
|
||||
@ -36,6 +48,11 @@ private Image img;
|
||||
DownButton = new java.awt.Button();
|
||||
LeftButton = new java.awt.Button();
|
||||
UpButton = new java.awt.Button();
|
||||
MapNameTextField = new java.awt.TextField();
|
||||
AddMapButton = new java.awt.Button();
|
||||
DeleteMapButton = new java.awt.Button();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
MapList = new javax.swing.JList<>();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
@ -124,21 +141,33 @@ private Image img;
|
||||
}
|
||||
});
|
||||
|
||||
AddMapButton.setLabel("Добавить карту");
|
||||
AddMapButton.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||
AddMapButtonMouseClicked(evt);
|
||||
}
|
||||
});
|
||||
|
||||
DeleteMapButton.setLabel("Удалить карту");
|
||||
DeleteMapButton.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||
DeleteMapButtonMouseClicked(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jScrollPane1.setViewportView(MapList);
|
||||
|
||||
javax.swing.GroupLayout InstrumentPanelLayout = new javax.swing.GroupLayout(InstrumentPanel);
|
||||
InstrumentPanel.setLayout(InstrumentPanelLayout);
|
||||
InstrumentPanelLayout.setHorizontalGroup(
|
||||
InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(InstrumentPanelLayout.createSequentialGroup()
|
||||
.addComponent(jLabel1)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addGroup(InstrumentPanelLayout.createSequentialGroup()
|
||||
.addGap(22, 22, 22)
|
||||
.addGroup(InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(MapComboBox, 0, 165, Short.MAX_VALUE)
|
||||
.addComponent(AddMachineButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(TextBoxPosition, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(DeleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(StoreButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(StoreButton, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
|
||||
.addComponent(MapButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, InstrumentPanelLayout.createSequentialGroup()
|
||||
@ -156,14 +185,43 @@ private Image img;
|
||||
.addComponent(DownButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(29, 29, 29))))
|
||||
.addGap(49, 49, 49))
|
||||
.addGroup(InstrumentPanelLayout.createSequentialGroup()
|
||||
.addComponent(jLabel1)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, InstrumentPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(MapNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
.addGroup(InstrumentPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(DeleteMapButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
.addGroup(InstrumentPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(AddMapButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(InstrumentPanelLayout.createSequentialGroup()
|
||||
.addComponent(MapComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
.addGroup(InstrumentPanelLayout.createSequentialGroup()
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 0, Short.MAX_VALUE))))
|
||||
);
|
||||
InstrumentPanelLayout.setVerticalGroup(
|
||||
InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(InstrumentPanelLayout.createSequentialGroup()
|
||||
.addComponent(jLabel1)
|
||||
.addGap(21, 21, 21)
|
||||
.addComponent(MapNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(MapComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(AddMapButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(9, 9, 9)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(DeleteMapButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(AddMachineButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(TextBoxPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
@ -173,7 +231,7 @@ private Image img;
|
||||
.addComponent(StoreButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(MapButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
|
||||
.addGap(25, 25, 25)
|
||||
.addComponent(UpButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(1, 1, 1)
|
||||
.addGroup(InstrumentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
@ -191,7 +249,7 @@ private Image img;
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(PicturePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
|
||||
.addComponent(PicturePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(InstrumentPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
);
|
||||
@ -221,38 +279,37 @@ private Image img;
|
||||
}//GEN-LAST:event_UpButtonMouseClicked
|
||||
|
||||
private void MapComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MapComboBoxActionPerformed
|
||||
AbstractMap map = null;
|
||||
String name = (String) MapComboBox.getSelectedItem();
|
||||
switch (name)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Горизонтальная карта":
|
||||
map = new HorizontalMap();
|
||||
break;
|
||||
case "Вертикальная карта":
|
||||
map = new VerticalMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapCollectionGeneric = new MapWithSetArmoredCarsGeneric<DrawingObject, AbstractMap>(
|
||||
PicturePanel.getWidth(), PicturePanel.getHeight(), map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapCollectionGeneric = null;
|
||||
}
|
||||
// AbstractMap map = null;
|
||||
// String name = (String) MapComboBox.getSelectedItem();
|
||||
// switch (name)
|
||||
// {
|
||||
// case "Простая карта":
|
||||
// map = new SimpleMap();
|
||||
// break;
|
||||
// case "Горизонтальная карта":
|
||||
// map = new HorizontalMap();
|
||||
// break;
|
||||
// case "Вертикальная карта":
|
||||
// map = new VerticalMap();
|
||||
// break;
|
||||
// }
|
||||
// if (map != null)
|
||||
// {
|
||||
// _mapCollection = new MapsCollection(PicturePanel.getWidth(), PicturePanel.getHeight());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _mapCollection = null;
|
||||
// }
|
||||
}//GEN-LAST:event_MapComboBoxActionPerformed
|
||||
|
||||
private void AddMachineButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddMachineButtonMouseClicked
|
||||
if (_mapCollectionGeneric == null)
|
||||
if (_mapCollection == null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не выбрана карта");
|
||||
return;
|
||||
}
|
||||
PolimorphForm form = new PolimorphForm();
|
||||
MapForm form = new MapForm();
|
||||
form.setVisible(true);
|
||||
form.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
@ -260,12 +317,14 @@ private Image img;
|
||||
if (form.getSelectedCar() == null)
|
||||
return;
|
||||
DrawingObject machine = new DrawingObject(form.getSelectedCar());
|
||||
if (_mapCollectionGeneric.add(machine) > -1)
|
||||
if (_mapCollection.Get(MapList.getSelectedValue().toString()).add(machine) != -1)
|
||||
{
|
||||
if (form.DialogResult) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
img = _mapCollectionGeneric.ShowSet();
|
||||
img = _mapCollection.Get(MapList.getSelectedValue().toString()).ShowSet();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||
@ -284,10 +343,10 @@ private Image img;
|
||||
"Удаление", JOptionPane.YES_NO_OPTION);
|
||||
if (res == JOptionPane.YES_OPTION) {
|
||||
int pos = Integer.parseInt(TextBoxPosition.getText());
|
||||
if (_mapCollectionGeneric.remove(pos) != null)
|
||||
if (_mapCollection.Get(MapList.getSelectedValue().toString()).remove(pos) != null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||
img = _mapCollectionGeneric.ShowSet();
|
||||
img = _mapCollection.Get(MapList.getSelectedValue().toString()).ShowSet();
|
||||
Draw();
|
||||
}
|
||||
else
|
||||
@ -298,30 +357,70 @@ private Image img;
|
||||
}//GEN-LAST:event_DeleteButtonMouseClicked
|
||||
|
||||
private void StoreButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_StoreButtonMouseClicked
|
||||
if (_mapCollectionGeneric == null)
|
||||
if (_mapCollection == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
img = _mapCollectionGeneric.ShowSet();
|
||||
img = _mapCollection.Get(MapList.getSelectedValue().toString()).ShowSet();
|
||||
Draw();
|
||||
}//GEN-LAST:event_StoreButtonMouseClicked
|
||||
|
||||
private void MapButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MapButtonMouseClicked
|
||||
if (_mapCollectionGeneric == null)
|
||||
if (_mapCollection == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
img = _mapCollectionGeneric.ShowOnMap();
|
||||
img = _mapCollection.Get(MapList.getSelectedValue().toString()).ShowOnMap();
|
||||
Draw();
|
||||
}//GEN-LAST:event_MapButtonMouseClicked
|
||||
|
||||
private void AddMapButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddMapButtonMouseClicked
|
||||
if (MapComboBox.getSelectedIndex() == -1 || MapNameTextField.getText().isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "Не все данные заполнены", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.containsKey(MapComboBox.getSelectedItem())) {
|
||||
JOptionPane.showMessageDialog(null, "Нет такой карты", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
_mapCollection.AddMap(MapNameTextField.getText(), _mapsDict.get(MapComboBox.getSelectedItem().toString()));
|
||||
ReloadMaps();
|
||||
}//GEN-LAST:event_AddMapButtonMouseClicked
|
||||
private void ReloadMaps() {
|
||||
int index = MapList.getSelectedIndex();
|
||||
|
||||
DefaultListModel<String> model = (DefaultListModel<String>) MapList.getModel();
|
||||
model.removeAllElements();
|
||||
for (int i = 0; i < _mapCollection.Keys.size(); i++) {
|
||||
model.addElement(_mapCollection.Keys.get(i));
|
||||
}
|
||||
|
||||
if (MapList.getModel().getSize() > 0 &&
|
||||
(index == -1 || index >= MapList.getModel().getSize())) {
|
||||
MapList.setSelectedIndex(0);
|
||||
} else if (MapList.getModel().getSize() > 0 &&
|
||||
index > -1 && index < MapList.getModel().getSize()) {
|
||||
MapList.setSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
private void DeleteMapButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DeleteMapButtonMouseClicked
|
||||
if (MapList.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
if (JOptionPane.showConfirmDialog(null, "Удалить карту " + MapList.getSelectedValue().toString() + "?",
|
||||
"Удаление", JOptionPane.YES_NO_OPTION) == 0) {
|
||||
_mapCollection.DelMap(MapList.getSelectedValue().toString());
|
||||
ReloadMaps();
|
||||
}
|
||||
}//GEN-LAST:event_DeleteMapButtonMouseClicked
|
||||
public void Move(String name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "UpButton" -> img = _mapCollectionGeneric.MoveObject(Direction.Up);
|
||||
case "DownButton" -> img = _mapCollectionGeneric.MoveObject(Direction.Down);
|
||||
case "LeftButton" -> img = _mapCollectionGeneric.MoveObject(Direction.Left);
|
||||
case "RightButton" -> img = _mapCollectionGeneric.MoveObject(Direction.Right);
|
||||
case "UpButton" -> img = _mapCollection.Get(MapList.getSelectedValue().toString()).MoveObject(Direction.Up);
|
||||
case "DownButton" -> img = _mapCollection.Get(MapList.getSelectedValue().toString()).MoveObject(Direction.Down);
|
||||
case "LeftButton" -> img =_mapCollection.Get(MapList.getSelectedValue().toString()).MoveObject(Direction.Left);
|
||||
case "RightButton" -> img = _mapCollection.Get(MapList.getSelectedValue().toString()).MoveObject(Direction.Right);
|
||||
}
|
||||
|
||||
Draw();
|
||||
@ -367,17 +466,22 @@ private Image img;
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private java.awt.Button AddMachineButton;
|
||||
private java.awt.Button AddMapButton;
|
||||
private java.awt.Button DeleteButton;
|
||||
private java.awt.Button DeleteMapButton;
|
||||
private java.awt.Button DownButton;
|
||||
private javax.swing.JPanel InstrumentPanel;
|
||||
private java.awt.Button LeftButton;
|
||||
private java.awt.Button MapButton;
|
||||
private javax.swing.JComboBox<String> MapComboBox;
|
||||
private javax.swing.JList<String> MapList;
|
||||
private java.awt.TextField MapNameTextField;
|
||||
private javax.swing.JPanel PicturePanel;
|
||||
private java.awt.Button RightButton;
|
||||
private java.awt.Button StoreButton;
|
||||
private java.awt.TextField TextBoxPosition;
|
||||
private java.awt.Button UpButton;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ public class MapForm extends JFrame{
|
||||
|
||||
private DrawingArmoredVehicle _ArmoredVehicle;
|
||||
private DrawingArmoredVehicle SelectedMachine;
|
||||
public boolean DialogResult = false;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
@ -197,7 +198,6 @@ public class MapForm extends JFrame{
|
||||
}//GEN-LAST:event_CreateButtonMouseClicked
|
||||
public void SetData()
|
||||
{
|
||||
|
||||
Random rnd = new Random();
|
||||
_ArmoredVehicle.SetPosition(rnd.nextInt(0, 100), rnd.nextInt(25, 200),
|
||||
DrawPanel.getWidth(), DrawPanel.getHeight());
|
||||
@ -260,6 +260,7 @@ public class MapForm extends JFrame{
|
||||
private void SetButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SetButtonMouseClicked
|
||||
if (_ArmoredVehicle != null) {
|
||||
SelectedMachine = _ArmoredVehicle;
|
||||
DialogResult = true;
|
||||
dispose();
|
||||
}
|
||||
}//GEN-LAST:event_SetButtonMouseClicked
|
||||
|
@ -1,7 +1,7 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
||||
public class MapWithSetMachineGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
||||
|
||||
private int _pictureWidth;
|
||||
|
||||
@ -15,7 +15,7 @@ public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends Ab
|
||||
|
||||
private U _map;
|
||||
|
||||
public MapWithSetArmoredCarsGeneric(int picWidth, int picHeight, U map)
|
||||
public MapWithSetMachineGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
@ -47,14 +47,9 @@ public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends Ab
|
||||
public Image ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setCars.getCount(); i++)
|
||||
{
|
||||
var car = _setCars.Get(i);
|
||||
if (car != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
|
||||
}
|
||||
}
|
||||
for (var machine : _setCars) {
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, machine);
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_BGR);
|
||||
}
|
||||
|
||||
@ -111,13 +106,13 @@ public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends Ab
|
||||
|
||||
private void DrawArmoredCars(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _setCars.getCount(); i++)
|
||||
{
|
||||
if (_setCars.Get(i) != null) {
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
for(int i = 0; i<_setCars.getCount(); i++)
|
||||
{
|
||||
if (_setCars.Get(i) != null) {
|
||||
_setCars.Get(i).SetObject(i % width * _placeSizeWidth + 5, i / width * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setCars.Get(i).DrawingObject((Graphics2D) g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
87
ArmoredVehicle/src/MapsCollection.java
Normal file
87
ArmoredVehicle/src/MapsCollection.java
Normal file
@ -0,0 +1,87 @@
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class MapsCollection {
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
Map <String, MapWithSetMachineGeneric<DrawingObject, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
public ArrayList<String> Keys;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new HashMap<String, MapWithSetMachineGeneric<DrawingObject, AbstractMap>>();
|
||||
Keys = new ArrayList<String>(_mapStorages.keySet());
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(String name, AbstractMap map)
|
||||
{
|
||||
if (Keys.contains(name))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Такая карта уже есть");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var NewElem = new MapWithSetMachineGeneric<DrawingObject, AbstractMap>(
|
||||
_pictureWidth, _pictureHeight, map);
|
||||
_mapStorages.put(name, NewElem);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(String name)
|
||||
{
|
||||
if (Keys.contains(name))
|
||||
{
|
||||
_mapStorages.remove(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Такой карты нет");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к парковке
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetMachineGeneric<DrawingObject, AbstractMap> Get(String ind)
|
||||
{
|
||||
if(Keys.contains(ind))
|
||||
{
|
||||
return _mapStorages.get(ind);
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "Такой карты нет");
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +1,41 @@
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SetArmoredCarsGeneric<T> {
|
||||
private T[] _places;
|
||||
|
||||
public class SetArmoredCarsGeneric<T> implements Iterable<T>{
|
||||
private ArrayList<T> _places;
|
||||
private int _MaxCount;
|
||||
public SetArmoredCarsGeneric(int count)
|
||||
{
|
||||
_places = (T[]) new Object[count];
|
||||
_MaxCount = count;
|
||||
_places = new ArrayList<>(_MaxCount);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return _places != null ? _places.length : 0;
|
||||
return _places.isEmpty() ? 0 : _places.size();
|
||||
}
|
||||
|
||||
public int Insert(T armoredCar)
|
||||
{
|
||||
return Insert(armoredCar, 0);
|
||||
if(_places.size()+1 <= _MaxCount) return Insert(armoredCar, 0);
|
||||
else return -1;
|
||||
}
|
||||
|
||||
public int Insert(T armoredCar, int position)
|
||||
{
|
||||
if (position < 0 || position >= getCount())
|
||||
if ((position < 0 || position > getCount()))
|
||||
return -1;
|
||||
|
||||
if (!(_places[position] == null))
|
||||
if(_places.isEmpty())
|
||||
{
|
||||
_places.add(armoredCar);
|
||||
return 0;
|
||||
}
|
||||
if (!(_places.get(position) == null) && !_places.isEmpty())
|
||||
{
|
||||
int index_empty = -1;
|
||||
// поиск первого пустого элемента
|
||||
for (int i = position + 1; i < getCount(); i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
if (_places.get(i) == null)
|
||||
{
|
||||
index_empty = i;
|
||||
}
|
||||
@ -40,20 +46,22 @@ public class SetArmoredCarsGeneric<T> {
|
||||
{
|
||||
for (int i = index_empty; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
_places.set(i, _places.get(i-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
_places[position] = armoredCar;
|
||||
_places.add(position, armoredCar);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= getCount())
|
||||
if (position < 0 || position >= getCount() || _places.get(position) == null)
|
||||
return null;
|
||||
T armoredCar = _places[position];
|
||||
_places[position] = null;
|
||||
T armoredCar = _places.get(position);
|
||||
_places.set(position, null);
|
||||
|
||||
return armoredCar;
|
||||
}
|
||||
|
||||
@ -61,6 +69,16 @@ public class SetArmoredCarsGeneric<T> {
|
||||
{
|
||||
if (position < 0 || position >= getCount())
|
||||
return null;
|
||||
return _places[position];
|
||||
return _places.get(position);
|
||||
}
|
||||
public void Set(int position, T value){
|
||||
if (position < 0 || position + 1 >= getCount())
|
||||
return;
|
||||
Insert(value, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return _places.iterator();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user