diff --git a/SelfPropelledArtilleryUnit_Hard/.gitignore b/SelfPropelledArtilleryUnit_Hard/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit_Hard/.idea/.gitignore b/SelfPropelledArtilleryUnit_Hard/.idea/.gitignore new file mode 100644 index 0000000..eaf91e2 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/SelfPropelledArtilleryUnit_Hard/.idea/misc.xml b/SelfPropelledArtilleryUnit_Hard/.idea/misc.xml new file mode 100644 index 0000000..90ca720 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit_Hard/.idea/modules.xml b/SelfPropelledArtilleryUnit_Hard/.idea/modules.xml new file mode 100644 index 0000000..c66a155 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit_Hard/.idea/uiDesigner.xml b/SelfPropelledArtilleryUnit_Hard/.idea/uiDesigner.xml new file mode 100644 index 0000000..6d50cd4 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_down.png b/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_down.png new file mode 100644 index 0000000..7aa3255 Binary files /dev/null and b/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_down.png differ diff --git a/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_left.png b/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_left.png new file mode 100644 index 0000000..9a3dfa2 Binary files /dev/null and b/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_left.png differ diff --git a/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_right.png b/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_right.png new file mode 100644 index 0000000..0f06fd0 Binary files /dev/null and b/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_right.png differ diff --git a/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_up.png b/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_up.png new file mode 100644 index 0000000..67ae4bc Binary files /dev/null and b/SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_up.png differ diff --git a/SelfPropelledArtilleryUnit_Hard/SelfPropelledArtilleryUnit_Hard.iml b/SelfPropelledArtilleryUnit_Hard/SelfPropelledArtilleryUnit_Hard.iml new file mode 100644 index 0000000..ceb0789 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/SelfPropelledArtilleryUnit_Hard.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit_Hard/src/CrawlerRollersCount.java b/SelfPropelledArtilleryUnit_Hard/src/CrawlerRollersCount.java new file mode 100644 index 0000000..d016394 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/src/CrawlerRollersCount.java @@ -0,0 +1,14 @@ +public enum CrawlerRollersCount { + Four(4), + Five(5), + Six(6); + + private int numOfRollers; + CrawlerRollersCount(int numOfRollers){ + this.numOfRollers = numOfRollers; + } + public int getNumOfRollers(){ + return numOfRollers; + } +} + diff --git a/SelfPropelledArtilleryUnit_Hard/src/DirectionType.java b/SelfPropelledArtilleryUnit_Hard/src/DirectionType.java new file mode 100644 index 0000000..913ef3f --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/src/DirectionType.java @@ -0,0 +1,6 @@ +public enum DirectionType { + Up, + Down, + Left, + Right +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit_Hard/src/DrawingCrawlerRollers.java b/SelfPropelledArtilleryUnit_Hard/src/DrawingCrawlerRollers.java new file mode 100644 index 0000000..e5867df --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/src/DrawingCrawlerRollers.java @@ -0,0 +1,24 @@ +import java.awt.*; + +public class DrawingCrawlerRollers { + private CrawlerRollersCount rollersCount; + public void setCrawlerRollersCount(int numOfRoller){ + for (CrawlerRollersCount numofenum : CrawlerRollersCount.values()){ + if (numofenum.getNumOfRollers() == numOfRoller){ + rollersCount = numofenum; + return; + } + } + } + + public CrawlerRollersCount getCrawlerRollersCount(){ + return rollersCount; + } + public void DrawRollers(Graphics g, int x, int y, int width, int height, Color bodyColor){ + g.setColor(bodyColor); + g.fillOval(x, y, width, height); + g.setColor(Color.BLACK); + g.drawOval(x, y, width, height); + g.setColor(bodyColor); + } +} diff --git a/SelfPropelledArtilleryUnit_Hard/src/DrawingSelfPropelledArtilleryUnit.java b/SelfPropelledArtilleryUnit_Hard/src/DrawingSelfPropelledArtilleryUnit.java new file mode 100644 index 0000000..56992a3 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/src/DrawingSelfPropelledArtilleryUnit.java @@ -0,0 +1,183 @@ +import java.awt.*; +import java.util.Random; + +public class DrawingSelfPropelledArtilleryUnit { + private EntitySelfPropelledArtilleryUnit entitySelfPropelledArtilleryUnit; + public DrawingCrawlerRollers drawingCrawlerRollers = null; + private Integer pictureWidth; + private Integer pictureHeight; + private Integer _startPosX; + private Integer _startPosY; + private final int drawingSelfPropelledArtilleryUnitWidth = 100; + private final int drawingSelfPropelledArtilleryUnitHeight = 50; + private final int drawingKeelHeight = 35; + private DrawingCrawlerRollers _drawingCrawlerRollers; + public EntitySelfPropelledArtilleryUnit EntitySelfPropelledArtilleryUnit() { + return entitySelfPropelledArtilleryUnit; + } + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean turretCannon, boolean launchBattery) { + entitySelfPropelledArtilleryUnit = new EntitySelfPropelledArtilleryUnit(); + entitySelfPropelledArtilleryUnit.Init(speed, weight, bodyColor, additionalColor, turretCannon, launchBattery); + pictureHeight = null; + pictureWidth = null; + _startPosX = null; + _startPosY = null; + drawingCrawlerRollers = new DrawingCrawlerRollers(); + Random random = new Random(); + int rand = random.nextInt(3,7); + drawingCrawlerRollers.setCrawlerRollersCount(rand); + } + + public void setPictureSize(int width, int height) { + pictureWidth = width; + pictureHeight = height; + } + + public void setPosition(int x, int y) { + if (pictureHeight == null || pictureWidth == null) { + return; + } + + if (x < 0) { + x = 0; + } else if (x - drawingSelfPropelledArtilleryUnitWidth >= pictureWidth) { + x = pictureWidth - drawingSelfPropelledArtilleryUnitWidth - drawingSelfPropelledArtilleryUnitWidth; + } + + if (y - drawingKeelHeight < 0) { + y = drawingKeelHeight; + } else if (y - drawingSelfPropelledArtilleryUnitHeight >= pictureHeight) { + y = pictureHeight - drawingSelfPropelledArtilleryUnitHeight - drawingSelfPropelledArtilleryUnitHeight; + } + + _startPosY = y; + _startPosX = x; + } + + public boolean moveTransport(DirectionType direction) { + if (entitySelfPropelledArtilleryUnit == null || _startPosX == null || _startPosY == null || pictureWidth == null || pictureHeight == null) { + return false; + } + + return switch (direction) { + case Left -> { + if (_startPosX - entitySelfPropelledArtilleryUnit.getStep() >= 0) { + _startPosX -= (int) entitySelfPropelledArtilleryUnit.getStep(); + } + yield true; + } + case Up -> { + if (_startPosY - drawingKeelHeight - entitySelfPropelledArtilleryUnit.getStep() >= 0) { + _startPosY -= (int) entitySelfPropelledArtilleryUnit.getStep(); + } + yield true; + } + case Right -> { + if (_startPosX + entitySelfPropelledArtilleryUnit.getStep() <= pictureWidth - drawingSelfPropelledArtilleryUnitWidth) { + _startPosX += (int) entitySelfPropelledArtilleryUnit.getStep(); + } + yield true; + } + case Down -> { + if (_startPosY + entitySelfPropelledArtilleryUnit.getStep() <= pictureHeight - drawingSelfPropelledArtilleryUnitHeight + drawingKeelHeight) { + _startPosY += (int) entitySelfPropelledArtilleryUnit.getStep(); + } + yield true; + } + default -> false; + }; + } + + public void drawTransport(Graphics g) { + if (entitySelfPropelledArtilleryUnit == null || _startPosX == null || _startPosY == null) { + return; + } + + Graphics2D g2d = (Graphics2D) g; + g2d.setColor(Color.BLACK); + g.drawOval(_startPosX + 0, _startPosY + 75, 30, 30); + g.drawOval(_startPosX + 90, _startPosY + 75, 30, 30); + g.drawRect(_startPosX + 15, _startPosY + 75, 90, 30); + + //границы ЦВЕТ + g.fillRect(_startPosX + 25, _startPosY + 40, 35, 30);//башня + g.fillOval(_startPosX + 0, _startPosY + 75, 30, 30); + g.fillOval(_startPosX + 90, _startPosY + 75, 30, 30); + g.fillRect(_startPosX + 15, _startPosY + 75, 90, 30); + + // границы арт. установки + g.drawRect(_startPosX + 25, _startPosY + 40, 35, 30); + g.drawRect(_startPosX + 0, _startPosY + 65, 120, 13); + + // верхние катки ОТРИСОВКА + g.drawOval(_startPosX + 30, _startPosY + 70, 20, 20); + g.drawOval(_startPosX + 50, _startPosY + 70, 20, 20); + g.drawOval(_startPosX + 70, _startPosY + 70, 20, 20); + + //нижние катки ОТРИСОВКА + g.drawOval(_startPosX + 30, _startPosY + 90, 15, 15); + g.drawOval(_startPosX + 45, _startPosY + 90, 15, 15); + g.drawOval(_startPosX + 60, _startPosY + 90, 15, 15); + g.drawOval(_startPosX + 75, _startPosY + 90, 15, 15); + + g.fillOval(_startPosX + 3, _startPosY + 78, 24, 24); + g.fillOval(_startPosX + 93, _startPosY + 78, 24, 24); + + int x = _startPosX; + if (drawingCrawlerRollers.getCrawlerRollersCount() != null){ + switch (drawingCrawlerRollers.getCrawlerRollersCount()){ + case Four: + drawingCrawlerRollers.DrawRollers(g,x + 15, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor()); + break; + case Five: + drawingCrawlerRollers.DrawRollers(g,x + 15, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor()); + drawingCrawlerRollers.DrawRollers(g,x + 90, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor()); + break; + case Six: + drawingCrawlerRollers.DrawRollers(g,x + 15, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor()); + drawingCrawlerRollers.DrawRollers(g,x + 90, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor()); + drawingCrawlerRollers.DrawRollers(g,x + 90, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor()); + break; + } + } + + g2d.setColor(entitySelfPropelledArtilleryUnit.getBodyColor()); + // верхние катки ЦВЕТ + g.fillOval(_startPosX + 30, _startPosY + 70, 20, 20); + g.fillOval(_startPosX + 50, _startPosY + 70, 20, 20); + g.fillOval(_startPosX + 70, _startPosY + 70, 20, 20); + + //нижние катки ЦВЕТ + g.fillOval(_startPosX + 30, _startPosY + 90, 15, 15); + g.fillOval(_startPosX + 45, _startPosY + 90, 15, 15); + g.fillOval(_startPosX + 60, _startPosY + 90, 15, 15); + g.fillOval(_startPosX + 75, _startPosY + 90, 15, 15); + + //Большие катки ОТРИСОВКА + g.drawOval(_startPosX + 3, _startPosY + 78, 24, 24); + g.drawOval(_startPosX + 93, _startPosY + 78, 24, 24); + + g.fillRect(_startPosX + 0, _startPosY + 65, 120, 13); + + + // Орудийная башня + if (entitySelfPropelledArtilleryUnit.getTurretCannon()) { + g.fillOval(_startPosX + 26, _startPosY + 35, 50, 30); + g.fillRect(_startPosX + 25, _startPosY + 36, 20, 29); + g.fillRect(_startPosX + 60, _startPosY + 45, 60, 5); + g.fillOval(_startPosX + 113, _startPosY + 42, 20, 10); + } + g.setColor(Color.RED); + // Пусковая батарея + if (entitySelfPropelledArtilleryUnit.getLaunchBattery()) { + g.fillRect(_startPosX + 0, _startPosY + 45, 20, 20); + int[] xPoints = {_startPosX + 0, _startPosX + 0, _startPosX + 20, _startPosX + 20, _startPosX + 0}; + int[] yPoints = {_startPosY + 15, _startPosY + 65, _startPosY + 65, _startPosY + 45, _startPosY + 15}; + g.fillPolygon(xPoints, yPoints, 5); + g.fillOval(_startPosX + 0, _startPosY + 5, 10, 30); + g.fillRect(_startPosX + 10, _startPosY + 15, 20, 5); + g.fillRect(_startPosX + 10, _startPosY + 25, 15, 5); + } + } +} + diff --git a/SelfPropelledArtilleryUnit_Hard/src/EntitySelfPropelledArtilleryUnit.java b/SelfPropelledArtilleryUnit_Hard/src/EntitySelfPropelledArtilleryUnit.java new file mode 100644 index 0000000..d681057 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/src/EntitySelfPropelledArtilleryUnit.java @@ -0,0 +1,48 @@ +import java.awt.*; + +public class EntitySelfPropelledArtilleryUnit { + private int Speed; + public int getSpeed() { + return Speed; + } + + private double Weight; + + public double getWeight() { + return Weight; + } + + private Color BodyColor; + public Color getBodyColor() { + return BodyColor; + } + + private Color AdditionalColor; + public Color getAdditionalColor() { + return AdditionalColor; + } + + private double Step; + public double getStep() { + return (double)Speed * 100 / Weight; + } + + private boolean TurretCannon; + public boolean getTurretCannon() { + return TurretCannon; + } + + private boolean LaunchBattery; + public boolean getLaunchBattery() { + return LaunchBattery; + } + + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean turretCannon, boolean launchBattery) { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + TurretCannon = turretCannon; + LaunchBattery = launchBattery; + } +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit_Hard/src/FormSelfPropelledArtilleryUnit.form b/SelfPropelledArtilleryUnit_Hard/src/FormSelfPropelledArtilleryUnit.form new file mode 100644 index 0000000..7743b24 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/src/FormSelfPropelledArtilleryUnit.form @@ -0,0 +1,93 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/SelfPropelledArtilleryUnit_Hard/src/FormSelfPropelledArtilleryUnit.java b/SelfPropelledArtilleryUnit_Hard/src/FormSelfPropelledArtilleryUnit.java new file mode 100644 index 0000000..a652d44 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/src/FormSelfPropelledArtilleryUnit.java @@ -0,0 +1,107 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; + +public class FormSelfPropelledArtilleryUnit { + protected DrawingSelfPropelledArtilleryUnit _drawningSeaplane = new DrawingSelfPropelledArtilleryUnit(); + JPanel PanelWrapper; + private JPanel PictureBox; + private JButton buttonCreate; + private JButton buttonRight; + private JButton buttonLeft; + private JButton buttonDown; + private JButton buttonUp; + + private List controls; + public FormSelfPropelledArtilleryUnit() { + buttonUp.setName("buttonUp"); + buttonDown.setName("buttonDown"); + buttonLeft.setName("buttonLeft"); + buttonRight.setName("buttonRight"); + + InitializeControlsRepaintList(); + + buttonCreate.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + _drawningSeaplane = new DrawingSelfPropelledArtilleryUnit(); + Random random = new Random(); + _drawningSeaplane.Init(random.nextInt(30, 100), + random.nextInt(100, 500), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + random.nextBoolean(), random.nextBoolean() ); + _drawningSeaplane.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight()); + _drawningSeaplane.setPosition(random.nextInt(35, 100), + random.nextInt(35, 100)); + Draw(); + + } + }); + ActionListener buttonMoveClickedListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String buttonName = ((JButton) e.getSource()).getName(); + boolean result = false; + + switch (buttonName) { + case "buttonUp": { + result = _drawningSeaplane.moveTransport(DirectionType.Up); + } + break; + case "buttonDown": { + result = _drawningSeaplane.moveTransport(DirectionType.Down); + } + break; + case "buttonLeft": { + result = _drawningSeaplane.moveTransport(DirectionType.Left); + } + break; + case "buttonRight": { + result = _drawningSeaplane.moveTransport(DirectionType.Right); + } + break; + + }; + + if (result) { + Draw(); + }; + }; + }; + buttonRight.addActionListener(buttonMoveClickedListener); + buttonDown.addActionListener(buttonMoveClickedListener); + buttonLeft.addActionListener(buttonMoveClickedListener); + buttonUp.addActionListener(buttonMoveClickedListener); + + } + private void Draw() { + if (_drawningSeaplane.EntitySelfPropelledArtilleryUnit() == null) { + return; + } + Graphics g = PictureBox.getGraphics(); + g.setColor(PictureBox.getBackground()); + g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight()); + _drawningSeaplane.drawTransport(g); + + RepaintControls(); + } + private void RepaintControls() { + for (JComponent control : controls) { + control.repaint(); + } + } + + private void InitializeControlsRepaintList() { + controls = new LinkedList<>(); + controls.add(buttonCreate); + controls.add(buttonUp); + controls.add(buttonDown); + controls.add(buttonLeft); + controls.add(buttonRight); + } +} diff --git a/SelfPropelledArtilleryUnit_Hard/src/Main.java b/SelfPropelledArtilleryUnit_Hard/src/Main.java new file mode 100644 index 0000000..cbfe257 --- /dev/null +++ b/SelfPropelledArtilleryUnit_Hard/src/Main.java @@ -0,0 +1,14 @@ +import javax.swing.*; + +public class Main { + public static void main(String[] args) { + JFrame.setDefaultLookAndFeelDecorated(false); + JFrame frame = new JFrame("FormSeaplane"); + frame.setContentPane(new FormSelfPropelledArtilleryUnit().PanelWrapper); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocation(500, 200); + frame.pack(); + frame.setSize(1000, 500); + frame.setVisible(true); + } +} \ No newline at end of file