This commit is contained in:
dex_moth 2023-11-18 12:42:03 +04:00
parent abcf145b71
commit ec2c529fa5
27 changed files with 553 additions and 0 deletions

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-21 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/PIbd-22_Isaeva_A.I._Airbus_Hard.iml" filepath="$PROJECT_DIR$/PIbd-22_Isaeva_A.I._Airbus_Hard.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

69
.idea/workspace.xml Normal file
View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="4ad590c0-5ac3-4af8-9d5f-82f5c307cd9c" name="Changes" comment="clean" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="main" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 8
}]]></component>
<component name="ProjectId" id="2YLEaNaqu94PwzQjd2r7Rir4Z96" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "lab1",
"last_opened_file_path": "E:/GitLab/PIbd-22_Isaeva_A.I._Airbus_Hard"
}
}]]></component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="E:\GitLab\PIbd-22_Isaeva_A.I._Airbus_Hard" />
</key>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="4ad590c0-5ac3-4af8-9d5f-82f5c307cd9c" name="Changes" comment="" />
<created>1700296521973</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1700296521973</updated>
</task>
<task id="LOCAL-00001" summary="clean">
<option name="closed" value="true" />
<created>1700296643884</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1700296643884</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="clean" />
<option name="LAST_COMMIT_MESSAGE" value="clean" />
</component>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

BIN
images/KeyDown.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
images/KeyLeft.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
images/KeyRight.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
images/KeyUp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,144 @@
package Drawnings;
import java.awt.*;
import Entities.*;
import MovementStrategy.*;
public class DrawingAirbus {
public EntityAirbus entityAirbus;
public DrawingPortholes _portholes;
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
private int _airbusWidth = 123;
private int _airbusHeight = 44;
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isadditionalEngine, int countPortholes, int width, int height) {
if (width < _airbusHeight || height < _airbusWidth)
return;
_pictureWidth = width;
_pictureHeight = height;
entityAirbus = new EntityAirbus();
entityAirbus.Init(speed, weight, bodyColor, additionalColor, isCompartment, isadditionalEngine);
_portholes = new DrawingPortholes();
_portholes.SetCount(countPortholes);
}
public void SetPosition (int x, int y) {
if (x + _airbusWidth > _pictureWidth || y + _airbusHeight > _pictureHeight) {
_startPosX = _pictureWidth - _airbusWidth;
_startPosY = _pictureHeight - _airbusHeight;
}
else
{
_startPosX = x;
_startPosY = y;
}
}
public void MoveTransport(Direction direction){
if (entityAirbus == null) {
return;
}
switch (direction) {
case Left:
if (_startPosX - entityAirbus.Step > 0)
{
_startPosX -= entityAirbus.Step;
}
break;
case Right:
if (_startPosX + _airbusWidth + entityAirbus.Step < _pictureWidth)
{
_startPosX += entityAirbus.Step;
}
break;
case Up:
if (_startPosY - entityAirbus.Step > 0)
{
_startPosY -= entityAirbus.Step;
}
break;
case Down:
if (_startPosY + _airbusHeight + entityAirbus.Step < _pictureHeight)
{
_startPosY += entityAirbus.Step;
}
break;
}
}
public void DrawTransport(Graphics2D g) {
if (entityAirbus == null) {
return;
}
// тело
g.setColor(entityAirbus.getBodyColor());
g.fillRect(_startPosX+3, _startPosY+17, 103, 20);
g.setColor(Color.BLACK);
g.drawRect(_startPosX+3, _startPosY+17, 103, 20);
// иллюминаторы
_portholes.Draw(g, _startPosX, _startPosY);
// нос
int[] xPolygonNoise = {_startPosX+106, _startPosX + 120, _startPosX+106,};
int[] yPolygonNoise = {_startPosY+17, _startPosY+27, _startPosY+37};
g.setColor(entityAirbus.getBodyColor());
g.fillPolygon(xPolygonNoise, yPolygonNoise, xPolygonNoise.length);
g.setColor(Color.BLACK);
g.drawPolygon(xPolygonNoise, yPolygonNoise, xPolygonNoise.length);
// хвост
int[] xPolygonTale = { _startPosX+2, _startPosX+27, _startPosX+2};
int[] yPolygonTale = {_startPosY, _startPosY + 18,_startPosY+18};
g.setColor(entityAirbus.getBodyColor());
g.fillPolygon(xPolygonTale, yPolygonTale, xPolygonTale.length);
g.setColor(Color.BLACK);
g.drawPolygon(xPolygonTale, yPolygonTale, xPolygonTale.length);
// крыло
g.setColor(Color.BLACK);
g.fillOval(_startPosX+43, _startPosY+25, 22, 5);
g.drawOval(_startPosX+43, _startPosY+25, 22, 5);
// двигатель
g.setColor(Color.BLACK);
g.fillOval(_startPosX+1, _startPosY+15, 19, 5);
g.drawOval(_startPosX+1, _startPosY+15, 19, 5);
// шасси
g.setColor(entityAirbus.getBodyColor());
g.fillOval(_startPosX+25,_startPosY+38, 6, 6);
g.fillOval(_startPosX+30,_startPosY+38, 6, 6);
g.fillOval(_startPosX+100,_startPosY+38, 6, 6);
g.setColor(Color.BLACK);
g.drawOval(_startPosX+25,_startPosY+38, 6, 6);
g.drawOval(_startPosX+30,_startPosY+38, 6, 6);
g.drawOval(_startPosX+100,_startPosY+38, 6, 6);
// пассажирский отсек
if (entityAirbus.IsCompartment())
{
g.setColor(entityAirbus.getAdditionalColor());
g.fillOval(_startPosX+57, _startPosY+11, 39, 9);
g.setColor(Color.BLACK);
g.drawOval(_startPosX+57, _startPosY+11, 39, 9);
}
// доп двигатель
if (entityAirbus.IsAdditionalEngine())
{
g.setColor(entityAirbus.getAdditionalColor());
g.fillOval(_startPosX, _startPosY + 25, 11, 5);
g.setColor(Color.BLACK);
g.drawOval(_startPosX, _startPosY + 25, 11, 5);
}
}
}

View File

@ -0,0 +1,93 @@
package Drawnings;
import java.awt.*;
import Entities.*;
public class DrawingPortholes {
private CountPortholes _porthole;
public CountPortholes getCount()
{
return _porthole;
}
public void SetCount (int count) {
switch (count) {
case 10:
_porthole = CountPortholes.Ten;
break;
case 20:
_porthole = CountPortholes.Twenty;
break;
case 30:
_porthole = CountPortholes.Thirty;
break;
}
}
public void Draw (Graphics2D g, int _startPosx, int _startPoxY) {
g.setColor(Color.BLACK);
if (_porthole == CountPortholes.Ten) {
// цикл
for (int i = 0; i < 10; ++i)
{
g.setColor(Color.cyan);
g.fillOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
g.setColor(Color.black);
g.drawOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
}
}
if (_porthole == CountPortholes.Twenty) {
for (int i = 0; i < 10; ++i)
{
g.setColor(Color.cyan);
g.fillOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
g.setColor(Color.black);
g.drawOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
}
for (int i=0; i < 5; ++i)
{
g.setColor(Color.cyan);
g.fillOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
g.setColor(Color.black);
g.drawOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
}
for (int i=0; i < 5; ++i)
{
g.setColor(Color.cyan);
g.fillOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
g.setColor(Color.black);
g.drawOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
}
}
if (_porthole == CountPortholes.Thirty){
for (int i = 0; i < 10; ++i)
{
g.setColor(Color.cyan);
g.fillOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
g.setColor(Color.black);
g.drawOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
}
for (int i=0; i < 5; ++i)
{
g.setColor(Color.cyan);
g.fillOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
g.setColor(Color.black);
g.drawOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
}
for (int i=0; i < 5; ++i)
{
g.setColor(Color.cyan);
g.fillOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
g.setColor(Color.black);
g.drawOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
}
for (int i = 0; i < 10; ++i)
{
g.setColor(Color.cyan);
g.fillOval(_startPosx + 19 + i*8, _startPoxY+31, 3, 3);
g.setColor(Color.black);
g.drawOval(_startPosx + 19 + i*8, _startPoxY+31, 3, 3);
}
}
}
}

View File

@ -0,0 +1,6 @@
package Entities;
public enum CountPortholes {
Ten,
Twenty,
Thirty;
}

View File

@ -0,0 +1,47 @@
package Entities;
import java.awt.*;
public class EntityAirbus {
private int Speed;
private float Weight;
private Color BodyColor;
private Color AdditionalColor;
private boolean IsCompartment;
private boolean IsAdditionalEngine;
public int Step;
public int getSpeed() {
return Speed;
}
public float getWeight() {
return Weight;
}
public Color getBodyColor() {
return BodyColor;
}
public Color getAdditionalColor() {
return AdditionalColor;
}
public boolean IsCompartment() {
return IsCompartment;
}
public boolean IsAdditionalEngine() {
return IsAdditionalEngine;
}
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isAdditionalEngine)
{
Weight = weight;
Speed = speed;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
IsCompartment = isCompartment;
IsAdditionalEngine = isAdditionalEngine;
Step = Speed * 100 / (int) Weight;
}
}

151
src/FormAirbus.java Normal file
View File

@ -0,0 +1,151 @@
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Random;
import Drawnings.*;
import MovementStrategy.*;
public class FormAirbus extends JFrame {
private DrawingAirbus _drawningAirbus;
private Canvas canvas = new Canvas();
JLabel labelCount = new JLabel("Введите число иллюминаторов:");
private JTextField fieldCount = new JTextField();
private JButton buttonCreate;
private JButton buttonUp;
private JButton buttonDown;
private JButton buttonRight;
private JButton buttonLeft;
public FormAirbus() {
super("Создание самолёта");
InitializeComponent();
setVisible(true);
}
private void InitializeComponent()
{
buttonCreate = new JButton("Создать самолёт");
buttonUp = new JButton();
buttonUp.setName("up");
buttonUp.setIcon(new ImageIcon("images\\KeyUp.png"));
buttonUp.setSize(48, 44);
buttonRight = new JButton();
buttonRight.setName("right");
buttonRight.setIcon(new ImageIcon("images\\KeyRight.png"));
buttonRight.setSize(48, 44);
buttonLeft = new JButton();
buttonLeft.setName("left");
buttonLeft.setIcon(new ImageIcon("images\\KeyLeft.png"));
buttonLeft.setSize(48, 44);
buttonDown = new JButton();
buttonDown.setName("down");
buttonDown.setIcon(new ImageIcon("images\\KeyDown.png"));
buttonDown.setSize(48, 44);
setSize(800,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
buttonCreate.setBounds(12, 355, 170, 44);
buttonUp.setBounds(679, 313, 48, 44);
buttonRight.setBounds( 728, 358, 48, 44);
buttonLeft.setBounds(630, 358, 48, 44);
buttonDown.setBounds( 679, 358, 48, 44);
labelCount.setBounds(12, 405, 240, 20);
fieldCount.setBounds(210, 407, 48, 20);
canvas.setBounds(0,0,800, 460);
add(buttonCreate);
add(buttonUp);
add(buttonRight);
add(buttonDown);
add(buttonLeft);
add(labelCount);
add(fieldCount);
add(canvas);
buttonCreate.addActionListener(buttonCreateListener);
buttonUp.addActionListener(buttonsMoveListener);
buttonRight.addActionListener(buttonsMoveListener);
buttonDown.addActionListener(buttonsMoveListener);
buttonLeft.addActionListener(buttonsMoveListener);
}
ActionListener buttonCreateListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
int countPortholes;
try
{
countPortholes = Integer.parseInt(fieldCount.getText());
}
catch (Exception ex)
{
countPortholes = 0;
}
if (countPortholes != 10 && countPortholes != 20 && countPortholes != 30)
{
JOptionPane.showMessageDialog(null, "Число должно быть равно 10, 20 или 30.\nКол-во иллюминаторов приравнено к 10");
countPortholes = 10;
}
Random rand = new Random();
_drawningAirbus = new DrawingAirbus();
_drawningAirbus.Init(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
new Color(rand.nextInt(256),rand.nextInt(256),rand.nextInt(256)),
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
rand.nextBoolean(), rand.nextBoolean(),
countPortholes,
canvas.getWidth(), canvas.getHeight());
_drawningAirbus.SetPosition(rand.nextInt(100) + 10, rand.nextInt(100) + 10);
canvas.repaint();
}
};
ActionListener buttonsMoveListener = new ActionListener() {
// реакция на нажатие
public void actionPerformed(ActionEvent e) {
if (_drawningAirbus == null)
{
return;
}
String command = ((JButton)(e.getSource())).getName();
switch (command) {
case "up":
_drawningAirbus.MoveTransport(Direction.Up);
break;
case "down":
_drawningAirbus.MoveTransport(Direction.Down);
break;
case "right":
_drawningAirbus.MoveTransport(Direction.Right);
break;
case "left":
_drawningAirbus.MoveTransport(Direction.Left);
break;
}
canvas.repaint();
}
};
class Canvas extends JComponent{
public Canvas(){
}
public void paintComponent (Graphics g){
if (_drawningAirbus == null){
return;
}
super.paintComponents (g) ;
Graphics2D g2d = (Graphics2D)g;
_drawningAirbus.DrawTransport(g2d);
super.repaint();
}
}
}

5
src/Main.java Normal file
View File

@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
new FormAirbus();
}
}

View File

@ -0,0 +1,7 @@
package MovementStrategy;
public enum Direction {
Up,
Down,
Left,
Right;
}