Tsukanova I.V. HardLabWork3 #5
@ -139,7 +139,7 @@ public abstract class AbstractMap {
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawingObject.DrawningObject(gr);
|
||||
_drawingObject.DrawingObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,11 @@ public class DrawingAircraftCarrier extends DrawingWarship{
|
||||
Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, cabin, superEngine);
|
||||
}
|
||||
|
||||
public DrawingAircraftCarrier(EntityWarship warship, IDrawingObjectBlock additionalObject) {
|
||||
super(warship, additionalObject);
|
||||
Warship = warship;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics gr){
|
||||
if(!(Warship instanceof EntityAircraftCarrier))
|
||||
@ -79,4 +84,4 @@ public class DrawingAircraftCarrier extends DrawingWarship{
|
||||
g2.drawRect(_startPosX + 85, _startPosY + 13, 10, 14);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingMap extends JPanel{
|
||||
private final FormMap Map;
|
||||
private AbstractMap _abstractMap;
|
||||
BufferedImage bufferedImage;
|
||||
public DrawingMap(FormMap map){
|
||||
Map = map;
|
||||
_abstractMap = new SimpleMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
|
||||
private void SetData(DrawingWarship warship) {
|
||||
Random rnd = new Random();
|
||||
warship.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), getWidth(),getHeight());
|
||||
Map.toolBarLabelSpeed.setText("Color: " + warship.GetWarship().GetSpeed() + " ");
|
||||
Map.toolBarLabelWieght.setText("Weight: " + warship.GetWarship().GetWeight() + " ");
|
||||
Map.toolBarLabelColor.setText("Color: " + warship.GetWarship().GetBodyColor().getRed() + " " +
|
||||
warship.GetWarship().GetBodyColor().getGreen() + " " + warship.GetWarship().GetBodyColor().getBlue());
|
||||
bufferedImage = _abstractMap.CreateMap(750,550,new DrawingObjectWarship(warship));
|
||||
}
|
||||
//Создание обычного корабля
|
||||
public void CreateButtonAction(){
|
||||
Random rnd=new Random();
|
||||
DrawingWarship warship=new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(3));
|
||||
SetData(warship);
|
||||
}
|
||||
//Создание модифицированного корабля
|
||||
public void CreateModifButtonAction(){
|
||||
Random rnd = new Random();
|
||||
DrawingWarship warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData(warship);
|
||||
}
|
||||
|
||||
public void DirectionButtonAction(Direction side){
|
||||
if(_abstractMap != null){
|
||||
bufferedImage = _abstractMap.MoveObject(side);
|
||||
}
|
||||
}
|
||||
|
||||
public void ComboBoxSelectorMapAction(String name){
|
||||
switch (name){
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Вторая карта":
|
||||
_abstractMap = new LineMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawMap(Graphics g){
|
||||
g.drawImage(bufferedImage,0,0,null);
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ public class DrawingObjectWarship implements IDrawingObject {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawningObject(Graphics g) {
|
||||
public void DrawingObject(Graphics g) {
|
||||
_warship.DrawTransport(g);
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,11 @@ public class DrawingWarship {
|
||||
_warshipHeight = warshipHeight;
|
||||
}
|
||||
|
||||
public DrawingWarship(EntityWarship warship,IDrawingObjectBlock block){
|
||||
Warship = warship;
|
||||
Blocks = block;
|
||||
}
|
||||
|
||||
public int BlockRandom(){
|
||||
Random rnd = new Random();
|
||||
int count = rnd.nextInt(0,3);
|
||||
|
137
src/FormMap.form
137
src/FormMap.form
@ -1,137 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" 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>
|
||||
<xy x="20" y="20" width="897" height="504"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<toolbar id="ced8" binding="toolBar">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="7c17c" class="javax.swing.JLabel" binding="toolBarLabelSpeed">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Speed"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a7229" class="javax.swing.JLabel" binding="toolBarLabelWieght">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Weight"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7c70" class="javax.swing.JLabel" binding="toolBarLabelColor">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<text value="Color"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</toolbar>
|
||||
<grid id="3b625" binding="drawPanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" 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="2" 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>
|
||||
<component id="c54f8" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="a1d54">
|
||||
<constraints>
|
||||
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="4c365">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="aaec9" class="javax.swing.JButton" binding="buttonCreateModif">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Modificarion"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c7660" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="3" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e0470" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a6de2" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="633e1" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e1523" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="0" column="3" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
@ -1,84 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FormMap extends JFrame{
|
||||
DrawingMap map = new DrawingMap(this);
|
||||
private JPanel mainPanel;
|
||||
private JToolBar toolBar;
|
||||
public JLabel toolBarLabelSpeed;
|
||||
public JLabel toolBarLabelWieght;
|
||||
public JLabel toolBarLabelColor;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonCreateModif;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JComboBox ComboBoxSelectorMap;
|
||||
private JPanel drawPanel;
|
||||
|
||||
public FormMap(){
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent() {
|
||||
setContentPane(mainPanel);
|
||||
setTitle("Warship");
|
||||
setSize(900, 700);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
|
||||
Icon iconUp = new ImageIcon("src\\Images\\ArrowUp.jpg");
|
||||
buttonUp.setIcon(iconUp);
|
||||
Icon iconDown = new ImageIcon("src\\Images\\ArrowDown.jpg");
|
||||
buttonDown.setIcon(iconDown);
|
||||
Icon iconLeft = new ImageIcon("src\\Images\\ArrowLeft.jpg");
|
||||
buttonLeft.setIcon(iconLeft);
|
||||
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
||||
buttonRight.setIcon(iconRight);
|
||||
|
||||
buttonCreate.addActionListener(e -> {
|
||||
map.CreateButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonCreateModif.addActionListener(e -> {
|
||||
map.CreateModifButtonAction();
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Up);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonLeft.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Left);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonRight.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Right);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
buttonDown.addActionListener(e -> {
|
||||
map.DirectionButtonAction(Direction.Down);
|
||||
ReDraw();
|
||||
});
|
||||
|
||||
ComboBoxSelectorMap.addActionListener(e -> {
|
||||
map.ComboBoxSelectorMapAction(Objects.requireNonNull(ComboBoxSelectorMap.getSelectedItem()).toString());
|
||||
ReDraw();
|
||||
});
|
||||
}
|
||||
|
||||
private void ReDraw()
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D) drawPanel.getGraphics();
|
||||
graphics.clearRect(0, 0, drawPanel.getWidth(), drawPanel.getHeight());
|
||||
drawPanel.paintComponents(graphics);
|
||||
map.DrawMap(graphics);
|
||||
}
|
||||
}
|
158
src/FormMapWithSetWarships.form
Normal file
158
src/FormMapWithSetWarships.form
Normal file
@ -0,0 +1,158 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetWarships">
|
||||
<grid id="27dc6" binding="mainPanel" 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="884" height="479"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="ae53a" 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="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="727" height="24"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="815b1">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="716" height="11"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="16c60" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="11" column-count="3" 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"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="bevel-lowered" title="Tools" title-justification="1" title-position="2">
|
||||
<font/>
|
||||
</border>
|
||||
<children>
|
||||
<component id="d5ebd" class="javax.swing.JComboBox" binding="СomboBoxSelectorMap">
|
||||
<constraints>
|
||||
<grid row="0" column="0" 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="9e5dd" class="javax.swing.JButton" binding="ButtonAddWarship">
|
||||
<constraints>
|
||||
<grid row="2" column="0" 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="Add warship"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="16e2c" class="javax.swing.JButton" binding="ButtonRemoveWarship">
|
||||
<constraints>
|
||||
<grid row="4" column="0" 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="Remove warship"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1fc5b" class="javax.swing.JButton" binding="ButtonShowStorage">
|
||||
<constraints>
|
||||
<grid row="6" column="0" 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="Show storage"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3dd40" class="javax.swing.JButton" binding="ButtonShowOnMap">
|
||||
<constraints>
|
||||
<grid row="7" column="0" 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="Show map"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="608d7" class="javax.swing.JTextField" binding="TextBoxPosition">
|
||||
<constraints>
|
||||
<grid row="3" column="0" 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>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="2ea34" class="javax.swing.JButton" binding="ButtonRight">
|
||||
<constraints>
|
||||
<grid row="10" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="daf62" class="javax.swing.JButton" binding="ButtonDown">
|
||||
<constraints>
|
||||
<grid row="10" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="76b8a" class="javax.swing.JButton" binding="ButtonLeft">
|
||||
<constraints>
|
||||
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="675d4" class="javax.swing.JButton" binding="ButtonUp">
|
||||
<constraints>
|
||||
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="aa195">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<vspacer id="fa6fc">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<vspacer id="f6c4c">
|
||||
<constraints>
|
||||
<grid row="8" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
166
src/FormMapWithSetWarships.java
Normal file
166
src/FormMapWithSetWarships.java
Normal file
@ -0,0 +1,166 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class FormMapWithSetWarships extends JFrame{
|
||||
private JPanel mainPanel;
|
||||
private JPanel PictureBox;
|
||||
private JPanel GroupBoxTools;
|
||||
private JComboBox СomboBoxSelectorMap;
|
||||
private JButton ButtonAddWarship;
|
||||
private JButton ButtonRemoveWarship;
|
||||
private JButton ButtonShowStorage;
|
||||
private JButton ButtonShowOnMap;
|
||||
private JTextField TextBoxPosition;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonUp;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonLeft;
|
||||
private Image bufferedImage;
|
||||
private MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap> _mapWarshipsCollectionGeneric;
|
||||
|
||||
public FormMapWithSetWarships(){
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
if (bufferedImage != null) {
|
||||
PictureBox.paintComponents(bufferedImage.getGraphics());
|
||||
PictureBox.getGraphics().drawImage(bufferedImage, 0, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeComponent(){
|
||||
setContentPane(mainPanel);
|
||||
setTitle("Warship");
|
||||
setSize(1000, 693);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
|
||||
Icon iconUp = new ImageIcon("src\\Images\\ArrowUp.jpg");
|
||||
ButtonUp.setIcon(iconUp);
|
||||
Icon iconDown = new ImageIcon("src\\Images\\ArrowDown.jpg");
|
||||
ButtonDown.setIcon(iconDown);
|
||||
Icon iconLeft = new ImageIcon("src\\Images\\ArrowLeft.jpg");
|
||||
ButtonLeft.setIcon(iconLeft);
|
||||
Icon iconRight = new ImageIcon("src\\Images\\ArrowRight.jpg");
|
||||
ButtonRight.setIcon(iconRight);
|
||||
|
||||
СomboBoxSelectorMap.addActionListener(e -> {
|
||||
AbstractMap map = switch (СomboBoxSelectorMap.getSelectedItem().toString()) {
|
||||
case "Простая карта" -> new SimpleMap();
|
||||
case "Преграды-линии" -> new LineMap();
|
||||
default -> null;
|
||||
};
|
||||
if( map != null){
|
||||
_mapWarshipsCollectionGeneric = new MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>(
|
||||
PictureBox.getWidth(), PictureBox.getHeight(), map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapWarshipsCollectionGeneric = null;
|
||||
}
|
||||
});
|
||||
|
||||
ButtonAddWarship.addActionListener(e -> {
|
||||
if(_mapWarshipsCollectionGeneric == null){
|
||||
return;
|
||||
}
|
||||
FormWarshipCreator warshipCreator = new FormWarshipCreator();
|
||||
warshipCreator.setSize(1200,700);
|
||||
warshipCreator.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||
warshipCreator.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
warshipCreator.setVisible(true);
|
||||
if (warshipCreator.getSelectedWarship() != null) {
|
||||
DrawingObjectWarship warship = new DrawingObjectWarship(warshipCreator.getSelectedWarship());
|
||||
|
||||
if (_mapWarshipsCollectionGeneric.Plus(warship) >= 0) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Не удалось добавить объект", "Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ButtonRemoveWarship.addActionListener(e -> {
|
||||
String text = TextBoxPosition.getText();
|
||||
if (text == null || _mapWarshipsCollectionGeneric == null || text.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int result = JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Удалить объект?",
|
||||
"Удаление",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
if (result == JOptionPane.NO_OPTION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Integer.parseInt(text);
|
||||
if (_mapWarshipsCollectionGeneric.Minus(pos) != null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Объект удален","Успех",JOptionPane.INFORMATION_MESSAGE);
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"Не удалось удалить объект","Ошибка",JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
ButtonShowStorage.addActionListener(e -> {
|
||||
if(_mapWarshipsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowSet();
|
||||
repaint();
|
||||
});
|
||||
|
||||
ButtonShowOnMap.addActionListener(e -> {
|
||||
if (_mapWarshipsCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.ShowOnMap();
|
||||
repaint();
|
||||
});
|
||||
|
||||
ButtonUp.addActionListener(e -> {
|
||||
if (_mapWarshipsCollectionGeneric != null) {
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Up);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
ButtonDown.addActionListener(e -> {
|
||||
if (_mapWarshipsCollectionGeneric != null) {
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Down);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
ButtonRight.addActionListener(e -> {
|
||||
if (_mapWarshipsCollectionGeneric != null) {
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Right);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
ButtonLeft.addActionListener(e -> {
|
||||
if (_mapWarshipsCollectionGeneric != null) {
|
||||
bufferedImage = _mapWarshipsCollectionGeneric.MoveObject(Direction.Left);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="dfecd" binding="drawPanel" layout-manager="GridLayoutManager" row-count="3" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="dfecd" binding="drawPanel" layout-manager="GridLayoutManager" row-count="3" column-count="7" 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="3" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
@ -44,7 +44,7 @@
|
||||
</component>
|
||||
<component id="55933" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -56,7 +56,7 @@
|
||||
</component>
|
||||
<component id="bb79e" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -69,7 +69,7 @@
|
||||
</component>
|
||||
<component id="82cc1" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -81,7 +81,7 @@
|
||||
</component>
|
||||
<component id="32714" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
@ -91,6 +91,14 @@
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b9b11" class="javax.swing.JButton" binding="buttonSelect">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Select"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<toolbar id="3697c" binding="toolBar">
|
||||
|
@ -1,14 +1,16 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormWarship extends JFrame {
|
||||
private DrawingWarship _warship;
|
||||
public DrawingWarship selectedWarship;
|
||||
public DrawingWarship getSelectedCar(){
|
||||
return selectedWarship;
|
||||
}
|
||||
public boolean DialogResult = false;
|
||||
private JPanel mainPanel;
|
||||
private JPanel drawPanel;
|
||||
private JButton buttonCreate;
|
||||
@ -21,6 +23,7 @@ public class FormWarship extends JFrame {
|
||||
private JLabel toolBarLabelWieght;
|
||||
private JLabel toolBarLabelColor;
|
||||
private JButton buttonCreateModif;
|
||||
private JButton buttonSelect;
|
||||
|
||||
public FormWarship(){
|
||||
InitializeComponent();
|
||||
@ -64,61 +67,50 @@ public class FormWarship extends JFrame {
|
||||
buttonRight.setIcon(iconRight);
|
||||
|
||||
//кнопка добавления объекта
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(3));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
buttonCreate.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingWarship(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(3));
|
||||
SetData();
|
||||
Draw();
|
||||
});
|
||||
|
||||
//добавление модифицированного объекта
|
||||
buttonCreateModif.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
Draw();
|
||||
buttonCreateModif.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
_warship = new DrawingAircraftCarrier(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonSelect.addActionListener(e -> {
|
||||
if(_warship != null){
|
||||
selectedWarship =_warship;
|
||||
DialogResult = true;
|
||||
}
|
||||
});
|
||||
|
||||
buttonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Left);
|
||||
Draw();
|
||||
}
|
||||
buttonLeft.addActionListener(e -> {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Left);
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Right);
|
||||
Draw();
|
||||
}
|
||||
buttonRight.addActionListener(e -> {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Right);
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Up);
|
||||
Draw();
|
||||
}
|
||||
buttonUp.addActionListener(e -> {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Up);
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Down);
|
||||
Draw();
|
||||
}
|
||||
buttonDown.addActionListener(e -> {
|
||||
if (_warship != null) _warship.MoveTransport(Direction.Down);
|
||||
Draw();
|
||||
});
|
||||
|
||||
mainPanel.addComponentListener(new ComponentAdapter() {
|
||||
|
205
src/FormWarshipCreator.form
Normal file
205
src/FormWarshipCreator.form
Normal file
@ -0,0 +1,205 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormWarshipCreator">
|
||||
<grid id="27dc6" binding="PictureBox" 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="838" height="633"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="b8cad" binding="SettingsPanel" layout-manager="GridLayoutManager" row-count="9" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<opaque value="true"/>
|
||||
</properties>
|
||||
<border type="etched" title="Settings"/>
|
||||
<children>
|
||||
<grid id="41669" binding="BlocksTypePanel" layout-manager="GridLayoutManager" row-count="3" 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="6" 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="etched" title="Blocks type"/>
|
||||
<children>
|
||||
<component id="40e8a" class="javax.swing.JRadioButton" binding="RoundRectangleFormRadioButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Round Rectangle blocks"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="339d6" class="javax.swing.JRadioButton" binding="RoundFormRadioButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Round blocks"/>
|
||||
<text value="Round blocks"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ad164" class="javax.swing.JRadioButton" binding="RectangleFormRadioButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Rectangle blocks"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="15d71" layout-manager="GridLayoutManager" row-count="2" 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="8" 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>
|
||||
<component id="a819c" class="javax.swing.JButton" binding="CreateButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Create"/>
|
||||
<text value="Create"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="821c8" class="javax.swing.JButton" binding="SelectButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Select"/>
|
||||
<text value="Select"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="6c05e">
|
||||
<constraints>
|
||||
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="21a40" binding="CountOfBlocksPanel" layout-manager="GridLayoutManager" row-count="3" 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="4" 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="etched" title="Number of blocks"/>
|
||||
<children>
|
||||
<component id="e77e" class="javax.swing.JRadioButton" binding="SixRadioButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="6"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="90578" class="javax.swing.JRadioButton" binding="FourRadioButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="4"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d9b90" class="javax.swing.JRadioButton" binding="TwoRadioButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="2"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="f0649">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<vspacer id="18811">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<vspacer id="1084d">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="7b5d7" binding="TypePanel" 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="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="etched" title="Type"/>
|
||||
<children>
|
||||
<component id="b0d54" class="javax.swing.JComboBox" binding="comboBoxType">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="Warship"/>
|
||||
<item value="AircraftCarrier"/>
|
||||
</model>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="5220b" binding="ModificationPanel" layout-manager="GridLayoutManager" row-count="3" 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="2" 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="etched" title="Modification"/>
|
||||
<children>
|
||||
<component id="c96ee" class="javax.swing.JCheckBox" binding="EngineCheckBox">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Super engine"/>
|
||||
<text value="Super engine"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="385c6" class="javax.swing.JCheckBox" binding="CabinCheckBox">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Cabin"/>
|
||||
<text value="Cabin"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="63fa9" class="javax.swing.JCheckBox" binding="AreaCheckBox">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Landing area"/>
|
||||
<text value="Landing area"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="2bb5c">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
140
src/FormWarshipCreator.java
Normal file
140
src/FormWarshipCreator.java
Normal file
@ -0,0 +1,140 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormWarshipCreator extends JDialog{
|
||||
private JPanel PictureBox;
|
||||
private JPanel SettingsPanel;
|
||||
private JPanel BlocksTypePanel;
|
||||
private JPanel CountOfBlocksPanel;
|
||||
private JPanel ModificationPanel;
|
||||
private JPanel TypePanel;
|
||||
private JRadioButton RoundRectangleFormRadioButton;
|
||||
private JRadioButton RoundFormRadioButton;
|
||||
private JRadioButton RectangleFormRadioButton;
|
||||
private JRadioButton SixRadioButton;
|
||||
private JRadioButton FourRadioButton;
|
||||
private JRadioButton TwoRadioButton;
|
||||
private JButton CreateButton;
|
||||
private JButton SelectButton;
|
||||
private JCheckBox EngineCheckBox;
|
||||
private JCheckBox CabinCheckBox;
|
||||
private JCheckBox AreaCheckBox;
|
||||
private JComboBox comboBoxType;
|
||||
private BlockCount _block = null;
|
||||
private IDrawingObjectBlock objectBlock = null;
|
||||
private final WarshipCreatorGeneric<EntityWarship,IDrawingObjectBlock> warshipCreator =new WarshipCreatorGeneric<>(40,40);
|
||||
private DrawingWarship _warship;
|
||||
private DrawingWarship selectedWarship;
|
||||
private boolean isModified = false;
|
||||
|
||||
public FormWarshipCreator(){
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
Graphics2D g2d = (Graphics2D) PictureBox.getGraphics();
|
||||
if (_warship != null) {
|
||||
_warship.DrawTransport(g2d);
|
||||
}
|
||||
}
|
||||
|
||||
public DrawingWarship getSelectedWarship() {
|
||||
return selectedWarship;
|
||||
}
|
||||
|
||||
private void InitializeComponent(){
|
||||
setContentPane(PictureBox);
|
||||
setTitle("Warship");
|
||||
setResizable(false);
|
||||
setSize(1000, 600);
|
||||
|
||||
//Определение типа объекта
|
||||
comboBoxType.addItemListener(e -> isModified = e.getItem().toString().equals("AircraftCarrier"));
|
||||
|
||||
//количество блоков
|
||||
TwoRadioButton.addActionListener(e -> {
|
||||
_block = BlockCount.TwoBlocks;
|
||||
});
|
||||
FourRadioButton.addActionListener(e -> {
|
||||
_block = BlockCount.FourBlocks;
|
||||
});
|
||||
SixRadioButton.addActionListener(e -> {
|
||||
_block = BlockCount.SixBlocks;
|
||||
});
|
||||
|
||||
//Квадратная форма блоков
|
||||
RectangleFormRadioButton.addActionListener(e -> {
|
||||
if(_block == null) return;
|
||||
|
||||
objectBlock = new DrawingBlocks(_block);
|
||||
objectBlock.SetBlockCount(_block.GetBlockCount());
|
||||
warshipCreator.AddBlock(objectBlock);
|
||||
});
|
||||
|
||||
//Круглая форма блоков
|
||||
RoundFormRadioButton.addActionListener(e -> {
|
||||
if(_block ==null){
|
||||
return;
|
||||
}
|
||||
objectBlock = new DrawingRoundBlocks(_block);
|
||||
objectBlock.SetBlockCount(_block.GetBlockCount());
|
||||
warshipCreator.AddBlock(objectBlock);
|
||||
});
|
||||
|
||||
//Закруглено-квадратная форма блоков
|
||||
RoundRectangleFormRadioButton.addActionListener(e -> {
|
||||
if(_block == null){
|
||||
return;
|
||||
}
|
||||
objectBlock = new DrawingRoundBlocks(_block);
|
||||
objectBlock.SetBlockCount(_block.GetBlockCount());
|
||||
warshipCreator.AddBlock(objectBlock);
|
||||
});
|
||||
|
||||
CreateButton.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
if (_block != null && objectBlock != null) {
|
||||
Color color = JColorChooser.showDialog(this, "Choose color", Color.WHITE);
|
||||
|
||||
if (isModified) {
|
||||
Color additionalColor = JColorChooser.showDialog(this, "Choose color", Color.GRAY);
|
||||
|
||||
warshipCreator.AddWarship(
|
||||
new EntityAircraftCarrier(
|
||||
rnd.nextInt(10, 300),
|
||||
rnd.nextFloat(10, 3000),
|
||||
color,
|
||||
additionalColor,
|
||||
AreaCheckBox.isSelected(),
|
||||
CabinCheckBox.isSelected(),
|
||||
EngineCheckBox.isSelected()
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
warshipCreator.AddWarship(
|
||||
new EntityWarship(
|
||||
rnd.nextInt(10, 300),
|
||||
rnd.nextFloat(10, 3000),
|
||||
color)
|
||||
);
|
||||
}
|
||||
|
||||
_warship = warshipCreator.NewWarshipCreating();
|
||||
_warship.SetPosition(
|
||||
rnd.nextInt(20),
|
||||
rnd.nextInt(20),
|
||||
PictureBox.getWidth(),
|
||||
PictureBox.getHeight());
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
SelectButton.addActionListener(e -> {
|
||||
selectedWarship = _warship;
|
||||
dispose();
|
||||
});
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ public interface IDrawingObject {
|
||||
// Изменение направления пермещения объекта
|
||||
void MoveObject(Direction direction);
|
||||
// Отрисовка объекта
|
||||
void DrawningObject(Graphics g);
|
||||
void DrawingObject(Graphics g);
|
||||
// Получение текущей позиции объекта
|
||||
// /Left, Right, Top, Bottom)
|
||||
float[] GetCurrentPosition();
|
||||
|
@ -1,6 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new FormMap();
|
||||
new FormMapWithSetWarships();
|
||||
}
|
||||
|
||||
}
|
||||
|
123
src/MapWithSetWarshipsGeneric.java
Normal file
123
src/MapWithSetWarshipsGeneric.java
Normal file
@ -0,0 +1,123 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class MapWithSetWarshipsGeneric <T extends IDrawingObject,U extends AbstractMap> {
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
private final int _placeSizeWidth = 120;
|
||||
private final int _placeSizeHeight = 50;
|
||||
private final SetWarshipsGeneric<T> _setWarships;
|
||||
private final U _map;
|
||||
|
||||
public MapWithSetWarshipsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight/_placeSizeHeight;
|
||||
_setWarships = new SetWarshipsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public int Plus(T warship)
|
||||
{
|
||||
return _setWarships.Insert(warship);
|
||||
}
|
||||
|
||||
public T Minus(int position)
|
||||
{
|
||||
return _setWarships.Remove(position);
|
||||
}
|
||||
|
||||
public Image ShowSet()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureWidth,BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics gr = bmp.getGraphics();
|
||||
DrawBackground(gr);
|
||||
DrawWarship(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public Image ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setWarships.getCount(); i++)
|
||||
{
|
||||
T warship = _setWarships.Get(i);
|
||||
if (warship != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, warship);
|
||||
}
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, 1);
|
||||
}
|
||||
|
||||
public Image MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, 1);
|
||||
}
|
||||
|
||||
public void Shaking()
|
||||
{
|
||||
int j = _setWarships.getCount() - 1;
|
||||
for (int i = 0; i < _setWarships.getCount(); i++)
|
||||
{
|
||||
if (_setWarships.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var warship = _setWarships.Get(j);
|
||||
if (warship != null)
|
||||
{
|
||||
_setWarships.Insert(warship, i);
|
||||
_setWarships.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics gr)
|
||||
{
|
||||
Graphics2D g = (Graphics2D)gr;
|
||||
|
||||
Color brush=Color.BLACK;
|
||||
Stroke penWide = new BasicStroke(3);
|
||||
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j <= _pictureHeight / _placeSizeHeight ; ++j)
|
||||
{
|
||||
g.setColor(brush);
|
||||
g.setStroke(penWide);
|
||||
g.drawLine(i * _placeSizeWidth + 20, j * _placeSizeHeight+2, i * _placeSizeWidth + (int)(_placeSizeWidth*0.8), j * _placeSizeHeight+2);
|
||||
g.drawLine(i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight/2);
|
||||
g.drawLine(i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2, i * _placeSizeWidth+ (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawWarship(Graphics gr)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < _setWarships.getCount(); i++)
|
||||
{
|
||||
if (_setWarships.Get(i) != null)
|
||||
{
|
||||
_setWarships.Get(i).SetObject(i % width * _placeSizeWidth, ((height - 1 - i / width) * _placeSizeHeight) + 6, _pictureWidth, _pictureHeight);
|
||||
_setWarships.Get(i).DrawingObject(gr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
src/SetWarshipsGeneric.java
Normal file
57
src/SetWarshipsGeneric.java
Normal file
@ -0,0 +1,57 @@
|
||||
public class SetWarshipsGeneric<T extends Object>{
|
||||
private final Object[] _places;
|
||||
|
||||
public int getCount() {
|
||||
return _places.length;
|
||||
}
|
||||
|
||||
public SetWarshipsGeneric(int count)
|
||||
{
|
||||
_places = new Object[count];
|
||||
}
|
||||
|
||||
public int Insert(T warship)
|
||||
{
|
||||
return Insert(warship,0);
|
||||
}
|
||||
|
||||
public int Insert(T warship, int position)
|
||||
{
|
||||
if (position < 0 || position >= getCount())
|
||||
return -1;
|
||||
|
||||
int empty = -1;
|
||||
for (int i = position + 1; i < getCount(); i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
empty = i;
|
||||
}
|
||||
if (empty == -1)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
for (int i = empty; i > position; i--)
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = warship;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= getCount() || position < 0 || _places[position] == null)
|
||||
return null;
|
||||
|
||||
T deleted =(T) _places[position];
|
||||
_places[position] = null;
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= getCount() || position < 0)
|
||||
return null;
|
||||
|
||||
return (T) _places[position];
|
||||
}
|
||||
}
|
43
src/WarshipCreatorGeneric.java
Normal file
43
src/WarshipCreatorGeneric.java
Normal file
@ -0,0 +1,43 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class WarshipCreatorGeneric <T extends EntityWarship, U extends IDrawingObjectBlock>{
|
||||
private final ArrayList<T> Warships;
|
||||
private final ArrayList<U> Blocks;
|
||||
private int WarshipsCount = 0;
|
||||
private int BlocksCount = 0;
|
||||
public WarshipCreatorGeneric(int warshipsCount, int blocksCount){
|
||||
Warships = new ArrayList<>(warshipsCount);
|
||||
Blocks = new ArrayList<>(blocksCount);
|
||||
}
|
||||
|
||||
public int AddWarship(T warship){
|
||||
|
||||
if(WarshipsCount <= Warships.size()){
|
||||
Warships.add(warship);
|
||||
WarshipsCount++;
|
||||
return WarshipsCount - 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int AddBlock(U block){
|
||||
eegov
commented
Методы должны были быть полиморфные Методы должны были быть полиморфные
|
||||
if(BlocksCount <= Blocks.size()){
|
||||
Blocks.add(block);
|
||||
BlocksCount++;
|
||||
return BlocksCount - 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public DrawingWarship NewWarshipCreating()
|
||||
{
|
||||
Random rand=new Random();
|
||||
T warship = (T)Warships.get(rand.nextInt(WarshipsCount));
|
||||
U block = (U)Blocks.get(rand.nextInt(BlocksCount));
|
||||
|
||||
if(warship instanceof EntityAircraftCarrier){
|
||||
return new DrawingAircraftCarrier(warship, block);
|
||||
}
|
||||
return new DrawingWarship(warship,block);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Методы должны были быть полиморфные