Недоделанная 2 лаба
This commit is contained in:
parent
843de80fbb
commit
ebb84c09de
@ -1,29 +1,29 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="AntiAircraftGun">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="AntiAircraftGun">
|
||||||
<grid id="27dc6" binding="panelAntiAircraftGun" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="panelAntiAircraftGun" layout-manager="GridLayoutManager" row-count="5" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="41" y="20" width="624" height="340"/>
|
<xy x="41" y="20" width="810" height="380"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<component id="f9412" class="javax.swing.JButton" binding="buttonCreate">
|
<component id="f9412" class="javax.swing.JButton" binding="buttonCreateGun">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="4" 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>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Создать"/>
|
<text value="Создать установку"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<vspacer id="bf8a3">
|
<vspacer id="bf8a3">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
<grid row="1" 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>
|
</constraints>
|
||||||
</vspacer>
|
</vspacer>
|
||||||
<component id="9c76c" class="javax.swing.JButton" binding="buttonDown">
|
<component id="9c76c" class="javax.swing.JButton" binding="buttonDown">
|
||||||
<constraints>
|
<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"/>
|
<grid row="4" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value=""/>
|
<text value=""/>
|
||||||
@ -31,7 +31,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="4edcf" class="javax.swing.JButton" binding="buttonLeft">
|
<component id="4edcf" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" 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="4" 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>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<hideActionText value="false"/>
|
<hideActionText value="false"/>
|
||||||
@ -41,7 +41,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="40000" class="javax.swing.JButton" binding="buttonRight">
|
<component id="40000" class="javax.swing.JButton" binding="buttonRight">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="4" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value=""/>
|
<text value=""/>
|
||||||
@ -49,7 +49,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="ab0ea" class="javax.swing.JButton" binding="buttonUp">
|
<component id="ab0ea" class="javax.swing.JButton" binding="buttonUp">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" 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="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value=""/>
|
<text value=""/>
|
||||||
@ -57,9 +57,36 @@
|
|||||||
</component>
|
</component>
|
||||||
<hspacer id="c1d4a">
|
<hspacer id="c1d4a">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="4" 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>
|
</constraints>
|
||||||
</hspacer>
|
</hspacer>
|
||||||
|
<component id="cb31c" class="javax.swing.JButton" binding="buttonCreateAntiAircraftGun">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" 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="Создать зенитную установку"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="699cc" class="javax.swing.JButton" binding="buttonStep">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="5" 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="Шаг"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<vspacer id="cec6d">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="5" 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="96b8a" class="javax.swing.JComboBox" binding="comboBoxStrategy">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,18 +1,27 @@
|
|||||||
|
import Drawings.DirectionType;
|
||||||
|
import Drawings.DrawingAntiAircraftGun;
|
||||||
|
import Drawings.DrawingGun;
|
||||||
|
import Drawings.EnumerateWheels;
|
||||||
|
import MovementStrategy.*;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Форма
|
* Форма
|
||||||
*/
|
*/
|
||||||
public class AntiAircraftGun extends JFrame {
|
public class AntiAircraftGun extends JFrame {
|
||||||
|
/**
|
||||||
|
* Стратегия перемещения
|
||||||
|
*/
|
||||||
|
private AbstractStrategy abstractStrategy;
|
||||||
/**
|
/**
|
||||||
* Объект сущности зенитной установки
|
* Объект сущности зенитной установки
|
||||||
*/
|
*/
|
||||||
private DrawingAntiAircraftGun _drawingAntiAircraftGun;
|
private DrawingGun _drawingGun;
|
||||||
/**
|
/**
|
||||||
* Панель
|
* Панель
|
||||||
*/
|
*/
|
||||||
@ -20,7 +29,7 @@ public class AntiAircraftGun extends JFrame {
|
|||||||
/**
|
/**
|
||||||
* Кнопка создания
|
* Кнопка создания
|
||||||
*/
|
*/
|
||||||
private JButton buttonCreate;
|
private JButton buttonCreateGun;
|
||||||
/**
|
/**
|
||||||
* Кнопка движения вниз
|
* Кнопка движения вниз
|
||||||
*/
|
*/
|
||||||
@ -37,6 +46,9 @@ public class AntiAircraftGun extends JFrame {
|
|||||||
* Кнопка движения вправо
|
* Кнопка движения вправо
|
||||||
*/
|
*/
|
||||||
private JButton buttonRight;
|
private JButton buttonRight;
|
||||||
|
private JButton buttonCreateAntiAircraftGun;
|
||||||
|
private JButton buttonStep;
|
||||||
|
private JComboBox comboBoxStrategy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Метод отрисовки
|
* Метод отрисовки
|
||||||
@ -45,11 +57,12 @@ public class AntiAircraftGun extends JFrame {
|
|||||||
*/
|
*/
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
super.paint(g);
|
super.paint(g);
|
||||||
if (_drawingAntiAircraftGun == null) {
|
if (_drawingGun == null) {
|
||||||
System.out.println("Значение пустое, я ничего не нарисовал");
|
System.out.println("Значение пустое, я ничего не нарисовал");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_drawingAntiAircraftGun.DrawTransport(g);
|
System.out.println(_drawingGun.getClass().getSimpleName());
|
||||||
|
_drawingGun.DrawTransport(g);
|
||||||
System.out.println("Ура, я что-то нарисовал");
|
System.out.println("Ура, я что-то нарисовал");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,9 +72,10 @@ public class AntiAircraftGun extends JFrame {
|
|||||||
public AntiAircraftGun() {
|
public AntiAircraftGun() {
|
||||||
add(panelAntiAircraftGun);
|
add(panelAntiAircraftGun);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setSize(600, 600);
|
setSize(800, 800);
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
Graphics g = getGraphics().create();
|
Graphics g = getGraphics().create();
|
||||||
|
abstractStrategy = null;
|
||||||
Icon iconDown = new ImageIcon("AntiAirCraftGun\\src\\Resources\\Down123.jpg");
|
Icon iconDown = new ImageIcon("AntiAirCraftGun\\src\\Resources\\Down123.jpg");
|
||||||
Icon iconUp = new ImageIcon("AntiAirCraftGun\\src\\Resources\\up123.jpg");
|
Icon iconUp = new ImageIcon("AntiAirCraftGun\\src\\Resources\\up123.jpg");
|
||||||
Icon iconLeft = new ImageIcon("AntiAirCraftGun\\src\\Resources\\left123.jpg");
|
Icon iconLeft = new ImageIcon("AntiAirCraftGun\\src\\Resources\\left123.jpg");
|
||||||
@ -70,42 +84,33 @@ public class AntiAircraftGun extends JFrame {
|
|||||||
buttonUp.setIcon(iconUp);
|
buttonUp.setIcon(iconUp);
|
||||||
buttonRight.setIcon(iconRight);
|
buttonRight.setIcon(iconRight);
|
||||||
buttonLeft.setIcon(iconLeft);
|
buttonLeft.setIcon(iconLeft);
|
||||||
_drawingAntiAircraftGun = new DrawingAntiAircraftGun();
|
comboBoxStrategy.addItem("К центру");
|
||||||
buttonCreate.addActionListener(new ActionListener() {
|
comboBoxStrategy.addItem("К краю");
|
||||||
|
buttonCreateGun.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
System.out.println("Я нажал на кнопку");
|
System.out.println("Я нажал на кнопку");
|
||||||
System.out.println(e.paramString());
|
System.out.println(e.paramString());
|
||||||
Random random = new Random();
|
CreateObj(g, "EntityGun");
|
||||||
|
|
||||||
_drawingAntiAircraftGun.Init(
|
|
||||||
random.nextInt(10, 100),
|
|
||||||
random.nextInt(10, 1000),
|
|
||||||
new Color(random.nextInt(0, 255), random.nextInt(0, 255), random.nextInt(0, 255)),
|
|
||||||
new Color(random.nextInt(0, 255), random.nextInt(0, 255), random.nextInt(0, 255)),
|
|
||||||
random.nextBoolean(),
|
|
||||||
random.nextBoolean(),
|
|
||||||
EnumerateWheels.getRandomEnumerateWheels()
|
|
||||||
|
|
||||||
);
|
|
||||||
_drawingAntiAircraftGun.SetPictureSize(
|
|
||||||
panelAntiAircraftGun.getWidth(),
|
|
||||||
panelAntiAircraftGun.getHeight()
|
|
||||||
);
|
|
||||||
_drawingAntiAircraftGun.SetPosition(
|
|
||||||
random.nextInt(50, 150),
|
|
||||||
random.nextInt(50, 150)
|
|
||||||
);
|
|
||||||
paint(g);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (_drawingAntiAircraftGun == null) {
|
buttonCreateAntiAircraftGun.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
System.out.println("Я нажал на кнопку");
|
||||||
|
System.out.println(actionEvent.paramString());
|
||||||
|
CreateObj(g, "EntityAntiAircraftGun");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (_drawingGun == null) {
|
||||||
|
System.out.println("Это выход из формы");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
System.out.println("Все нормально, идем дальше");
|
||||||
buttonDown.addActionListener(new ActionListener() {
|
buttonDown.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
boolean result = _drawingAntiAircraftGun.MoveTransport(DirectionType.Down);
|
boolean result = _drawingGun.MoveTransport(DirectionType.Down);
|
||||||
if (result) {
|
if (result) {
|
||||||
paint(g);
|
paint(g);
|
||||||
System.out.println(actionEvent.paramString());
|
System.out.println(actionEvent.paramString());
|
||||||
@ -115,7 +120,7 @@ public class AntiAircraftGun extends JFrame {
|
|||||||
buttonUp.addActionListener(new ActionListener() {
|
buttonUp.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Up);
|
_drawingGun.MoveTransport(DirectionType.Up);
|
||||||
paint(g);
|
paint(g);
|
||||||
System.out.println(actionEvent.paramString());
|
System.out.println(actionEvent.paramString());
|
||||||
}
|
}
|
||||||
@ -123,7 +128,7 @@ public class AntiAircraftGun extends JFrame {
|
|||||||
buttonLeft.addActionListener(new ActionListener() {
|
buttonLeft.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Left);
|
_drawingGun.MoveTransport(DirectionType.Left);
|
||||||
paint(g);
|
paint(g);
|
||||||
System.out.println(actionEvent.paramString());
|
System.out.println(actionEvent.paramString());
|
||||||
}
|
}
|
||||||
@ -131,10 +136,85 @@ public class AntiAircraftGun extends JFrame {
|
|||||||
buttonRight.addActionListener(new ActionListener() {
|
buttonRight.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Right);
|
_drawingGun.MoveTransport(DirectionType.Right);
|
||||||
paint(g);
|
paint(g);
|
||||||
System.out.println(actionEvent.paramString());
|
System.out.println(actionEvent.paramString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
buttonStep.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
if (_drawingGun == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.isEnabled()) {
|
||||||
|
abstractStrategy = null;
|
||||||
|
switch (comboBoxStrategy.getSelectedIndex()) {
|
||||||
|
case 0: {
|
||||||
|
abstractStrategy = new MoveToCenter();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
abstractStrategy = new MoveToBorder();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (abstractStrategy == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
abstractStrategy.SetData(new MoveableGun(_drawingGun),
|
||||||
|
panelAntiAircraftGun.getWidth(), panelAntiAircraftGun.getHeight());
|
||||||
|
}
|
||||||
|
if (abstractStrategy == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
comboBoxStrategy.setEnabled(false);
|
||||||
|
abstractStrategy.MakeStep();
|
||||||
|
paint(g);
|
||||||
|
if (abstractStrategy.GetStatus() == StrategyStatus.Finish) {
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateObj(Graphics g, String type) {
|
||||||
|
Random random = new Random();
|
||||||
|
switch (type) {
|
||||||
|
case "EntityAntiAircraftGun": {
|
||||||
|
System.out.println("Я зашле внутрь зенитной установик");
|
||||||
|
_drawingGun =
|
||||||
|
new DrawingAntiAircraftGun(
|
||||||
|
random.nextInt(100, 300),
|
||||||
|
random.nextInt(1000, 3000),
|
||||||
|
new Color(random.nextInt(0, 255), random.nextInt(0, 255), random.nextInt(0, 255)),
|
||||||
|
new Color(random.nextInt(0, 255), random.nextInt(0, 255), random.nextInt(0, 255)),
|
||||||
|
random.nextBoolean(),
|
||||||
|
random.nextBoolean(),
|
||||||
|
EnumerateWheels.getRandomEnumerateWheels()
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "EntityGun": {
|
||||||
|
_drawingGun = new DrawingGun(
|
||||||
|
random.nextInt(100, 300),
|
||||||
|
random.nextInt(1000, 3000),
|
||||||
|
new Color(random.nextInt(0, 255), random.nextInt(0, 255), random.nextInt(0, 255)),
|
||||||
|
EnumerateWheels.getRandomEnumerateWheels()
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
System.out.println("А здесь мы начинаем рисовать");
|
||||||
|
_drawingGun.SetPictureSize(panelAntiAircraftGun.getWidth(), panelAntiAircraftGun.getHeight());
|
||||||
|
_drawingGun.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||||
|
abstractStrategy = null;
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
paint(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
package Drawings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Пересичление напрваления
|
* Пересичление напрваления
|
||||||
*/
|
*/
|
||||||
@ -17,5 +19,9 @@ public enum DirectionType {
|
|||||||
/**
|
/**
|
||||||
* Вправо
|
* Вправо
|
||||||
*/
|
*/
|
||||||
Right
|
Right,
|
||||||
|
/**
|
||||||
|
* Без направления
|
||||||
|
*/
|
||||||
|
Unknow,
|
||||||
}
|
}
|
@ -1,13 +1,23 @@
|
|||||||
|
package Drawings;
|
||||||
|
|
||||||
|
import Entites.EntityAntiAirCraftGun;
|
||||||
|
import Entites.EntityGun;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Класс отрисовки зенитной установки
|
* Класс отрисовки зенитной установки
|
||||||
*/
|
*/
|
||||||
public class DrawingAntiAircraftGun {
|
public class DrawingAntiAircraftGun extends DrawingGun {
|
||||||
|
|
||||||
|
public DrawingAntiAircraftGun(int speed, double weight, Color bodyColor, Color optionalElementsColor, boolean hatchHeight, boolean radar,EnumerateWheels enumerateWheels){
|
||||||
|
super(140,65);
|
||||||
|
setEntityGun(new EntityAntiAirCraftGun(speed,weight,bodyColor,optionalElementsColor,hatchHeight,radar,enumerateWheels));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Класс-сущность
|
* Класс-сущность
|
||||||
*/
|
*/
|
||||||
private EntityAntiAirCraftGun EntityAntiAirCraftGun;
|
private Entites.EntityAntiAirCraftGun EntityAntiAirCraftGun;
|
||||||
/**
|
/**
|
||||||
* Объект прорисовки колес
|
* Объект прорисовки колес
|
||||||
*/
|
*/
|
||||||
@ -93,39 +103,6 @@ public class DrawingAntiAircraftGun {
|
|||||||
*/
|
*/
|
||||||
private final int _drawingGunHeight = 115;
|
private final int _drawingGunHeight = 115;
|
||||||
|
|
||||||
/**
|
|
||||||
* Инициализация
|
|
||||||
*
|
|
||||||
* @param speed - скорость
|
|
||||||
* @param weight - вес
|
|
||||||
* @param bodyColor - основной цвет
|
|
||||||
* @param optionalElement - дополнительный элемент
|
|
||||||
* @param hatchHeight -
|
|
||||||
* @param radar - радар
|
|
||||||
*/
|
|
||||||
public void Init(int speed,
|
|
||||||
double weight,
|
|
||||||
Color bodyColor,
|
|
||||||
Color optionalElement,
|
|
||||||
boolean hatchHeight,
|
|
||||||
boolean radar,
|
|
||||||
EnumerateWheels countWheels) {
|
|
||||||
EntityAntiAirCraftGun = new EntityAntiAirCraftGun();
|
|
||||||
|
|
||||||
EntityAntiAirCraftGun.Init(
|
|
||||||
speed,
|
|
||||||
weight,
|
|
||||||
bodyColor,
|
|
||||||
optionalElement,
|
|
||||||
hatchHeight,
|
|
||||||
radar,
|
|
||||||
countWheels
|
|
||||||
);
|
|
||||||
_pictureHeight = null;
|
|
||||||
_pictureWidth = null;
|
|
||||||
_startPosX = null;
|
|
||||||
_startPosY = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Установка границ поля
|
* Установка границ поля
|
||||||
@ -192,25 +169,25 @@ public class DrawingAntiAircraftGun {
|
|||||||
int heightCap=28;
|
int heightCap=28;
|
||||||
double step = EntityAntiAirCraftGun.getStep();
|
double step = EntityAntiAirCraftGun.getStep();
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX - step > 0) {
|
if (_startPosX - step > 0) {
|
||||||
System.out.println("Left");
|
System.out.println("Left");
|
||||||
_startPosX -= (int) step;
|
_startPosX -= (int) step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX + step + _drawingGunWidth < _pictureWidth) {
|
if (_startPosX + step + _drawingGunWidth < _pictureWidth) {
|
||||||
System.out.println("Right");
|
System.out.println("Right");
|
||||||
_startPosX += (int) step;
|
_startPosX += (int) step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY + step + _drawingGunHeight < _pictureHeight+heightCap) {
|
if (_startPosY + step + _drawingGunHeight < _pictureHeight+heightCap) {
|
||||||
System.out.println("Down");
|
System.out.println("Down");
|
||||||
_startPosY += (int) step;
|
_startPosY += (int) step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY - step > heightCap) {
|
if (_startPosY - step > heightCap) {
|
||||||
System.out.println("Up");
|
System.out.println("Up");
|
||||||
_startPosY -= (int) step;
|
_startPosY -= (int) step;
|
||||||
@ -227,25 +204,19 @@ public class DrawingAntiAircraftGun {
|
|||||||
* @param g - объект графики
|
* @param g - объект графики
|
||||||
*/
|
*/
|
||||||
public void DrawTransport(Graphics g) {
|
public void DrawTransport(Graphics g) {
|
||||||
if (EntityAntiAirCraftGun == null || _startPosX == null || _startPosY == null) {
|
if(EntityGun()==null){
|
||||||
|
|
||||||
|
System.out.println("Здесь EntityGun уже не существует");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
drawingWheels = new DrawingWheels(_startPosX, _startPosY, EntityAntiAirCraftGun.getCountWheels());
|
_startPosX+=10;
|
||||||
// Башня
|
_startPosY+=50;
|
||||||
g.setColor(EntityAntiAirCraftGun.getBodyColor());
|
super.DrawTransport(g);
|
||||||
g.fillRect(_startPosX + 50, _startPosY + 50, 60, 25);
|
_startPosX-=10;
|
||||||
g.fillRect(_startPosX + 25, _startPosY + 75, 110, 10);
|
_startPosY-=50;
|
||||||
// Гусеницы
|
|
||||||
g.drawArc(_startPosX + 110, _startPosY + 85, 40, 30, 270, 180);
|
|
||||||
g.drawArc(_startPosX + 10, _startPosY + 85, 40, 30, 90, 180);
|
|
||||||
g.drawLine(_startPosX + 30, _startPosY + 115, _startPosX + 130, _startPosY + 115);
|
|
||||||
//Катки большие
|
|
||||||
g.drawOval(_startPosX + 13, _startPosY + 93, 20, 20);
|
|
||||||
g.drawOval(_startPosX + 126, _startPosY + 93, 20, 20);
|
|
||||||
// Катки малые
|
|
||||||
drawingWheels.drawWheels(g, EntityAntiAirCraftGun.getBodyColor());
|
|
||||||
//Орудие
|
//Орудие
|
||||||
g.drawLine(_startPosX + 100, _startPosY + 70, _startPosX + 150, _startPosY + 10);
|
g.drawLine(_startPosX + 100, _startPosY + 70, _startPosX + 150, _startPosY + 10);
|
||||||
|
System.out.println(EntityAntiAirCraftGun.isHatch()+"здЕСЬ НЕ ДОЛЖНО БЫТЬ ПУСТО");
|
||||||
//Люк
|
//Люк
|
||||||
if (EntityAntiAirCraftGun.isHatch()) {
|
if (EntityAntiAirCraftGun.isHatch()) {
|
||||||
g.setColor(EntityAntiAirCraftGun.getOptionalElementsColor());
|
g.setColor(EntityAntiAirCraftGun.getOptionalElementsColor());
|
244
AntiAirCraftGun/src/Drawings/DrawingGun.java
Normal file
244
AntiAirCraftGun/src/Drawings/DrawingGun.java
Normal file
@ -0,0 +1,244 @@
|
|||||||
|
package Drawings;
|
||||||
|
|
||||||
|
import Entites.EntityGun;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingGun {
|
||||||
|
private DrawingWheels drawingWheels;
|
||||||
|
private EntityGun entityGun;
|
||||||
|
|
||||||
|
public EntityGun EntityGun() {
|
||||||
|
return entityGun;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setEntityGun(EntityGun entityGun) {
|
||||||
|
this.entityGun = entityGun;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer _pictureWidth;
|
||||||
|
|
||||||
|
public Integer GetPictureWidth() {
|
||||||
|
return _pictureWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
private Integer _pictureHeight;
|
||||||
|
|
||||||
|
public Integer GetPictureHeight() {
|
||||||
|
return _pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Позиция по Х
|
||||||
|
*/
|
||||||
|
private Integer _startPosX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для стартовой позиции Y
|
||||||
|
*
|
||||||
|
* @return стартовую позицию по Y
|
||||||
|
*/
|
||||||
|
public Integer get_startPosY() {
|
||||||
|
return _startPosY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для стартовой позиции X
|
||||||
|
*
|
||||||
|
* @return стартовую позицию по X
|
||||||
|
*/
|
||||||
|
public Integer get_startPosX() {
|
||||||
|
return _startPosX;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для стартовой позиции X
|
||||||
|
*
|
||||||
|
* @param _startPosX - стартовая позиция X
|
||||||
|
*/
|
||||||
|
public void set_startPosX(Integer _startPosX) {
|
||||||
|
this._startPosX = _startPosX;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для стартовой позиции Y
|
||||||
|
*
|
||||||
|
* @param _startPosY - стартовая позиция Y
|
||||||
|
*/
|
||||||
|
public void set_startPosY(Integer _startPosY) {
|
||||||
|
this._startPosY = _startPosY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Позиция по Y
|
||||||
|
*/
|
||||||
|
private Integer _startPosY;
|
||||||
|
|
||||||
|
private Integer _drawingGunWidth = 140;
|
||||||
|
private Integer _drawingGunHeight = 65;
|
||||||
|
|
||||||
|
public Integer GetWidth() {
|
||||||
|
return _drawingGunWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer GetHeight() {
|
||||||
|
return _drawingGunHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DrawingGun() {
|
||||||
|
_pictureHeight = null;
|
||||||
|
_pictureWidth = null;
|
||||||
|
_startPosX = null;
|
||||||
|
_startPosY = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingGun(int speed, double weight, Color bodyColor, EnumerateWheels countWheels) {
|
||||||
|
super();
|
||||||
|
setEntityGun(new EntityGun(speed, weight, bodyColor, countWheels));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DrawingGun(int _drawingGunWidth, int _drawingGunHeight) {
|
||||||
|
super();
|
||||||
|
this._drawingGunWidth = _drawingGunWidth;
|
||||||
|
this._drawingGunHeight = _drawingGunHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установка границ поля
|
||||||
|
*
|
||||||
|
* @param width - ширина
|
||||||
|
* @param height - высота
|
||||||
|
* @return false - проверка не пройдена, нельзя разместить объект в этих границах,
|
||||||
|
* true - проверка пройдена
|
||||||
|
*/
|
||||||
|
public boolean SetPictureSize(int width, int height) {
|
||||||
|
if (_drawingGunHeight > height || _drawingGunWidth > width) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_startPosY != null && _startPosX != null) {
|
||||||
|
if (_startPosX + _drawingGunWidth > width) {
|
||||||
|
_startPosX = width - _drawingGunWidth;
|
||||||
|
}
|
||||||
|
if (_startPosY + _drawingGunHeight > height) {
|
||||||
|
_startPosY = height - _drawingGunHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установка позиции
|
||||||
|
*
|
||||||
|
* @param x - позиция по x
|
||||||
|
* @param y - позиция по y
|
||||||
|
*/
|
||||||
|
public void SetPosition(int x, int y) {
|
||||||
|
if (_pictureHeight == null || _pictureWidth == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (x + _drawingGunWidth > _pictureWidth || x < 0) {
|
||||||
|
_startPosX = _pictureWidth - _drawingGunWidth;
|
||||||
|
} else {
|
||||||
|
_startPosX = x;
|
||||||
|
}
|
||||||
|
if (y + _drawingGunHeight > _pictureHeight || y < 0) {
|
||||||
|
_startPosY = _pictureHeight - _drawingGunHeight;
|
||||||
|
} else {
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Изменение направления перемещения
|
||||||
|
*
|
||||||
|
* @param direction - тип перемещения
|
||||||
|
* @return true - перемещение удалось;
|
||||||
|
* false - не удалось переместить объект
|
||||||
|
*/
|
||||||
|
public boolean MoveTransport(DirectionType direction) {
|
||||||
|
if ((EntityGun() == null) || (_startPosX == null) || (_startPosY == null)) {
|
||||||
|
System.out.println("Все плохо");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Высота шапки экрана
|
||||||
|
*/
|
||||||
|
int heightCap = 28;
|
||||||
|
double step = EntityGun().getStep();
|
||||||
|
switch (direction) {
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_startPosX - step > 0) {
|
||||||
|
System.out.println("Left");
|
||||||
|
_startPosX -= (int) step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (_startPosX + step + _drawingGunWidth < _pictureWidth) {
|
||||||
|
System.out.println("Right");
|
||||||
|
_startPosX += (int) step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_startPosY + step + _drawingGunHeight < _pictureHeight + heightCap) {
|
||||||
|
System.out.println("Down");
|
||||||
|
_startPosY += (int) step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPosY - step > heightCap) {
|
||||||
|
System.out.println("Up");
|
||||||
|
_startPosY -= (int) step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Прорисовка объекта
|
||||||
|
*
|
||||||
|
* @param g - объект графики
|
||||||
|
*/
|
||||||
|
public void DrawTransport(Graphics g) {
|
||||||
|
if (EntityGun() == null || _startPosX == null || _startPosY == null) {
|
||||||
|
System.out.println("При вызове DrawTransport, получилось исключение");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
drawingWheels = new DrawingWheels(_startPosX, _startPosY, EntityGun().getCountWheels());
|
||||||
|
// Башня
|
||||||
|
g.setColor(EntityGun().getBodyColor());
|
||||||
|
g.fillRect(_startPosX + 50 - 10, _startPosY + 50 - 50, 60, 25);
|
||||||
|
g.fillRect(_startPosX + 25 - 10, _startPosY + 75 - 50, 110, 10);
|
||||||
|
// Гусеницы
|
||||||
|
g.drawArc(_startPosX + 110 - 10, _startPosY + 85 - 50, 40, 30, 270, 180);
|
||||||
|
g.drawArc(_startPosX + 10 - 10, _startPosY + 85 - 50, 40, 30, 90, 180);
|
||||||
|
g.drawLine(_startPosX + 30 - 10, _startPosY + 115 - 50, _startPosX + 130 - 10, _startPosY + 115 - 50);
|
||||||
|
//Катки большие
|
||||||
|
g.drawOval(_startPosX + 13 - 10, _startPosY + 93 - 50, 20, 20);
|
||||||
|
g.drawOval(_startPosX + 126 - 10, _startPosY + 93 - 50, 20, 20);
|
||||||
|
// Катки малые
|
||||||
|
drawingWheels.drawWheels(g, EntityGun().getBodyColor());
|
||||||
|
// //Орудие
|
||||||
|
// g.drawLine(_startPosX + 100, _startPosY + 70, _startPosX + 150, _startPosY + 10);
|
||||||
|
// //Люк
|
||||||
|
// if (EntityGun().isHatch()) {
|
||||||
|
// g.setColor(EntityGun().getOptionalElementsColor());
|
||||||
|
// g.fillRect(_startPosX + 85, _startPosY + 45, 20, 5);
|
||||||
|
// }
|
||||||
|
// //Радар
|
||||||
|
// if (EntityGun().isRadar()) {
|
||||||
|
// g.setColor(Color.BLACK);
|
||||||
|
// g.drawLine(_startPosX + 65, _startPosY + 50, _startPosX + 65, _startPosY + 25);
|
||||||
|
// g.fillOval(_startPosX + 35, _startPosY, 60, 25);
|
||||||
|
// g.setColor(Color.GREEN);
|
||||||
|
// g.drawLine(_startPosX + 65, _startPosY + 25, _startPosX + 65, _startPosY);
|
||||||
|
// g.drawLine(_startPosX + 35, _startPosY + 13, _startPosX + 95, _startPosY + 13);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
package Drawings;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingWheels {
|
public class DrawingWheels {
|
||||||
@ -21,17 +23,17 @@ public class DrawingWheels {
|
|||||||
// */
|
// */
|
||||||
// public void setEnumerateWheels(int countWheels) {
|
// public void setEnumerateWheels(int countWheels) {
|
||||||
// if (4 > countWheels || 6 < countWheels) {
|
// if (4 > countWheels || 6 < countWheels) {
|
||||||
// enumerateWheels = EnumerateWheels.getRandomEnumerateWheels();
|
// enumerateWheels = Drawings.EnumerateWheels.getRandomEnumerateWheels();
|
||||||
// }
|
// }
|
||||||
// switch (countWheels) {
|
// switch (countWheels) {
|
||||||
// case 4:
|
// case 4:
|
||||||
// enumerateWheels = EnumerateWheels.Four;
|
// enumerateWheels = Drawings.EnumerateWheels.Four;
|
||||||
// break;
|
// break;
|
||||||
// case 5:
|
// case 5:
|
||||||
// enumerateWheels = EnumerateWheels.Five;
|
// enumerateWheels = Drawings.EnumerateWheels.Five;
|
||||||
// break;
|
// break;
|
||||||
// case 6:
|
// case 6:
|
||||||
// enumerateWheels = EnumerateWheels.Six;
|
// enumerateWheels = Drawings.EnumerateWheels.Six;
|
||||||
// break;
|
// break;
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
@ -39,6 +41,7 @@ public class DrawingWheels {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Геттер для объекта перечисления
|
* Геттер для объекта перечисления
|
||||||
|
*
|
||||||
* @return - объект перечисления
|
* @return - объект перечисления
|
||||||
*/
|
*/
|
||||||
public EnumerateWheels getEnumerateWheels() {
|
public EnumerateWheels getEnumerateWheels() {
|
||||||
@ -47,6 +50,7 @@ public class DrawingWheels {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Конструктор
|
* Конструктор
|
||||||
|
*
|
||||||
* @param _startPosX - координата по Х
|
* @param _startPosX - координата по Х
|
||||||
* @param _startPosY - координата по У
|
* @param _startPosY - координата по У
|
||||||
* @param enumerateWheels - объект перечисления
|
* @param enumerateWheels - объект перечисления
|
||||||
@ -59,17 +63,18 @@ public class DrawingWheels {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Геттер для кол-ва колес
|
* Геттер для кол-ва колес
|
||||||
|
*
|
||||||
* @return кол-во колес
|
* @return кол-во колес
|
||||||
*/
|
*/
|
||||||
public Integer getEnumerateWheelsCount() {
|
public Integer getEnumerateWheelsCount() {
|
||||||
switch (getEnumerateWheels()) {
|
switch (getEnumerateWheels()) {
|
||||||
case Five -> {
|
case EnumerateWheels.Five -> {
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
case Four -> {
|
case EnumerateWheels.Four -> {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
case Six -> {
|
case EnumerateWheels.Six -> {
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
@ -80,6 +85,7 @@ public class DrawingWheels {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Отрисовка колес
|
* Отрисовка колес
|
||||||
|
*
|
||||||
* @param g - объект графики
|
* @param g - объект графики
|
||||||
* @param optionColor - цвет колес
|
* @param optionColor - цвет колес
|
||||||
*/
|
*/
|
||||||
@ -88,7 +94,7 @@ public class DrawingWheels {
|
|||||||
System.out.println("Дошел до drawWheels");
|
System.out.println("Дошел до drawWheels");
|
||||||
g.setColor(optionColor);
|
g.setColor(optionColor);
|
||||||
for (int i = 1; i <= getEnumerateWheelsCount(); i++) {
|
for (int i = 1; i <= getEnumerateWheelsCount(); i++) {
|
||||||
g.drawOval(_startPosX + 20 + count, _startPosY + 105, 10, 10);
|
g.drawOval(_startPosX + 20 + count - 10, _startPosY + 105 - 50, 10, 10);
|
||||||
count += 15;
|
count += 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
package Drawings;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public enum EnumerateWheels {
|
public enum EnumerateWheels {
|
96
AntiAirCraftGun/src/Entites/EntityAntiAirCraftGun.java
Normal file
96
AntiAirCraftGun/src/Entites/EntityAntiAirCraftGun.java
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
package Entites;
|
||||||
|
|
||||||
|
import Drawings.EnumerateWheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Класс-сущность зенитной установки
|
||||||
|
*/
|
||||||
|
public class EntityAntiAirCraftGun extends EntityGun{
|
||||||
|
private EntityGun EntityGun;
|
||||||
|
private Color optionalElementsColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для опциональных элементов
|
||||||
|
*
|
||||||
|
* @return цвет для опциональных элементов
|
||||||
|
*/
|
||||||
|
public Color getOptionalElementsColor() {
|
||||||
|
return optionalElementsColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для опциональных элементов
|
||||||
|
*
|
||||||
|
* @param optionalElementsColor - цвет для опциональных элементов
|
||||||
|
*/
|
||||||
|
public void setOptionalElementsColor(Color optionalElementsColor) {
|
||||||
|
this.optionalElementsColor = optionalElementsColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Люк
|
||||||
|
*/
|
||||||
|
private boolean Hatch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер на наличие люка
|
||||||
|
*
|
||||||
|
* @return true - люк есть, false - люка нет
|
||||||
|
*/
|
||||||
|
public boolean isHatch() {
|
||||||
|
return Hatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для люка
|
||||||
|
*
|
||||||
|
* @param hatch - наличие люка
|
||||||
|
*/
|
||||||
|
private void setHatch(boolean hatch) {
|
||||||
|
Hatch = hatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Радар
|
||||||
|
*/
|
||||||
|
private boolean Radar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для радара
|
||||||
|
*
|
||||||
|
* @return true - радар есть, false - радара нет
|
||||||
|
*/
|
||||||
|
public boolean isRadar() {
|
||||||
|
return Radar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для радара
|
||||||
|
*
|
||||||
|
* @param radar - наличие радара
|
||||||
|
*/
|
||||||
|
private void setRadar(boolean radar) {
|
||||||
|
Radar = radar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Инициализация
|
||||||
|
*
|
||||||
|
* @param speed - скорость
|
||||||
|
* @param weight - вес
|
||||||
|
* @param bodyColor - основной цвет
|
||||||
|
* @param optionalElementsColor - дополнительный цве
|
||||||
|
* @param hatch - люк
|
||||||
|
* @param radar - радара
|
||||||
|
*/
|
||||||
|
|
||||||
|
public EntityAntiAirCraftGun(int speed, double weight, Color bodyColor, Color optionalElementsColor, boolean hatch, boolean radar, EnumerateWheels countWheels) {
|
||||||
|
super(speed, weight, bodyColor,countWheels);
|
||||||
|
EntityGun = new EntityGun(speed,weight,bodyColor,countWheels);
|
||||||
|
this.optionalElementsColor = optionalElementsColor;
|
||||||
|
Hatch = hatch;
|
||||||
|
Radar = radar;
|
||||||
|
}
|
||||||
|
}
|
115
AntiAirCraftGun/src/Entites/EntityGun.java
Normal file
115
AntiAirCraftGun/src/Entites/EntityGun.java
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
package Entites;
|
||||||
|
|
||||||
|
import Drawings.EnumerateWheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityGun {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Скорость
|
||||||
|
*/
|
||||||
|
private int speed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для скорости
|
||||||
|
*
|
||||||
|
* @return скорость
|
||||||
|
*/
|
||||||
|
public int getSpeed() {
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для скорости
|
||||||
|
*
|
||||||
|
* @param speed - скорость
|
||||||
|
*/
|
||||||
|
private void setSpeed(int speed) {
|
||||||
|
this.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Вес
|
||||||
|
*/
|
||||||
|
private double weight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для веса
|
||||||
|
*
|
||||||
|
* @return вес
|
||||||
|
*/
|
||||||
|
public double getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для веса
|
||||||
|
*
|
||||||
|
* @param weight - вес
|
||||||
|
*/
|
||||||
|
private void setWeight(double weight) {
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Основной цвет
|
||||||
|
*/
|
||||||
|
private Color bodyColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для основого цвета
|
||||||
|
*
|
||||||
|
* @return основной цвет
|
||||||
|
*/
|
||||||
|
public Color getBodyColor() {
|
||||||
|
return bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для основого цвета
|
||||||
|
*
|
||||||
|
* @param bodyColor - основной цвет
|
||||||
|
*/
|
||||||
|
private void setBodyColor(Color bodyColor) {
|
||||||
|
this.bodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Кол-во колес
|
||||||
|
*/
|
||||||
|
private EnumerateWheels countWheels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для кол-ва колес
|
||||||
|
*
|
||||||
|
* @return кол-во колес
|
||||||
|
*/
|
||||||
|
public EnumerateWheels getCountWheels() {
|
||||||
|
return countWheels;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для кол-ва колес
|
||||||
|
*
|
||||||
|
* @param countWheels - кол-во колес
|
||||||
|
*/
|
||||||
|
public void setCountWheels(EnumerateWheels countWheels) {
|
||||||
|
this.countWheels = countWheels;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Геттер для шага
|
||||||
|
*
|
||||||
|
* @return шаг
|
||||||
|
*/
|
||||||
|
public Double getStep() {
|
||||||
|
return getSpeed() * 100 / getWeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityGun(int speed, double weight, Color bodyColor, EnumerateWheels countWheels) {
|
||||||
|
this.speed = speed;
|
||||||
|
this.weight = weight;
|
||||||
|
this.bodyColor = bodyColor;
|
||||||
|
this.countWheels = countWheels;
|
||||||
|
}
|
||||||
|
}
|
@ -1,204 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Класс-сущность зенитной установки
|
|
||||||
*/
|
|
||||||
public class EntityAntiAirCraftGun {
|
|
||||||
/**
|
|
||||||
* Скорость
|
|
||||||
*/
|
|
||||||
private int speed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Геттер для скорости
|
|
||||||
*
|
|
||||||
* @return скорость
|
|
||||||
*/
|
|
||||||
public int getSpeed() {
|
|
||||||
return speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Сеттер для скорости
|
|
||||||
*
|
|
||||||
* @param speed - скорость
|
|
||||||
*/
|
|
||||||
private void setSpeed(int speed) {
|
|
||||||
this.speed = speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Вес
|
|
||||||
*/
|
|
||||||
private double weight;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Геттер для веса
|
|
||||||
*
|
|
||||||
* @return вес
|
|
||||||
*/
|
|
||||||
public double getWeight() {
|
|
||||||
return weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Сеттер для веса
|
|
||||||
*
|
|
||||||
* @param weight - вес
|
|
||||||
*/
|
|
||||||
private void setWeight(double weight) {
|
|
||||||
this.weight = weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Основной цвет
|
|
||||||
*/
|
|
||||||
private Color bodyColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Геттер для основого цвета
|
|
||||||
*
|
|
||||||
* @return основной цвет
|
|
||||||
*/
|
|
||||||
public Color getBodyColor() {
|
|
||||||
return bodyColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Сеттер для основого цвета
|
|
||||||
*
|
|
||||||
* @param bodyColor - основной цвет
|
|
||||||
*/
|
|
||||||
private void setBodyColor(Color bodyColor) {
|
|
||||||
this.bodyColor = bodyColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Опциональные элементы
|
|
||||||
*/
|
|
||||||
private Color optionalElementsColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Геттер для опциональных элементов
|
|
||||||
*
|
|
||||||
* @return цвет для опциональных элементов
|
|
||||||
*/
|
|
||||||
public Color getOptionalElementsColor() {
|
|
||||||
return optionalElementsColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Сеттер для опциональных элементов
|
|
||||||
*
|
|
||||||
* @param optionalElementsColor - цвет для опциональных элементов
|
|
||||||
*/
|
|
||||||
public void setOptionalElementsColor(Color optionalElementsColor) {
|
|
||||||
this.optionalElementsColor = optionalElementsColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Люк
|
|
||||||
*/
|
|
||||||
private boolean Hatch;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Геттер на наличие люка
|
|
||||||
*
|
|
||||||
* @return true - люк есть, false - люка нет
|
|
||||||
*/
|
|
||||||
public boolean isHatch() {
|
|
||||||
return Hatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Сеттер для люка
|
|
||||||
*
|
|
||||||
* @param hatch - наличие люка
|
|
||||||
*/
|
|
||||||
private void setHatch(boolean hatch) {
|
|
||||||
Hatch = hatch;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Радар
|
|
||||||
*/
|
|
||||||
private boolean Radar;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Геттер для радара
|
|
||||||
*
|
|
||||||
* @return true - радар есть, false - радара нет
|
|
||||||
*/
|
|
||||||
public boolean isRadar() {
|
|
||||||
return Radar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Сеттер для радара
|
|
||||||
*
|
|
||||||
* @param radar - наличие радара
|
|
||||||
*/
|
|
||||||
private void setRadar(boolean radar) {
|
|
||||||
Radar = radar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Геттер для шага
|
|
||||||
*
|
|
||||||
* @return шаг
|
|
||||||
*/
|
|
||||||
public double getStep() {
|
|
||||||
return getSpeed() * 100 / getWeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Кол-во колес
|
|
||||||
*/
|
|
||||||
private EnumerateWheels countWheels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Геттер для кол-ва колес
|
|
||||||
*
|
|
||||||
* @return кол-во колес
|
|
||||||
*/
|
|
||||||
public EnumerateWheels getCountWheels() {
|
|
||||||
return countWheels;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Сеттер для кол-ва колес
|
|
||||||
*
|
|
||||||
* @param countWheels - кол-во колес
|
|
||||||
*/
|
|
||||||
public void setCountWheels(EnumerateWheels countWheels) {
|
|
||||||
this.countWheels = countWheels;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Инициализация
|
|
||||||
*
|
|
||||||
* @param speed - скорость
|
|
||||||
* @param weight - вес
|
|
||||||
* @param bodyColor - основной цвет
|
|
||||||
* @param optionalElementsColor - дополнительный цве
|
|
||||||
* @param hatch - люк
|
|
||||||
* @param radar - радара
|
|
||||||
*/
|
|
||||||
public void Init(
|
|
||||||
int speed,
|
|
||||||
double weight,
|
|
||||||
Color bodyColor,
|
|
||||||
Color optionalElementsColor,
|
|
||||||
boolean hatch,
|
|
||||||
boolean radar,
|
|
||||||
EnumerateWheels countWheels
|
|
||||||
) {
|
|
||||||
setSpeed(speed);
|
|
||||||
setWeight(weight);
|
|
||||||
setBodyColor(bodyColor);
|
|
||||||
setOptionalElementsColor(optionalElementsColor);
|
|
||||||
setHatch(hatch);
|
|
||||||
setRadar(radar);
|
|
||||||
setCountWheels(countWheels);
|
|
||||||
}
|
|
||||||
}
|
|
183
AntiAirCraftGun/src/MovementStrategy/AbstractStrategy.java
Normal file
183
AntiAirCraftGun/src/MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Класс стратегии
|
||||||
|
*/
|
||||||
|
public abstract class AbstractStrategy {
|
||||||
|
/**
|
||||||
|
* Перемещаемый объект
|
||||||
|
*/
|
||||||
|
private IMoveableObject _moveableObject;
|
||||||
|
/**
|
||||||
|
* Статус перемещения
|
||||||
|
*/
|
||||||
|
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||||
|
/**
|
||||||
|
* Ширина поля
|
||||||
|
*/
|
||||||
|
private Integer fieldWidth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для ширины поля
|
||||||
|
*
|
||||||
|
* @return ширину поля
|
||||||
|
*/
|
||||||
|
protected Integer FieldWidth() {
|
||||||
|
return fieldWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для ширины поля
|
||||||
|
*
|
||||||
|
* @param fieldWidth ширина поля
|
||||||
|
*/
|
||||||
|
private void setFieldWidth(Integer fieldWidth) {
|
||||||
|
this.fieldWidth = fieldWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Высота поля
|
||||||
|
*/
|
||||||
|
private Integer fieldHeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для высоты поля
|
||||||
|
*
|
||||||
|
* @return высота поля
|
||||||
|
*/
|
||||||
|
protected Integer FieldHeight() {
|
||||||
|
return fieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Сеттер для высоты поля
|
||||||
|
*
|
||||||
|
* @param fieldHeight высота поля
|
||||||
|
*/
|
||||||
|
|
||||||
|
private void setFieldHeight(Integer fieldHeight) {
|
||||||
|
this.fieldHeight = fieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Геттер для состояния
|
||||||
|
*
|
||||||
|
* @return состояние
|
||||||
|
*/
|
||||||
|
public StrategyStatus GetStatus() {
|
||||||
|
return _state;
|
||||||
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установка данных
|
||||||
|
*
|
||||||
|
* @param moveableObject перемещаемый объект
|
||||||
|
* @param width ширина
|
||||||
|
* @param height высота
|
||||||
|
*/
|
||||||
|
public void SetData(IMoveableObject moveableObject, Integer width, Integer height) {
|
||||||
|
if (moveableObject == null) {
|
||||||
|
_state = StrategyStatus.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = StrategyStatus.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
setFieldWidth(width);
|
||||||
|
setFieldHeight(height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Шаг перемещения
|
||||||
|
*/
|
||||||
|
public void MakeStep() {
|
||||||
|
if (_state != StrategyStatus.InProgress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestinaion()) {
|
||||||
|
_state = StrategyStatus.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Влево
|
||||||
|
*
|
||||||
|
* @return Результат перемещения (true - удалось переместиться, false -неудача)
|
||||||
|
*/
|
||||||
|
protected boolean MoveLeft() {
|
||||||
|
return MoveTo(MovementDirection.Left);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Вправо
|
||||||
|
*
|
||||||
|
* @return Результат перемещения (true - удалось переместиться, false -неудача)
|
||||||
|
*/
|
||||||
|
protected boolean MoveRight() {
|
||||||
|
return MoveTo(MovementDirection.Right);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Наверх
|
||||||
|
*
|
||||||
|
* @return Результат перемещения (true - удалось переместиться, false -неудача)
|
||||||
|
*/
|
||||||
|
protected boolean MoveUp() {
|
||||||
|
return MoveTo(MovementDirection.Up);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Вниз
|
||||||
|
*
|
||||||
|
* @return Результат перемещения (true - удалось переместиться, false -неудача)
|
||||||
|
*/
|
||||||
|
protected boolean MoveDown() {
|
||||||
|
return MoveTo(MovementDirection.Down);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Параметры объекта
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected ObjectParameters GetObjectParameters() {
|
||||||
|
return _moveableObject.GetObjectPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Шаг объекта
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected Integer GetStep() {
|
||||||
|
if (_state != StrategyStatus.InProgress) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject.GetStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Перемещение к цели
|
||||||
|
*/
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Достигнута ли цель
|
||||||
|
*/
|
||||||
|
protected abstract boolean IsTargetDestinaion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Попытка перемещения в требуемом направлении
|
||||||
|
*
|
||||||
|
* @return Результат попытки (true - удалось переместиться, false -неудача)
|
||||||
|
*/
|
||||||
|
private boolean MoveTo(MovementDirection movementDirection) {
|
||||||
|
if (_state != StrategyStatus.InProgress) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return _moveableObject.TryMoveObject(movementDirection) && _moveableObject.TryMoveObject(movementDirection);
|
||||||
|
}
|
||||||
|
}
|
10
AntiAirCraftGun/src/MovementStrategy/IMoveableObject.java
Normal file
10
AntiAirCraftGun/src/MovementStrategy/IMoveableObject.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Интерфейс для работы с перемещаемым объектом
|
||||||
|
*/
|
||||||
|
public interface IMoveableObject {
|
||||||
|
ObjectParameters GetObjectPosition();
|
||||||
|
int GetStep();
|
||||||
|
boolean TryMoveObject(MovementDirection direction);
|
||||||
|
}
|
27
AntiAirCraftGun/src/MovementStrategy/MoveToBorder.java
Normal file
27
AntiAirCraftGun/src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToBorder extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
|
protected void MoveToTarget() {
|
||||||
|
ObjectParameters objectParameters = GetObjectParameters();
|
||||||
|
if (objectParameters == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (objectParameters.RightBorder() < FieldWidth()) {
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
if (objectParameters.DownBorder() < FieldHeight()) {
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean IsTargetDestinaion() {
|
||||||
|
ObjectParameters objectParameters = GetObjectParameters();
|
||||||
|
if (objectParameters == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objectParameters.RightBorder() <= FieldWidth() && objectParameters.RightBorder() + GetStep() >= FieldWidth() &&
|
||||||
|
objectParameters.DownBorder() <= FieldHeight() && objectParameters.DownBorder() + GetStep() >= FieldHeight();
|
||||||
|
}
|
||||||
|
}
|
39
AntiAirCraftGun/src/MovementStrategy/MoveToCenter.java
Normal file
39
AntiAirCraftGun/src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToCenter extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
|
protected void MoveToTarget() {
|
||||||
|
ObjectParameters objectParameters = GetObjectParameters();
|
||||||
|
if (objectParameters == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int diffx = objectParameters.ObjectMiddleHorizontal() - FieldWidth() / 2;
|
||||||
|
if (Math.abs(diffx) > GetStep()) {
|
||||||
|
if (diffx > 0) {
|
||||||
|
MoveLeft();
|
||||||
|
} else {
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int diffy = objectParameters.ObjectMiddleVertical() - FieldHeight() / 2;
|
||||||
|
if (Math.abs(diffx) > GetStep()) {
|
||||||
|
if (diffx > 0) {
|
||||||
|
MoveUp();
|
||||||
|
} else {
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean IsTargetDestinaion() {
|
||||||
|
ObjectParameters objectParameters = GetObjectParameters();
|
||||||
|
if (objectParameters == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objectParameters.ObjectMiddleHorizontal() - GetStep() <= FieldWidth() / 2
|
||||||
|
&& objectParameters.ObjectMiddleHorizontal() + GetStep() >= FieldWidth() / 2
|
||||||
|
&& objectParameters.ObjectMiddleVertical() - GetStep() <= FieldHeight() / 2
|
||||||
|
&& objectParameters.ObjectMiddleVertical() + GetStep() >= FieldHeight() / 2;
|
||||||
|
}
|
||||||
|
}
|
60
AntiAirCraftGun/src/MovementStrategy/MoveableGun.java
Normal file
60
AntiAirCraftGun/src/MovementStrategy/MoveableGun.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
import Drawings.DirectionType;
|
||||||
|
import Drawings.DrawingAntiAircraftGun;
|
||||||
|
import Drawings.DrawingGun;
|
||||||
|
|
||||||
|
public class MoveableGun implements IMoveableObject{
|
||||||
|
|
||||||
|
private DrawingGun _drawingGun = null;
|
||||||
|
|
||||||
|
public MoveableGun(DrawingGun drawingGun) {
|
||||||
|
this._drawingGun=drawingGun;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectParameters GetObjectPosition() {
|
||||||
|
if(_drawingGun==null || _drawingGun.EntityGun()==null
|
||||||
|
|| _drawingGun.get_startPosX()==null
|
||||||
|
||_drawingGun.get_startPosY()==null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(
|
||||||
|
_drawingGun.get_startPosX(),
|
||||||
|
_drawingGun.get_startPosY(),
|
||||||
|
_drawingGun.GetWidth(),
|
||||||
|
_drawingGun.GetHeight()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int GetStep() {
|
||||||
|
return (int)(_drawingGun.EntityGun().getStep()!=null ? _drawingGun.EntityGun().getStep():0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean TryMoveObject(MovementDirection direction) {
|
||||||
|
if(_drawingGun==null||_drawingGun.EntityGun()==null)return false;
|
||||||
|
return _drawingGun.MoveTransport(GetObjectType(direction));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DirectionType GetObjectType(MovementDirection direction){
|
||||||
|
switch (direction){
|
||||||
|
case Left -> {
|
||||||
|
return DirectionType.Left;
|
||||||
|
}
|
||||||
|
case Up -> {
|
||||||
|
return DirectionType.Up;
|
||||||
|
}
|
||||||
|
case Down -> {
|
||||||
|
return DirectionType.Down;
|
||||||
|
}
|
||||||
|
case Right -> {
|
||||||
|
return DirectionType.Right;
|
||||||
|
}
|
||||||
|
case null -> {
|
||||||
|
return DirectionType.Unknow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
AntiAirCraftGun/src/MovementStrategy/MovementDirection.java
Normal file
23
AntiAirCraftGun/src/MovementStrategy/MovementDirection.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Направление перемещения
|
||||||
|
*/
|
||||||
|
public enum MovementDirection {
|
||||||
|
/**
|
||||||
|
* Влево
|
||||||
|
*/
|
||||||
|
Left,
|
||||||
|
/**
|
||||||
|
* Вправо
|
||||||
|
*/
|
||||||
|
Right,
|
||||||
|
/**
|
||||||
|
* Вверх
|
||||||
|
*/
|
||||||
|
Up,
|
||||||
|
/**
|
||||||
|
* Вниз
|
||||||
|
*/
|
||||||
|
Down
|
||||||
|
}
|
69
AntiAirCraftGun/src/MovementStrategy/ObjectParameters.java
Normal file
69
AntiAirCraftGun/src/MovementStrategy/ObjectParameters.java
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class ObjectParameters {
|
||||||
|
/**
|
||||||
|
* Координата по х
|
||||||
|
*/
|
||||||
|
private final Integer _x;
|
||||||
|
/**
|
||||||
|
* Координат по y
|
||||||
|
*/
|
||||||
|
private final Integer _y;
|
||||||
|
/**
|
||||||
|
* Ширина объекта
|
||||||
|
*/
|
||||||
|
private final Integer _width;
|
||||||
|
/**
|
||||||
|
* Высоат объекта
|
||||||
|
*/
|
||||||
|
private final Integer _height;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Левая граница
|
||||||
|
* @return - х
|
||||||
|
*/
|
||||||
|
public Integer LeftBorder(){return _x;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Правая граница
|
||||||
|
* @return - х + высота
|
||||||
|
*/
|
||||||
|
public Integer RightBorder() {return _x+_width;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Верхняя граница
|
||||||
|
* @return - у
|
||||||
|
*/
|
||||||
|
public Integer TopBorder(){return _y;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Нижняя граница
|
||||||
|
* @return - y + высота
|
||||||
|
*/
|
||||||
|
public Integer DownBorder(){return _y+_height;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Середина обеъкта
|
||||||
|
* @return - середину объекта по горизонтали
|
||||||
|
*/
|
||||||
|
public Integer ObjectMiddleHorizontal(){return _x+_width/2;}
|
||||||
|
/**
|
||||||
|
* Середина обеъкта
|
||||||
|
* @return - середину объекта по вертикали
|
||||||
|
*/
|
||||||
|
public Integer ObjectMiddleVertical(){return _y+_height/2;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Констурктор
|
||||||
|
* @param _x - x
|
||||||
|
* @param _y - y
|
||||||
|
* @param _width - ширина
|
||||||
|
* @param _height - высота
|
||||||
|
*/
|
||||||
|
public ObjectParameters(Integer _x, Integer _y, Integer _width, Integer _height) {
|
||||||
|
this._x = _x;
|
||||||
|
this._y = _y;
|
||||||
|
this._width = _width;
|
||||||
|
this._height = _height;
|
||||||
|
}
|
||||||
|
}
|
16
AntiAirCraftGun/src/MovementStrategy/StrategyStatus.java
Normal file
16
AntiAirCraftGun/src/MovementStrategy/StrategyStatus.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public enum StrategyStatus {
|
||||||
|
/**
|
||||||
|
* Все готово к началу
|
||||||
|
*/
|
||||||
|
NotInit,
|
||||||
|
/**
|
||||||
|
* В процессе
|
||||||
|
*/
|
||||||
|
InProgress,
|
||||||
|
/**
|
||||||
|
* Завершено
|
||||||
|
*/
|
||||||
|
Finish
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user