Create project
This commit is contained in:
parent
675cf9259a
commit
c0ba056579
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
BIN
bin/CountPorthole.class
Normal file
BIN
bin/CountPorthole.class
Normal file
Binary file not shown.
BIN
bin/Direction.class
Normal file
BIN
bin/Direction.class
Normal file
Binary file not shown.
BIN
bin/DrawingAirbus.class
Normal file
BIN
bin/DrawingAirbus.class
Normal file
Binary file not shown.
BIN
bin/DrawingField.class
Normal file
BIN
bin/DrawingField.class
Normal file
Binary file not shown.
BIN
bin/DrawingPorthole.class
Normal file
BIN
bin/DrawingPorthole.class
Normal file
Binary file not shown.
BIN
bin/EntityAirbus.class
Normal file
BIN
bin/EntityAirbus.class
Normal file
Binary file not shown.
BIN
bin/FormAirbus$1.class
Normal file
BIN
bin/FormAirbus$1.class
Normal file
Binary file not shown.
BIN
bin/FormAirbus$ButtonsListener.class
Normal file
BIN
bin/FormAirbus$ButtonsListener.class
Normal file
Binary file not shown.
BIN
bin/FormAirbus.class
Normal file
BIN
bin/FormAirbus.class
Normal file
Binary file not shown.
BIN
bin/Main.class
Normal file
BIN
bin/Main.class
Normal file
Binary file not shown.
BIN
images/KeyDown.jpg
Normal file
BIN
images/KeyDown.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
images/KeyLeft.jpg
Normal file
BIN
images/KeyLeft.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
images/KeyRight.jpg
Normal file
BIN
images/KeyRight.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
images/KeyUp.jpg
Normal file
BIN
images/KeyUp.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
16
src/CountPorthole.java
Normal file
16
src/CountPorthole.java
Normal file
@ -0,0 +1,16 @@
|
||||
public enum CountPorthole {
|
||||
Ten(10),
|
||||
Twenty(20),
|
||||
Thirty(30);
|
||||
|
||||
// значение
|
||||
private final int Count;
|
||||
|
||||
CountPorthole(int count) {
|
||||
Count = count;
|
||||
}
|
||||
|
||||
public int getCountPorthole() {
|
||||
return Count;
|
||||
}
|
||||
}
|
6
src/Direction.java
Normal file
6
src/Direction.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum Direction {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right;
|
||||
}
|
153
src/DrawingAirbus.java
Normal file
153
src/DrawingAirbus.java
Normal file
@ -0,0 +1,153 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingAirbus {
|
||||
|
||||
public EntityAirbus Airbus;
|
||||
public EntityAirbus getAirbus() {
|
||||
return Airbus;
|
||||
}
|
||||
|
||||
public DrawingPorthole _porthole;
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
private Integer _pictureWidth = null;
|
||||
private Integer _pictureHeight = null;
|
||||
private final int _airbusWidth = 150;
|
||||
private final int _airbusHeight = 50;
|
||||
|
||||
// инициализация
|
||||
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isadditionalEngine) {
|
||||
EntityAirbus Airbus = new EntityAirbus();
|
||||
Airbus.Init(speed, weight, bodyColor, additionalColor, isCompartment, isadditionalEngine);
|
||||
Random rand = new Random();
|
||||
_porthole = new DrawingPorthole();
|
||||
_porthole.SetCountPorthole(rand.nextInt(3)*10);
|
||||
}
|
||||
|
||||
public void SetPosition (int x, int y, int width, int height) {
|
||||
if ( x>= 0 && x + _airbusWidth <= width && y>= 0 && _airbusHeight <= height) {
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
else return;
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction){
|
||||
if (_pictureWidth == null || _pictureHeight == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (direction) {
|
||||
case Left:
|
||||
if (_startPosX - Airbus.Step > 0)
|
||||
{
|
||||
_startPosX -= Airbus.Step;
|
||||
}
|
||||
break;
|
||||
case Right:
|
||||
if (_startPosX + Airbus.Step <= _pictureWidth)
|
||||
{
|
||||
_startPosX += Airbus.Step;
|
||||
}
|
||||
break;
|
||||
case Up:
|
||||
if (_startPosY - Airbus.Step > 0)
|
||||
{
|
||||
_startPosY -= Airbus.Step;
|
||||
}
|
||||
break;
|
||||
case Down:
|
||||
if (_startPosY + Airbus.Step <= _pictureHeight)
|
||||
{
|
||||
_startPosY += Airbus.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics2D g) {
|
||||
|
||||
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// пассажирский отсек
|
||||
if (Airbus.IsCompartment())
|
||||
{
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 51, _startPosY + 10, 24, 10);
|
||||
g.setColor(Airbus.getBodyColor());
|
||||
g.fillRect(_startPosX + 51, _startPosY + 10, 24, 10);
|
||||
}
|
||||
|
||||
// доп двигатель
|
||||
if (Airbus.IsAdditionalEngine())
|
||||
{
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX, _startPosY + 20, 11, 5);
|
||||
g.setColor(Airbus.getAdditionalColor());
|
||||
g.fillOval(_startPosX, _startPosY + 20, 11, 5);
|
||||
}
|
||||
|
||||
//// ЛАЙН
|
||||
g.setColor(Color.BLACK);
|
||||
// нос
|
||||
int[] xPolygonNoise = {_startPosX + 74, _startPosX + 88, _startPosX + 74};
|
||||
int[] yPolygonNoise = { _startPosY + 22, _startPosY + 15, _startPosY + 27};
|
||||
g.drawPolygon(xPolygonNoise, yPolygonNoise, xPolygonNoise.length);
|
||||
// хвост
|
||||
int[] xPolygonTale = { _startPosX + 4, _startPosX + 3, _startPosX + 21 };
|
||||
int[] yPolygonTale = { _startPosY + 17, _startPosY, _startPosY + 17 };
|
||||
g.drawPolygon(xPolygonTale, yPolygonTale, xPolygonTale.length);
|
||||
// тело
|
||||
g.drawRect(_startPosX + 2, _startPosY + 14, 72, 14);
|
||||
// шасси
|
||||
g.drawOval(_startPosX + 21, _startPosY + 30, 3, 3);
|
||||
g.drawOval(_startPosX + 25, _startPosY + 30, 3, 3);
|
||||
g.drawOval(_startPosX + 70, _startPosY + 30, 3, 3);
|
||||
// крыло
|
||||
g.drawOval(_startPosX + 24, _startPosY + 20, 31, 4);
|
||||
// двигатель
|
||||
g.drawOval(_startPosX, _startPosY + 14, 14, 5);
|
||||
|
||||
//// ПОКРАСКА
|
||||
// Основной цвет
|
||||
g.setColor(Airbus.getBodyColor());
|
||||
// тело
|
||||
g.fillRect(_startPosX + 2, _startPosY + 14, 72, 14);
|
||||
// нос
|
||||
g.fillPolygon(xPolygonNoise, yPolygonNoise, xPolygonNoise.length);
|
||||
// хвост
|
||||
g.fillPolygon(xPolygonTale, yPolygonTale, xPolygonTale.length);
|
||||
// двигатель
|
||||
g.fillOval(_startPosX, _startPosY + 14, 14, 5);
|
||||
|
||||
// Доп цвет
|
||||
g.setColor(Airbus.getAdditionalColor());
|
||||
// шасси
|
||||
g.fillOval(_startPosX + 21, _startPosY + 30, 3, 3);
|
||||
g.fillOval(_startPosX + 25, _startPosY + 30, 3, 3);
|
||||
g.fillOval(_startPosX + 70, _startPosY + 30, 3, 3);
|
||||
// крыло
|
||||
g.fillOval(_startPosX + 24, _startPosY + 20, 31, 4);
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height) {
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureWidth <= _airbusWidth || _pictureHeight <= _airbusHeight)
|
||||
{
|
||||
_pictureHeight = null;
|
||||
_pictureWidth = null;
|
||||
}
|
||||
if (_startPosX + _airbusWidth > _pictureWidth) {
|
||||
_startPosX = _pictureWidth - _airbusWidth;
|
||||
}
|
||||
if (_startPosY + _airbusHeight > _pictureHeight) {
|
||||
_startPosY = _pictureHeight - _airbusHeight;
|
||||
}
|
||||
}
|
||||
}
|
68
src/DrawingField.java
Normal file
68
src/DrawingField.java
Normal file
@ -0,0 +1,68 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingField extends JPanel {
|
||||
|
||||
private final FormAirbus field;
|
||||
DrawingAirbus _airbus;
|
||||
|
||||
public DrawingField(FormAirbus field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 =(Graphics2D)g;
|
||||
if (_airbus != null)
|
||||
_airbus.DrawTransport(g2);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
public void UpButtonAction() {
|
||||
if (_airbus != null)
|
||||
_airbus.MoveTransport(Direction.Up);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
public void DownButtonAction() {
|
||||
if (_airbus != null)
|
||||
_airbus.MoveTransport(Direction.Down);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
public void RightButtonAction() {
|
||||
if (_airbus != null)
|
||||
_airbus.MoveTransport(Direction.Right);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
public void LeftButtonAction() {
|
||||
if (_airbus != null)
|
||||
_airbus.MoveTransport(Direction.Left);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
public void CreateButtonAction() {
|
||||
Random rand = new Random();
|
||||
_airbus = new DrawingAirbus();
|
||||
_airbus.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)),
|
||||
false, false);
|
||||
|
||||
_airbus.SetPosition(rand.nextInt(100) + 10, rand.nextInt(100) + 10, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
public void ResizeField(){
|
||||
if (_airbus != null)
|
||||
_airbus.ChangeBorders(getWidth(),getHeight());
|
||||
else return;
|
||||
}
|
||||
}
|
36
src/DrawingPorthole.java
Normal file
36
src/DrawingPorthole.java
Normal file
@ -0,0 +1,36 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingPorthole {
|
||||
private CountPorthole _porthole;
|
||||
|
||||
public void SetCountPorthole (int Count) {
|
||||
// проход по значениям
|
||||
for (CountPorthole c: CountPorthole.values()) {
|
||||
if (c.getCountPorthole() == Count) {
|
||||
_porthole = c;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw (Graphics2D g, Color color, int _startPosx, int _startPoxY) {
|
||||
switch (_porthole.getCountPorthole()) {
|
||||
case 10:
|
||||
g.setColor(Color.BLACK);
|
||||
// цикл
|
||||
g.setColor(color);
|
||||
break;
|
||||
case 20:
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.setColor(color);
|
||||
break;
|
||||
case 30:
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.setColor(color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
54
src/EntityAirbus.java
Normal file
54
src/EntityAirbus.java
Normal file
@ -0,0 +1,54 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class EntityAirbus {
|
||||
private int Speed;
|
||||
private float Weight;
|
||||
private Color BodyColor;
|
||||
private Color AdditionalColor;
|
||||
private boolean IsCompartment;
|
||||
private boolean IsAdditionalEngine;
|
||||
|
||||
public float 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) {
|
||||
Random rand = new Random();
|
||||
|
||||
if (weight <= 0)
|
||||
Weight = rand.nextInt(100) + 500;
|
||||
else
|
||||
Weight = weight;
|
||||
|
||||
if (speed <= 0)
|
||||
Speed = rand.nextInt(50) + 10;
|
||||
else
|
||||
Speed = speed;
|
||||
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
IsCompartment = isCompartment;
|
||||
IsAdditionalEngine = isAdditionalEngine;
|
||||
|
||||
Step = Speed * 100 / (int) Weight;
|
||||
}
|
||||
}
|
147
src/FormAirbus.java
Normal file
147
src/FormAirbus.java
Normal file
@ -0,0 +1,147 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
|
||||
public class FormAirbus extends JFrame {
|
||||
|
||||
private int Width;
|
||||
private int Height;
|
||||
|
||||
JPanel BottomAndCreatePanel = new JPanel();
|
||||
JPanel CreatePanel = new JPanel();
|
||||
JPanel DimentionPanel = new JPanel();
|
||||
JPanel UpPanel = new JPanel();
|
||||
JPanel DownPanel = new JPanel();
|
||||
JPanel RightLeftPanel = new JPanel();
|
||||
|
||||
DrawingField field = new DrawingField(this);
|
||||
|
||||
JButton ButtonCreate = new JButton("Create");
|
||||
|
||||
Icon iconUp = new ImageIcon("images\\KeyUp.jpg");
|
||||
JButton ButtonUp=new JButton(iconUp);
|
||||
|
||||
Icon iconDown = new ImageIcon("images\\KeyDown.jpg");
|
||||
JButton ButtonDown=new JButton(iconDown);
|
||||
|
||||
Icon iconRight = new ImageIcon("images\\KeyRight.jpg");
|
||||
JButton ButtonRight=new JButton(iconRight);
|
||||
|
||||
Icon iconLeft = new ImageIcon("images\\KeyLeft.jpg");
|
||||
JButton ButtonLeft=new JButton(iconLeft);
|
||||
|
||||
public FormAirbus() {
|
||||
super("Airbus Hard");
|
||||
|
||||
setSize(800,600);
|
||||
Width = getWidth();
|
||||
Height = getHeight();
|
||||
ShowWindow();
|
||||
RefreshWindow();
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
ActionListener myButtonsListener = new ButtonsListener();
|
||||
|
||||
public class ButtonsListener implements ActionListener {
|
||||
// реакция на события
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
switch (command) {
|
||||
case "Вверх":
|
||||
field.UpButtonAction();
|
||||
break;
|
||||
case "Вниз":
|
||||
field.DownButtonAction();
|
||||
break;
|
||||
case "Вправо":
|
||||
field.RightButtonAction();
|
||||
break;
|
||||
case "Влево":
|
||||
field.LeftButtonAction();
|
||||
break;
|
||||
case "Создать":
|
||||
field.CreateButtonAction();
|
||||
break;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowWindow() {
|
||||
Dimension dimen = new Dimension(30,30);
|
||||
|
||||
ButtonUp.setPreferredSize(dimen);
|
||||
ButtonUp.setActionCommand("Вверх");
|
||||
ButtonUp.addActionListener(myButtonsListener);
|
||||
|
||||
ButtonDown.setPreferredSize(dimen);
|
||||
ButtonDown.setActionCommand("Вниз");
|
||||
ButtonDown.addActionListener(myButtonsListener);
|
||||
|
||||
ButtonRight.setPreferredSize(dimen);
|
||||
ButtonRight.setActionCommand("Вправо");
|
||||
ButtonRight.addActionListener(myButtonsListener);
|
||||
|
||||
ButtonLeft.setPreferredSize(dimen);
|
||||
ButtonLeft.setActionCommand("Влево");
|
||||
ButtonLeft.addActionListener(myButtonsListener);
|
||||
|
||||
ButtonCreate.setPreferredSize(dimen);
|
||||
ButtonCreate.setActionCommand("Создать");
|
||||
ButtonCreate.addActionListener(myButtonsListener);
|
||||
|
||||
RightLeftPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
||||
RightLeftPanel.setBackground(new Color(80, 80, 255, 0));
|
||||
RightLeftPanel.add(ButtonLeft);
|
||||
RightLeftPanel.add(ButtonRight);
|
||||
|
||||
UpPanel.setLayout(new FlowLayout());
|
||||
UpPanel.setBackground(new Color(255, 255, 255, 0));
|
||||
UpPanel.add(ButtonUp);
|
||||
|
||||
DownPanel.setLayout(new FlowLayout());
|
||||
DownPanel.setBackground(new Color(255, 255, 255, 0));
|
||||
DownPanel.add(ButtonDown);
|
||||
|
||||
DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS));
|
||||
DimentionPanel.setBackground(new Color(0,0,0,0));
|
||||
DimentionPanel.add(UpPanel);
|
||||
DimentionPanel.add(RightLeftPanel);
|
||||
DimentionPanel.add(DownPanel);
|
||||
add(DimentionPanel);
|
||||
|
||||
CreatePanel.setLayout(new FlowLayout());
|
||||
CreatePanel.setBackground(new Color(0,0,0,0));
|
||||
CreatePanel.add(ButtonCreate);
|
||||
|
||||
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
||||
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
||||
BottomAndCreatePanel.add(CreatePanel);
|
||||
|
||||
add(BottomAndCreatePanel);
|
||||
add(field);
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
super.componentResized(e);
|
||||
Width = getWidth();
|
||||
Height = getHeight();
|
||||
|
||||
field.ResizeField();
|
||||
repaint();
|
||||
RefreshWindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void RefreshWindow() {
|
||||
field.setBounds(0,0,Width,Height);
|
||||
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
||||
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
||||
}
|
||||
}
|
5
src/Main.java
Normal file
5
src/Main.java
Normal file
@ -0,0 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new FormAirbus();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user