Compare commits

...

6 Commits

Author SHA1 Message Date
2a1c499096 finally 2022-11-21 23:55:09 +04:00
1c92c5b0eb com3 2022-11-08 14:55:22 +04:00
666de2bf79 Изменил(а) на 'FormPlane.java' 2022-11-08 14:54:21 +04:00
91db5cf763 Изменил(а) на 'EntityPlane.java' 2022-11-08 14:54:01 +04:00
5324095e2a Изменил(а) на 'DrawingPlane.java' 2022-11-08 14:53:44 +04:00
968bae0c5b First commit 2022-10-20 23:43:35 +04:00
5 changed files with 117 additions and 51 deletions

3
DopIlum.java Normal file
View File

@ -0,0 +1,3 @@
enum DopIlum {
Ten, Twenty, Thirty
}

View File

@ -1,31 +1,29 @@
import java.awt.*;
public class DrawingPlane {
public EntityPlane Plane;
public EntityPlane getPlane()
{
return Plane;
}
public class DrawingAirbus {
public EntityAirbus Airbus;
private float _startPosX;
private float _startPosY;
private Integer _pictureWidth = null;
private Integer _pictureHeight = null;
private final int _planeWidth = 125;
private final int _planeHeight = 45;
private final int _airbusWidth = 125;
private final int _airbusHeight = 45;
public void Init(int speed, float weight, Color bodyColor, int ilNum, EntityPlane entity)
public DrawingIlum drawingilum;
public void Init(int speed, float weight, Color bodyColor, int ilNum, EntityAirbus entity)
{
Plane = new EntityPlane();
Plane.Init(speed, weight, bodyColor);
Airbus = entity;
drawingilum = new DrawingIlum();
drawingilum.Init(ilNum, bodyColor);
Airbus.Init(speed, weight, bodyColor);
}
public void SetPosition(int x, int y, int width, int height)
{
if (x < 0 || x + _planeWidth >= width)
if (x < 0 || x + _airbusWidth >= width)
{
return;
}
if (y < 0 || y + _planeHeight >= height)
if (y < 0 || y + _airbusHeight >= height)
{
return;
}
@ -44,44 +42,47 @@ public class DrawingPlane {
{
// вправо
case Right:
if (_startPosX + _planeWidth + Plane.Step() < _pictureWidth)
if (_startPosX + _airbusWidth + Airbus.Step() < _pictureWidth)
{
_startPosX += Plane.Step();
_startPosX += Airbus.Step();
}
else _startPosX = _pictureWidth - _airbusWidth;
break;
//влево
case Left:
if (_startPosX - Plane.Step() > 0)
if (_startPosX - Airbus.Step() >= 0)
{
_startPosX -= Plane.Step();
_startPosX -= Airbus.Step();
}
else _startPosX = 0;
break;
//вверх
case Up:
if (_startPosY - Plane.Step() > 0)
if (_startPosY - Airbus.Step() >= 0)
{
_startPosY -= Plane.Step();
_startPosY -= Airbus.Step();
}
else _startPosY = 0;
break;
//вниз
case Down:
if (_startPosY + _planeHeight + Plane.Step() < _pictureHeight)
if (_startPosY + _airbusHeight + Airbus.Step() < _pictureHeight)
{
_startPosY += Plane.Step();
_startPosY += Airbus.Step();
}
else _startPosY = _pictureHeight - _airbusWidth;
break;
}
}
public void DrawTransport(Graphics g)
public void DrawTransport(Graphics2D g)
{
if (_startPosX < 0 || _startPosY < 0
|| _pictureHeight == null|| _pictureWidth == 0)
{
return;
}
g.setColor(Color.BLACK);
g.setColor(Color.black);
g.drawOval((int)_startPosX, (int)_startPosY + 20, 20, 20);
g.drawRect((int)_startPosX + 8, (int)_startPosY + 20, 100, 20);
@ -104,7 +105,7 @@ public class DrawingPlane {
// корпус
g.setColor(Plane.getBodyColor());
g.setColor(Airbus.getBodyColor());
g.fillOval((int)_startPosX, (int)_startPosY + 20, 20, 20);
g.fillRect((int)_startPosX + 8, (int)_startPosY + 20, 100, 20);
@ -120,6 +121,12 @@ public class DrawingPlane {
new int[] {(int)_startPosY + 20, (int)_startPosY, (int)_startPosY + 20}, 3
);
g.setColor(Color.blue);
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillOval((int) _startPosX + tempX, (int)_startPosY + 20, 4, 4);
}
drawingilum.DrawIl((int)_startPosX, (int)_startPosY, g);
g.fillPolygon
(
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
@ -138,28 +145,28 @@ public class DrawingPlane {
g.fillOval((int)_startPosX, (int)_startPosY + 18, 7, 7);
g.fillOval((int)_startPosX + 20, (int)_startPosY + 18, 7, 7);
g.fillRect((int)_startPosX + 41, (int)_startPosY + 28, 42, 4);
g.fillOval((int)_startPosX + 39, (int)_startPosY + 28, 4, 4);
g.fillOval((int)_startPosX + 81, (int)_startPosY + 28, 4, 4);
g.fillRect((int)_startPosX + 41, (int)_startPosY + 34, 42, 4);
g.fillOval((int)_startPosX + 39, (int)_startPosY + 34, 4, 4);
g.fillOval((int)_startPosX + 81, (int)_startPosY + 34, 4, 4);
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _planeWidth || _pictureHeight <= _planeHeight)
if (_pictureWidth <= _airbusWidth || _pictureHeight <= _airbusHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _planeWidth > _pictureWidth)
if (_startPosX + _airbusWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _planeWidth;
_startPosX = _pictureWidth - _airbusWidth;
}
if (_startPosY + _planeHeight > _pictureHeight)
if (_startPosY + _airbusHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _planeHeight;
_startPosY = _pictureHeight - _airbusHeight;
}
}
}

49
DrawingIlum.java Normal file
View File

@ -0,0 +1,49 @@
import java.awt.*;
public class DrawingIlum {
private DopIlum il = DopIlum.Ten;
public void setIl(int num){
switch(num)
{
case 0:
il = DopIlum.Twenty;
break;
case 1:
il = DopIlum.Thirty;
break;
default:
break;
}
}
private Color color;
public void Init(int num, Color color) {
setIl(num);
this.color = color;
}
public void DrawIl(int startPosX, int startPosY, Graphics2D g) {
g.setColor(Color.blue);
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillOval((int) startPosX + tempX, (int) startPosY + 20, 4, 4);
}
switch (il) {
case Twenty: {
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillOval((int) startPosX + tempX, (int) startPosY + 26, 4, 4);
}
break;
}
case Thirty: {
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillOval((int) startPosX + tempX, (int) startPosY + 25, 4, 4);
g.fillOval((int) startPosX + tempX, (int) startPosY + 30, 4, 4);
}
break;
}
default:
break;
}
}
}

View File

@ -1,9 +1,9 @@
import java.awt.Color;
import java.util.Random;
public class EntityPlane {
private int Speed;
private float Weight;
public class EntityAirbus {
private int Speed = 0;
private float Weight = 0;
private Color BodyColor;
public int getSpeed(){return Speed;}
@ -16,7 +16,13 @@ public class EntityPlane {
{
Random rand = new Random();
if (speed <= 0) speed = rand.nextInt(350, 550);
else {
Speed = speed;
};
if (weight <= 0) weight = rand.nextFloat(350, 550);
else {
Weight = weight;
}
BodyColor = bodyColor;
}
}

View File

@ -3,12 +3,12 @@ import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class FormPlane extends JComponent
public class FormAirbus extends JComponent
{
private DrawingPlane _plane;
private EntityPlane _entity;
private DrawingAirbus _plane;
private EntityAirbus _entity;
public FormPlane()
public FormAirbus()
{
JFrame formFrame = new JFrame("Plane");
formFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -46,15 +46,16 @@ public class FormPlane extends JComponent
Label colorLabel = new Label("Color:");
JButton createButton = new JButton("Create");
createButton.addActionListener(e -> {
Random rand = new Random();
_plane = new DrawingPlane();
_entity = new EntityPlane();
_plane.Init(300 + rand.nextInt( 100), 1000 + rand.nextInt(1000), Color.getHSBColor(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)), rand.nextInt(3), _entity);
_plane = new DrawingAirbus();
_entity = new EntityAirbus();
_plane.Init(rand.nextInt( 400 + rand.nextInt(200)), 1000 + rand.nextInt(1000), Color.getHSBColor(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)), rand.nextInt(3), _entity);
_plane.SetPosition(10 + rand.nextInt(90), 10 + rand.nextInt(90), formFrame.getWidth(), formFrame.getHeight() - 75);
speedLabel.setText("Speed: " + _plane.Plane.getSpeed());
weightLabel.setText("Weight: " + (int)_plane.Plane.getWeight());
colorLabel.setText("Color: " + _plane.Plane.getBodyColor().getRed() + " " + _plane.Plane.getBodyColor().getGreen() + " " + _plane.Plane.getBodyColor().getBlue() );
speedLabel.setText("Speed: " + _plane.Airbus.getSpeed());
weightLabel.setText("Weight: " + (int)_plane.Airbus.getWeight());
colorLabel.setText("Color: " + _plane.Airbus.getBodyColor().getRed() + " " + _plane.Airbus.getBodyColor().getGreen() + " " + _plane.Airbus.getBodyColor().getBlue() );
repaint();
});
@ -84,10 +85,10 @@ public class FormPlane extends JComponent
repaint();
});
statusPanel.add(moveRightButton);
statusPanel.add(moveLeftButton);
statusPanel.add(moveUpButton);
statusPanel.add(moveDownButton);
statusPanel.add(moveLeftButton);
statusPanel.add(moveRightButton);
formFrame.getContentPane().add(this);
}
@ -99,8 +100,8 @@ public class FormPlane extends JComponent
super.repaint();
}
public static void main(String[] args) throws Exception {
new FormPlane();
public static void main(String[] args) {
new FormAirbus();
}
}