LabWork1 gg wp, делал очень долго, наконец-то перенес с гитхаба
This commit is contained in:
parent
f50eae2f0f
commit
843de80fbb
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="AntiAirCraftGun">
|
||||
<grid id="27dc6" row-count="1" column-count="1" layout-manager="GridLayoutManager">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</form>
|
@ -1,2 +0,0 @@
|
||||
public class AntiAirCraftGun {
|
||||
}
|
65
AntiAirCraftGun/src/AntiAircraftGun.form
Normal file
65
AntiAirCraftGun/src/AntiAircraftGun.form
Normal file
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="41" y="20" width="624" height="340"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="f9412" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="bf8a3">
|
||||
<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"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="9c76c" class="javax.swing.JButton" binding="buttonDown">
|
||||
<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=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="4edcf" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="false"/>
|
||||
<horizontalTextPosition value="11"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="40000" class="javax.swing.JButton" binding="buttonRight">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ab0ea" class="javax.swing.JButton" binding="buttonUp">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="c1d4a">
|
||||
<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"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
140
AntiAirCraftGun/src/AntiAircraftGun.java
Normal file
140
AntiAirCraftGun/src/AntiAircraftGun.java
Normal file
@ -0,0 +1,140 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Форма
|
||||
*/
|
||||
public class AntiAircraftGun extends JFrame {
|
||||
/**
|
||||
* Объект сущности зенитной установки
|
||||
*/
|
||||
private DrawingAntiAircraftGun _drawingAntiAircraftGun;
|
||||
/**
|
||||
* Панель
|
||||
*/
|
||||
public JPanel panelAntiAircraftGun;
|
||||
/**
|
||||
* Кнопка создания
|
||||
*/
|
||||
private JButton buttonCreate;
|
||||
/**
|
||||
* Кнопка движения вниз
|
||||
*/
|
||||
private JButton buttonDown;
|
||||
/**
|
||||
* Кнопка движения вверх
|
||||
*/
|
||||
private JButton buttonUp;
|
||||
/**
|
||||
* Кнопка движения влево
|
||||
*/
|
||||
private JButton buttonLeft;
|
||||
/**
|
||||
* Кнопка движения вправо
|
||||
*/
|
||||
private JButton buttonRight;
|
||||
|
||||
/**
|
||||
* Метод отрисовки
|
||||
*
|
||||
* @param g - графика
|
||||
*/
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
if (_drawingAntiAircraftGun == null) {
|
||||
System.out.println("Значение пустое, я ничего не нарисовал");
|
||||
return;
|
||||
}
|
||||
_drawingAntiAircraftGun.DrawTransport(g);
|
||||
System.out.println("Ура, я что-то нарисовал");
|
||||
}
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
*/
|
||||
public AntiAircraftGun() {
|
||||
add(panelAntiAircraftGun);
|
||||
setVisible(true);
|
||||
setSize(600, 600);
|
||||
setResizable(false);
|
||||
Graphics g = getGraphics().create();
|
||||
Icon iconDown = new ImageIcon("AntiAirCraftGun\\src\\Resources\\Down123.jpg");
|
||||
Icon iconUp = new ImageIcon("AntiAirCraftGun\\src\\Resources\\up123.jpg");
|
||||
Icon iconLeft = new ImageIcon("AntiAirCraftGun\\src\\Resources\\left123.jpg");
|
||||
Icon iconRight = new ImageIcon("AntiAirCraftGun\\src\\Resources\\right123.jpg");
|
||||
buttonDown.setIcon(iconDown);
|
||||
buttonUp.setIcon(iconUp);
|
||||
buttonRight.setIcon(iconRight);
|
||||
buttonLeft.setIcon(iconLeft);
|
||||
_drawingAntiAircraftGun = new DrawingAntiAircraftGun();
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Я нажал на кнопку");
|
||||
System.out.println(e.paramString());
|
||||
Random random = new Random();
|
||||
|
||||
_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) {
|
||||
return;
|
||||
}
|
||||
buttonDown.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
boolean result = _drawingAntiAircraftGun.MoveTransport(DirectionType.Down);
|
||||
if (result) {
|
||||
paint(g);
|
||||
System.out.println(actionEvent.paramString());
|
||||
}
|
||||
}
|
||||
});
|
||||
buttonUp.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Up);
|
||||
paint(g);
|
||||
System.out.println(actionEvent.paramString());
|
||||
}
|
||||
});
|
||||
buttonLeft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Left);
|
||||
paint(g);
|
||||
System.out.println(actionEvent.paramString());
|
||||
}
|
||||
});
|
||||
buttonRight.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Right);
|
||||
paint(g);
|
||||
System.out.println(actionEvent.paramString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
21
AntiAirCraftGun/src/DirectionType.java
Normal file
21
AntiAirCraftGun/src/DirectionType.java
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Пересичление напрваления
|
||||
*/
|
||||
public enum DirectionType {
|
||||
/**
|
||||
* Вверх
|
||||
*/
|
||||
Up,
|
||||
/**
|
||||
* Вниз
|
||||
*/
|
||||
Down,
|
||||
/**
|
||||
* Влево
|
||||
*/
|
||||
Left,
|
||||
/**
|
||||
* Вправо
|
||||
*/
|
||||
Right
|
||||
}
|
265
AntiAirCraftGun/src/DrawingAntiAircraftGun.java
Normal file
265
AntiAirCraftGun/src/DrawingAntiAircraftGun.java
Normal file
@ -0,0 +1,265 @@
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Класс отрисовки зенитной установки
|
||||
*/
|
||||
public class DrawingAntiAircraftGun {
|
||||
/**
|
||||
* Класс-сущность
|
||||
*/
|
||||
private EntityAntiAirCraftGun EntityAntiAirCraftGun;
|
||||
/**
|
||||
* Объект прорисовки колес
|
||||
*/
|
||||
private DrawingWheels drawingWheels;
|
||||
|
||||
/**
|
||||
* Geter для сущности
|
||||
*
|
||||
* @return Возвращает сущность
|
||||
*/
|
||||
public EntityAntiAirCraftGun getEntityAntiAirCraftGun() {
|
||||
return EntityAntiAirCraftGun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter для сущности
|
||||
*
|
||||
* @param EntityAntiAirCraftGun - объект сущности
|
||||
*/
|
||||
private void setEntityAntiAirCraftGun(EntityAntiAirCraftGun EntityAntiAirCraftGun) {
|
||||
this.EntityAntiAirCraftGun = EntityAntiAirCraftGun;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ширина окна
|
||||
*/
|
||||
private Integer _pictureWidth;
|
||||
/**
|
||||
* Высота окна
|
||||
*/
|
||||
private Integer _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 final int _drawingGunWidth = 150;
|
||||
/**
|
||||
* Высота прорисовки зенитной установки
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка границ поля
|
||||
*
|
||||
* @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 ((EntityAntiAirCraftGun == null) || (_startPosX == null) || (_startPosY == null)) {
|
||||
System.out.println("Все плохо");
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Высота шапки экрана
|
||||
*/
|
||||
int heightCap=28;
|
||||
double step = EntityAntiAirCraftGun.getStep();
|
||||
switch (direction) {
|
||||
case Left:
|
||||
if (_startPosX - step > 0) {
|
||||
System.out.println("Left");
|
||||
_startPosX -= (int) step;
|
||||
}
|
||||
return true;
|
||||
case Right:
|
||||
if (_startPosX + step + _drawingGunWidth < _pictureWidth) {
|
||||
System.out.println("Right");
|
||||
_startPosX += (int) step;
|
||||
}
|
||||
return true;
|
||||
case Down:
|
||||
if (_startPosY + step + _drawingGunHeight < _pictureHeight+heightCap) {
|
||||
System.out.println("Down");
|
||||
_startPosY += (int) step;
|
||||
}
|
||||
return true;
|
||||
case 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 (EntityAntiAirCraftGun == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
drawingWheels = new DrawingWheels(_startPosX, _startPosY, EntityAntiAirCraftGun.getCountWheels());
|
||||
// Башня
|
||||
g.setColor(EntityAntiAirCraftGun.getBodyColor());
|
||||
g.fillRect(_startPosX + 50, _startPosY + 50, 60, 25);
|
||||
g.fillRect(_startPosX + 25, _startPosY + 75, 110, 10);
|
||||
// Гусеницы
|
||||
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);
|
||||
//Люк
|
||||
if (EntityAntiAirCraftGun.isHatch()) {
|
||||
g.setColor(EntityAntiAirCraftGun.getOptionalElementsColor());
|
||||
g.fillRect(_startPosX + 85, _startPosY + 45, 20, 5);
|
||||
}
|
||||
//Радар
|
||||
if (EntityAntiAirCraftGun.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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
95
AntiAirCraftGun/src/DrawingWheels.java
Normal file
95
AntiAirCraftGun/src/DrawingWheels.java
Normal file
@ -0,0 +1,95 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingWheels {
|
||||
/**
|
||||
* Координата по Х
|
||||
*/
|
||||
private final Integer _startPosX;
|
||||
/**
|
||||
* Координата по У
|
||||
*/
|
||||
private final Integer _startPosY;
|
||||
/**
|
||||
* Объект перечисления
|
||||
*/
|
||||
private EnumerateWheels enumerateWheels;
|
||||
|
||||
// /**
|
||||
// * Установка кол-ва колес
|
||||
// *
|
||||
// * @param countWheels - кол-во колес
|
||||
// */
|
||||
// public void setEnumerateWheels(int countWheels) {
|
||||
// if (4 > countWheels || 6 < countWheels) {
|
||||
// enumerateWheels = EnumerateWheels.getRandomEnumerateWheels();
|
||||
// }
|
||||
// switch (countWheels) {
|
||||
// case 4:
|
||||
// enumerateWheels = EnumerateWheels.Four;
|
||||
// break;
|
||||
// case 5:
|
||||
// enumerateWheels = EnumerateWheels.Five;
|
||||
// break;
|
||||
// case 6:
|
||||
// enumerateWheels = EnumerateWheels.Six;
|
||||
// break;
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Геттер для объекта перечисления
|
||||
* @return - объект перечисления
|
||||
*/
|
||||
public EnumerateWheels getEnumerateWheels() {
|
||||
return enumerateWheels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
* @param _startPosX - координата по Х
|
||||
* @param _startPosY - координата по У
|
||||
* @param enumerateWheels - объект перечисления
|
||||
*/
|
||||
public DrawingWheels(Integer _startPosX, Integer _startPosY, EnumerateWheels enumerateWheels) {
|
||||
this._startPosX = _startPosX;
|
||||
this._startPosY = _startPosY;
|
||||
this.enumerateWheels = enumerateWheels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Геттер для кол-ва колес
|
||||
* @return кол-во колес
|
||||
*/
|
||||
public Integer getEnumerateWheelsCount() {
|
||||
switch (getEnumerateWheels()) {
|
||||
case Five -> {
|
||||
return 5;
|
||||
}
|
||||
case Four -> {
|
||||
return 4;
|
||||
}
|
||||
case Six -> {
|
||||
return 6;
|
||||
}
|
||||
default -> {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Отрисовка колес
|
||||
* @param g - объект графики
|
||||
* @param optionColor - цвет колес
|
||||
*/
|
||||
public void drawWheels(Graphics g, Color optionColor) {
|
||||
int count = 15;
|
||||
System.out.println("Дошел до drawWheels");
|
||||
g.setColor(optionColor);
|
||||
for (int i = 1; i <= getEnumerateWheelsCount(); i++) {
|
||||
g.drawOval(_startPosX + 20 + count, _startPosY + 105, 10, 10);
|
||||
count += 15;
|
||||
}
|
||||
}
|
||||
}
|
204
AntiAirCraftGun/src/EntityAntiAirCraftGun.java
Normal file
204
AntiAirCraftGun/src/EntityAntiAirCraftGun.java
Normal file
@ -0,0 +1,204 @@
|
||||
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);
|
||||
}
|
||||
}
|
37
AntiAirCraftGun/src/EnumerateWheels.java
Normal file
37
AntiAirCraftGun/src/EnumerateWheels.java
Normal file
@ -0,0 +1,37 @@
|
||||
import java.util.Random;
|
||||
|
||||
public enum EnumerateWheels {
|
||||
/**
|
||||
* Четыре
|
||||
*/
|
||||
Four,
|
||||
/**
|
||||
* Пять
|
||||
*/
|
||||
Five,
|
||||
/**
|
||||
* Шесть
|
||||
*/
|
||||
Six;
|
||||
/**
|
||||
* Массив перечисления
|
||||
*/
|
||||
private static final EnumerateWheels[] VALUES = values();
|
||||
/**
|
||||
* Размер массива
|
||||
*/
|
||||
private static final int SIZE = VALUES.length;
|
||||
/**
|
||||
* Объект рандома
|
||||
*/
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
/**
|
||||
* Геттер для рандомного кол-ва колес
|
||||
*
|
||||
* @return рандомное кол-во колес
|
||||
*/
|
||||
public static EnumerateWheels getRandomEnumerateWheels() {
|
||||
return VALUES[RANDOM.nextInt(SIZE)];
|
||||
}
|
||||
}
|
9
AntiAirCraftGun/src/Main.java
Normal file
9
AntiAirCraftGun/src/Main.java
Normal file
@ -0,0 +1,9 @@
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new AntiAircraftGun();
|
||||
}
|
||||
}
|
||||
|
BIN
AntiAirCraftGun/src/Resources/Down123.jpg
Normal file
BIN
AntiAirCraftGun/src/Resources/Down123.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 978 B |
BIN
AntiAirCraftGun/src/Resources/left123.jpg
Normal file
BIN
AntiAirCraftGun/src/Resources/left123.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
AntiAirCraftGun/src/Resources/right123.jpg
Normal file
BIN
AntiAirCraftGun/src/Resources/right123.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 839 B |
BIN
AntiAirCraftGun/src/Resources/up123.jpg
Normal file
BIN
AntiAirCraftGun/src/Resources/up123.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
Loading…
Reference in New Issue
Block a user