From a879f47bfe1895c76175b9d20b47f67181c33029 Mon Sep 17 00:00:00 2001 From: Andrey_Abazov Date: Sun, 16 Oct 2022 16:42:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/src/AirBomberPackage/CanvasMy.java | 31 +++ AirBomber/src/AirBomberPackage/Direction.java | 16 ++ .../AirBomberPackage/DrawingAirBomber.java | 224 ++++++++++++++++++ .../src/AirBomberPackage/DrawingEngines.java | 61 +++++ AirBomber/src/AirBomberPackage/Engines.java | 15 ++ .../src/AirBomberPackage/EntityAirBomber.java | 43 ++++ .../src/AirBomberPackage/JFrameAirBomber.form | 192 ++++++++++++++- .../src/AirBomberPackage/JFrameAirBomber.java | 176 +++++++++++++- AirBomber/src/AirBomberPackage/arrowDown.png | Bin 0 -> 565 bytes AirBomber/src/AirBomberPackage/arrowLeft.png | Bin 0 -> 612 bytes AirBomber/src/AirBomberPackage/arrowRight.png | Bin 0 -> 619 bytes AirBomber/src/AirBomberPackage/arrowUp.png | Bin 0 -> 546 bytes 12 files changed, 754 insertions(+), 4 deletions(-) create mode 100644 AirBomber/src/AirBomberPackage/CanvasMy.java create mode 100644 AirBomber/src/AirBomberPackage/Direction.java create mode 100644 AirBomber/src/AirBomberPackage/DrawingAirBomber.java create mode 100644 AirBomber/src/AirBomberPackage/DrawingEngines.java create mode 100644 AirBomber/src/AirBomberPackage/Engines.java create mode 100644 AirBomber/src/AirBomberPackage/EntityAirBomber.java create mode 100644 AirBomber/src/AirBomberPackage/arrowDown.png create mode 100644 AirBomber/src/AirBomberPackage/arrowLeft.png create mode 100644 AirBomber/src/AirBomberPackage/arrowRight.png create mode 100644 AirBomber/src/AirBomberPackage/arrowUp.png diff --git a/AirBomber/src/AirBomberPackage/CanvasMy.java b/AirBomber/src/AirBomberPackage/CanvasMy.java new file mode 100644 index 0000000..6557a30 --- /dev/null +++ b/AirBomber/src/AirBomberPackage/CanvasMy.java @@ -0,0 +1,31 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package AirBomberPackage; + +import javax.swing.*; +import java.awt.*; + +/** + * + * @author Андрей + */ +public class CanvasMy extends JComponent { + public CanvasMy(){ + super(); + } + + private DrawingAirBomber _airBomber = null; + + public void setAirBomber(DrawingAirBomber _airBomber) { + this._airBomber = _airBomber; + } + + @Override + public void paintComponent(Graphics g){ + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + if (_airBomber != null) _airBomber.DrawTransport(g2d); + } +} diff --git a/AirBomber/src/AirBomberPackage/Direction.java b/AirBomber/src/AirBomberPackage/Direction.java new file mode 100644 index 0000000..7c7d402 --- /dev/null +++ b/AirBomber/src/AirBomberPackage/Direction.java @@ -0,0 +1,16 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package AirBomberPackage; + +/** + * + * @author Андрей + */ +public enum Direction { + UP, + DOWN, + LEFT, + RIGHT +} diff --git a/AirBomber/src/AirBomberPackage/DrawingAirBomber.java b/AirBomber/src/AirBomberPackage/DrawingAirBomber.java new file mode 100644 index 0000000..7720f00 --- /dev/null +++ b/AirBomber/src/AirBomberPackage/DrawingAirBomber.java @@ -0,0 +1,224 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package AirBomberPackage; +import java.awt.*; +import java.util.Random; +/** + * + * @author Андрей + */ +public class DrawingAirBomber { + private EntityAirBomber AirBomber; + public DrawingEngines drawingEngines; + public float _startPosX; + public float _startPosY; + private Integer _pictureWidth = null; + private Integer _pictureHeight = null; + private static final int _airBomberWidth = 110; + private static final int _airBomberHeight = 100; + + public void Init(int speed, float weight, Color bodyColor, int numberOfEngines){ + AirBomber = new EntityAirBomber(); + drawingEngines = new DrawingEngines(); + AirBomber.Init(speed, weight, bodyColor); + System.out.println(numberOfEngines + ""); + drawingEngines.setNumberOfEngines(numberOfEngines); + } + + public EntityAirBomber getAirBomber() { + return AirBomber; + } + + public void SetPosition(int x, int y, int width, int height){ + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth == null || _pictureHeight == null) + { + return; + } + Random rd = new Random(); + _startPosX = x + _airBomberWidth >= _pictureWidth ? rd.nextInt(0, _pictureWidth - 1 - _airBomberWidth) : x; + _startPosY = y + _airBomberHeight >= _pictureHeight ? rd.nextInt(0, _pictureHeight - 1 - _airBomberHeight) : y; + } + + public void MoveTransport(Direction direction) + { + if (_pictureWidth == null || _pictureHeight == null) + { + return; + } + switch (direction) + { + // вправо + case RIGHT: + if (_startPosX + _airBomberWidth + AirBomber.Step < _pictureWidth) + { + _startPosX += AirBomber.Step; + } + break; + //влево + case LEFT: + if (_startPosX - AirBomber.Step > 0) + { + _startPosX -= AirBomber.Step; + } + break; + //вверх + case UP: + if (_startPosY - AirBomber.Step > 0) + { + _startPosY -= AirBomber.Step; + } + break; + //вниз + case DOWN: + if (_startPosY + _airBomberHeight + AirBomber.Step < _pictureHeight) + { + _startPosY += AirBomber.Step; + } + break; + } + } + + public void DrawTransport(Graphics2D g) + { + if (_startPosX < 0 || _startPosY < 0 + || _pictureHeight == null || _pictureWidth == null) + { + return; + } + + int _startPosXInt = (int)_startPosX; + int _startPosYInt = (int)_startPosY; + + //отрисовка двигателей + drawingEngines.drawEngines(g, _startPosXInt, _startPosYInt, AirBomber.getBodyColor()); + + //отрисовка кабины + int[] cabinX = + { + _startPosXInt + 5, + _startPosXInt + 20, + _startPosXInt + 20 + }; + + int[] cabinY = + { + _startPosYInt + 50, + _startPosYInt + 40, + _startPosYInt + 60 + }; + + g.fillPolygon(cabinX, cabinY, cabinX.length); + g.setColor(AirBomber.getBodyColor()); + //отрисовка корпуса + g.fillRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20); + + //отрисовка правого крыла + int[] rightWingX = + { + _startPosXInt + 50, + _startPosXInt + 50, + _startPosXInt + 60, + _startPosXInt + 70 + }; + + int[] rightWingY = + { + _startPosYInt + 40, + _startPosYInt, + _startPosYInt, + _startPosYInt + 40 + }; + + g.fillPolygon(rightWingX, rightWingY, rightWingX.length); + + //отрисовка левого крыла + int[] leftWingX = + { + _startPosXInt + 50, + _startPosXInt + 50, + _startPosXInt + 60, + _startPosXInt + 70 + }; + + int[] leftWingY = + { + _startPosYInt + 60, + _startPosYInt + 100, + _startPosYInt + 100, + _startPosYInt + 60 + }; + + g.fillPolygon(leftWingX, leftWingY, leftWingX.length); + + //отрисовка хвоста (справа) + int[] rightTailX = + { + _startPosXInt + 95, + _startPosXInt + 95, + _startPosXInt + 110, + _startPosXInt + 110 + }; + + int[] rightTailY = + { + _startPosYInt + 40, + _startPosYInt + 30, + _startPosYInt + 15, + _startPosYInt + 40 + }; + + g.fillPolygon(rightTailX, rightTailY, rightTailX.length); + + //отрисовка хвоста (слева) + int[] leftTailX = + { + _startPosXInt + 95, + _startPosXInt + 95, + _startPosXInt + 110, + _startPosXInt + 110 + }; + + int[] leftTailY = + { + _startPosYInt + 60, + _startPosYInt + 70, + _startPosYInt + 85, + _startPosYInt + 60 + }; + + g.fillPolygon(leftTailX, leftTailY, leftTailX.length); + + g.setColor(Color.BLACK); + + g.drawRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20); + g.drawPolygon(rightWingX, rightWingY, rightWingX.length); + g.drawPolygon(leftWingX, leftWingY, leftWingX.length); + g.drawPolygon(rightTailX, rightTailY, rightTailX.length); + g.drawPolygon(leftTailX, leftTailY, leftTailX.length); + g.drawLine(_startPosXInt, _startPosYInt + 50, _startPosXInt + 5, _startPosYInt + 50); + } + + public void ChangeBorders(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth <= _airBomberWidth || _pictureHeight <= _airBomberHeight) + { + _pictureWidth = null; + _pictureHeight = null; + return; + } + if (_startPosX + _airBomberWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _airBomberWidth; + } + if (_startPosY + _airBomberHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _airBomberHeight; + } + } +} diff --git a/AirBomber/src/AirBomberPackage/DrawingEngines.java b/AirBomber/src/AirBomberPackage/DrawingEngines.java new file mode 100644 index 0000000..53e529f --- /dev/null +++ b/AirBomber/src/AirBomberPackage/DrawingEngines.java @@ -0,0 +1,61 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package AirBomberPackage; + +import java.awt.Graphics2D; +import java.awt.Color; + +/** + * + * @author Андрей + */ +public class DrawingEngines { + private Engines engines = null; + private int numberOfEngines; + + public int getNumberOfEngines() { + return numberOfEngines; + } + + public void setNumberOfEngines(int numberOfEngines) { + if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return; + this.numberOfEngines = numberOfEngines; + switch (this.numberOfEngines) { + case 2: + engines = Engines.TWO; + break; + case 4: + engines = Engines.FOUR; + break; + case 6: + engines = Engines.SIX; + break; + } + } + + private void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor){ + g.setColor(bodyColor); + g.fillRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5); + g.setColor(Color.BLACK); + g.drawRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5); + } + + public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor){ + if (engines == null) return; + + switch (engines) { + case SIX: + drawEngine(g, startPosX, startPosY, -5 - 5 - 20, bodyColor); + drawEngine(g, startPosX, startPosY, 20 + 5 + 20, bodyColor); + case FOUR: + drawEngine(g, startPosX, startPosY, -5 - 5 - 10, bodyColor); + drawEngine(g, startPosX, startPosY, 20 + 5 + 10, bodyColor); + case TWO: + drawEngine(g, startPosX, startPosY, -5 - 5, bodyColor); + drawEngine(g, startPosX, startPosY, 20 + 5, bodyColor); + break; + } + } +} diff --git a/AirBomber/src/AirBomberPackage/Engines.java b/AirBomber/src/AirBomberPackage/Engines.java new file mode 100644 index 0000000..4fa9b8b --- /dev/null +++ b/AirBomber/src/AirBomberPackage/Engines.java @@ -0,0 +1,15 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package AirBomberPackage; + +/** + * + * @author Андрей + */ +public enum Engines { + TWO, + FOUR, + SIX +} diff --git a/AirBomber/src/AirBomberPackage/EntityAirBomber.java b/AirBomber/src/AirBomberPackage/EntityAirBomber.java new file mode 100644 index 0000000..d72ade4 --- /dev/null +++ b/AirBomber/src/AirBomberPackage/EntityAirBomber.java @@ -0,0 +1,43 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package AirBomberPackage; +import java.awt.Color; +import java.util.Random; + +/** + * + * @author Андрей + */ +public class EntityAirBomber { + private int Speed; + + private float Weight; + + private Color BodyColor; + + public float Step; + + public int getSpeed() { + return Speed; + } + + public float getWeight() { + return Weight; + } + + public Color getBodyColor() { + return BodyColor; + } + + + + public void Init(int speed, float weight, Color bodyColor){ + Random rnd = new Random(); + Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed; + Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight; + Step = Speed * 100 / Weight; + BodyColor = bodyColor; + } +} diff --git a/AirBomber/src/AirBomberPackage/JFrameAirBomber.form b/AirBomber/src/AirBomberPackage/JFrameAirBomber.form index 769eecd..527555d 100644 --- a/AirBomber/src/AirBomberPackage/JFrameAirBomber.form +++ b/AirBomber/src/AirBomberPackage/JFrameAirBomber.form @@ -3,6 +3,16 @@
+ + + + + + + + + + @@ -23,13 +33,191 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AirBomber/src/AirBomberPackage/JFrameAirBomber.java b/AirBomber/src/AirBomberPackage/JFrameAirBomber.java index 57162eb..e970014 100644 --- a/AirBomber/src/AirBomberPackage/JFrameAirBomber.java +++ b/AirBomber/src/AirBomberPackage/JFrameAirBomber.java @@ -3,6 +3,9 @@ * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template */ package AirBomberPackage; +import java.awt.*; +import javax.swing.*; +import java.util.Random; /** * @@ -16,6 +19,8 @@ public class JFrameAirBomber extends javax.swing.JFrame { public JFrameAirBomber() { initComponents(); } + + private DrawingAirBomber _airBomber; /** * This method is called from within the constructor to initialize the form. @@ -26,22 +31,180 @@ public class JFrameAirBomber extends javax.swing.JFrame { // //GEN-BEGIN:initComponents private void initComponents() { + createAirBomberButton = new javax.swing.JButton(); + leftButton = new javax.swing.JButton(); + downButton = new javax.swing.JButton(); + rightButton = new javax.swing.JButton(); + upButton = new javax.swing.JButton(); + statusLabel = new javax.swing.JLabel(); + airBomberCanvas = new AirBomberPackage.CanvasMy(); + jLabelEngines = new javax.swing.JLabel(); + jComboBoxEngines = new javax.swing.JComboBox<>(); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Бомбардировщик"); + setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N + setPreferredSize(new java.awt.Dimension(700, 400)); + setSize(new java.awt.Dimension(700, 400)); + + createAirBomberButton.setText("Создать"); + createAirBomberButton.setName("createAirBomberButton"); // NOI18N + createAirBomberButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + createAirBomberButtonActionPerformed(evt); + } + }); + + leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N + leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); + leftButton.setMaximumSize(new java.awt.Dimension(30, 30)); + leftButton.setMinimumSize(new java.awt.Dimension(30, 30)); + leftButton.setName("buttonLeft"); // NOI18N + leftButton.setPreferredSize(new java.awt.Dimension(30, 30)); + leftButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + moveButtonActionPerformed(evt); + } + }); + + downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N + downButton.setMaximumSize(new java.awt.Dimension(30, 30)); + downButton.setMinimumSize(new java.awt.Dimension(30, 30)); + downButton.setName("buttonDown"); // NOI18N + downButton.setPreferredSize(new java.awt.Dimension(30, 30)); + downButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + moveButtonActionPerformed(evt); + } + }); + + rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N + rightButton.setMaximumSize(new java.awt.Dimension(30, 30)); + rightButton.setMinimumSize(new java.awt.Dimension(30, 30)); + rightButton.setName("buttonRight"); // NOI18N + rightButton.setPreferredSize(new java.awt.Dimension(30, 30)); + rightButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + moveButtonActionPerformed(evt); + } + }); + + upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N + upButton.setMaximumSize(new java.awt.Dimension(30, 30)); + upButton.setMinimumSize(new java.awt.Dimension(30, 30)); + upButton.setName("buttonUp"); // NOI18N + upButton.setPreferredSize(new java.awt.Dimension(30, 30)); + upButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + moveButtonActionPerformed(evt); + } + }); + + statusLabel.setText("Скорость: Вес: Цвет: Двигатели:"); + statusLabel.setMinimumSize(new java.awt.Dimension(0, 0)); + + airBomberCanvas.addComponentListener(new java.awt.event.ComponentAdapter() { + public void componentResized(java.awt.event.ComponentEvent evt) { + airBomberCanvasComponentResized(evt); + } + }); + + jLabelEngines.setText("Количество двигателей: "); + + jComboBoxEngines.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Два", "Четыре", "Шесть" })); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 400, Short.MAX_VALUE) + .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabelEngines) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(createAirBomberButton)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 369, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(17, 17, 17)) + .addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 300, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabelEngines, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(createAirBomberButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)) ); pack(); }// //GEN-END:initComponents + private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed + Random rnd = new Random(); + _airBomber = new DrawingAirBomber(); + _airBomber.Init(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), (jComboBoxEngines.getSelectedIndex() + 1) * 2); + System.out.println(((jComboBoxEngines.getSelectedIndex() + 1) * 2) + ""); + _airBomber.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), airBomberCanvas.getWidth(), airBomberCanvas.getHeight()); + statusLabel.setText("Скорость: " + _airBomber.getAirBomber().getSpeed() + " Вес: " + (int) _airBomber.getAirBomber().getWeight() + " Цвет: " + _airBomber.getAirBomber().getBodyColor() + " Двигатели: " + _airBomber.drawingEngines.getNumberOfEngines()); + airBomberCanvas.setAirBomber(_airBomber); + Draw(); + }//GEN-LAST:event_createAirBomberButtonActionPerformed + + private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed + if (_airBomber == null) return; + String name = ((JButton) evt.getSource()).getName(); + switch (name) + { + case "buttonUp": + _airBomber.MoveTransport(Direction.UP); + break; + case "buttonDown": + _airBomber.MoveTransport(Direction.DOWN); + break; + case "buttonLeft": + _airBomber.MoveTransport(Direction.LEFT); + break; + case "buttonRight": + _airBomber.MoveTransport(Direction.RIGHT); + break; + } + Draw(); + }//GEN-LAST:event_moveButtonActionPerformed + + private void airBomberCanvasComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_airBomberCanvasComponentResized + if (_airBomber == null) return; + _airBomber.ChangeBorders(airBomberCanvas.getWidth(), airBomberCanvas.getHeight()); + }//GEN-LAST:event_airBomberCanvasComponentResized + + private void Draw(){ + airBomberCanvas.repaint(); + } + /** * @param args the command line arguments */ @@ -78,5 +241,14 @@ public class JFrameAirBomber extends javax.swing.JFrame { } // Variables declaration - do not modify//GEN-BEGIN:variables + private AirBomberPackage.CanvasMy airBomberCanvas; + private javax.swing.JButton createAirBomberButton; + private javax.swing.JButton downButton; + private javax.swing.JComboBox jComboBoxEngines; + private javax.swing.JLabel jLabelEngines; + private javax.swing.JButton leftButton; + private javax.swing.JButton rightButton; + private javax.swing.JLabel statusLabel; + private javax.swing.JButton upButton; // End of variables declaration//GEN-END:variables } diff --git a/AirBomber/src/AirBomberPackage/arrowDown.png b/AirBomber/src/AirBomberPackage/arrowDown.png new file mode 100644 index 0000000000000000000000000000000000000000..7aa94559546965734348a4d7fcc9096649797396 GIT binary patch literal 565 zcmV-50?Pe~P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0m?~4K~zXf?U%cX z!ax*;Pu6Rz4dG?$5WI-LX=5Rb=MI_LA*83pId`3wXM_xn9rmZj8eHYuG>I}yP#G6u0& z%o+WVN~N5U8OFxwQs?zJD8|PBMPwWrk#T55#-R}zhel+~yNTC_{a<*OPZ=Ws>i7Hn zaL4$!4|yQ-4F&_cTrS>x*zAGvc#KV-QoG&ed4L$`cDsq)Zs!{(V;+wOAJ6A=VQ-66 zT(w#ihr>bG8$*s$9cMBbN+y%e5mB$#;|fQkk*fX^*a#wKyWLWuP@rG1sVcod~l$+ZTdQ;F;rQpQq}Znx`6Vs|2z%cW}$ z#*Ie9H3t=oMJ^K9ox40Bk1>SGB(+-2lk}5vxtv(7R{UL@6Mp$2Ut=j$3f}#Ux)O{UXR?XJF00000NkvXXu0mjf DfK~lF literal 0 HcmV?d00001 diff --git a/AirBomber/src/AirBomberPackage/arrowLeft.png b/AirBomber/src/AirBomberPackage/arrowLeft.png new file mode 100644 index 0000000000000000000000000000000000000000..8853e4813af52fefafeb6e90eb1fadb5ea8bd829 GIT binary patch literal 612 zcmV-q0-ODbP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0r^QpK~zXf#g@IU z0Z|l%*G&8sLZucW5f7nMdISm&AW=$GdW}XD8V{hN5z%@HBJm2uKXYg8duC!TZgbCZ zzl1aUOfoC$%-(ypbvPUx`~$XHUlNPOkRM#SG9HN~RQD9-0I9LK@& zcvN@v@X|3whr^+Wl5V%F-Sv}W%d*5NSC7l(BCc<@o7(w1PmU?tZnsqgG@DI?LLsf9 zB;eS#ZA2oGfLl5}oldgqB;c5$wOUO@K)>IYRktYd9rHNpEFO=`jc_3_? zsZ>f5$C=G$e9s^I5sQCbYy1?hvh@qB$it);`p&?v|24$@Atc`x}a0$O{dcV zm|Vnd7XCYEG#avJ3TpZdgqh8z;g!&Cx0AkYs-yxfb26EzD@Ze8Q!z#0BSF{cbQ+t@ zM&jjiiA*MAB;x~)-Q&k}I#m%+DwX7mWrDy{nQ{4i9>ro&Vs^6me6D@^Ac3PMe6Rcc z9?4`Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0su)wK~zXf#g;pY z0zni-Z~Mp3B2;h>h9;W02Ep7w#6Zjh*B~e+V&DoiP;eU>_yJQRLGX(`-e-4@*d>UCosn2ZKSBN+r~4HF^II zrDyE*dL?Zv78A|X=kpo2+fDQ{N)!A2e)Ri&O96#K0f9ikQXf%X)uB*G9wsNd-45Y! z7}x7nw2hXk9*suU8<5ZE;q&<{^^TT4X5vI5f%SSVdOn{cl}b6gK(r)gF-;~DO99zz z_ET$VF=izvlSyPU8PS`~2IKKqcEU#6$mF?lYopPqqc4{Wj>n^D&{!wsa+$&8X}8<* z8$AuaR4NtOhM(r^Z}E5@C)sQ^WhHmJN0HH(`mdg9wMxrJV%16A;QZz}YpH5ChQpz( z#=X+a?RF~zUNuZNo6V3;r$uw9ESF13Eba8wNK*m-m;Jn2twb*t3&i7b>2qy;%r4>3 z$mMdPIZUS0snf?=jd>+*tTs#B50>I~cmtsPfcQrp(cS<6002ovPDHLk FV1j1Y7exR7 literal 0 HcmV?d00001 diff --git a/AirBomber/src/AirBomberPackage/arrowUp.png b/AirBomber/src/AirBomberPackage/arrowUp.png new file mode 100644 index 0000000000000000000000000000000000000000..c5c08cc47ec54489016b003757adc54da5323f07 GIT binary patch literal 546 zcmV+-0^R+IP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0k=s+K~zXf?Uy^Q zfg!bJB$;X){EOlU9`7A7_VMqZNiv_RMYMN-=I-L$bpU*V@cDrT9 zQ)`^6XnZmYhEl7MB)51s+d`^Cl5LV04@AtKfTCG;%!2zSuC^2TY+eJQ* z^#F>ep8LK}erQG8>3+Yn{eCZ7jJ6E6%67YDLY(&M^ZAtCY%m7a>-Ct3&qRXK^NN2s z9ArzNrmmLybUN|rbV_xg{K`PyjN{`}JoHZ{6RHE{k7g|TC|k_bahxdoZ&C43x~{9m z)81S`5d29nO>eVE_OC07*qoM6N<$f)9lHHUIzs literal 0 HcmV?d00001 -- 2.25.1