Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
4e293da393 |
12
AirplaneWithRadar_Hard.iml
Normal file
12
AirplaneWithRadar_Hard.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?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" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
70
src/AirplaneWithRadar/AirplaneWithRadarEntity.java
Normal file
70
src/AirplaneWithRadar/AirplaneWithRadarEntity.java
Normal file
@ -0,0 +1,70 @@
|
||||
package AirplaneWithRadar;
|
||||
|
||||
import java.awt.Color;
|
||||
public class AirplaneWithRadarEntity
|
||||
{
|
||||
public int Speed;
|
||||
public double Weight;
|
||||
public Color BodyColor;
|
||||
public Color AdditColor;
|
||||
public boolean RadarOnBoard;
|
||||
public boolean AdditFuelPod;
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
private void setSpeed(int speed) {
|
||||
Speed = speed;
|
||||
}
|
||||
|
||||
public double getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
|
||||
private void setWeight(double weight) {
|
||||
Weight = weight;
|
||||
}
|
||||
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
|
||||
private void setBodyColor(Color bodyColor) {
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
public Color getAdditColor() {
|
||||
return AdditColor;
|
||||
}
|
||||
|
||||
private void setAdditColor(Color additColor) {
|
||||
AdditColor = additColor;
|
||||
}
|
||||
|
||||
public boolean isRadarOnBoard() {
|
||||
return RadarOnBoard;
|
||||
}
|
||||
|
||||
private void setRadarOnBoard(boolean radarOnBoard) {
|
||||
RadarOnBoard = radarOnBoard;
|
||||
}
|
||||
|
||||
public boolean isAdditFuelPod() {
|
||||
return AdditFuelPod;
|
||||
}
|
||||
|
||||
private void setAdditFuelPod(boolean additFuelPod) {
|
||||
AdditFuelPod = additFuelPod;
|
||||
}
|
||||
|
||||
public double Step;
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additColor, boolean radarOnBoard, boolean additFuelPod)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditColor = additColor;
|
||||
RadarOnBoard = radarOnBoard;
|
||||
AdditFuelPod = additFuelPod;
|
||||
Step = (double)Speed * 100 / Weight;
|
||||
}
|
||||
}
|
162
src/AirplaneWithRadar/AirplaneWithRadarForm.java
Normal file
162
src/AirplaneWithRadar/AirplaneWithRadarForm.java
Normal file
@ -0,0 +1,162 @@
|
||||
package AirplaneWithRadar;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
public class AirplaneWithRadarForm extends JFrame {
|
||||
private PaintAirplaneWithRadar PaintPlanes;
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (PaintPlanes == null)
|
||||
return;
|
||||
|
||||
BufferedImage bmp = new BufferedImage(
|
||||
AirplanePictureBox.getWidth(),
|
||||
AirplanePictureBox.getHeight(),
|
||||
BufferedImage.TYPE_INT_ARGB
|
||||
);
|
||||
Graphics2D g = bmp.createGraphics();
|
||||
PaintPlanes.DrawTransport(g);
|
||||
|
||||
AirplanePictureBox.setIcon(new ImageIcon(bmp));
|
||||
}
|
||||
public AirplaneWithRadarForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AirplanePictureBox = new JLabel();
|
||||
CreateButton = new JButton();
|
||||
ButtonRight = new JButton();
|
||||
ButtonDown = new JButton();
|
||||
ButtonLeft = new JButton();
|
||||
ButtonUp = new JButton();
|
||||
AirplanePictureBox.setBounds(0, 0, 884, 461);
|
||||
//
|
||||
// CreateButton
|
||||
//
|
||||
CreateButton.setName("CreateButton");
|
||||
CreateButton.setBounds(12, 419, 80, 30);
|
||||
CreateButton.setText("Создать");
|
||||
CreateButton.setBackground(new Color(225, 225, 225));
|
||||
CreateButton.setFont(new Font("Segoe UI", Font.PLAIN, 11));
|
||||
CreateButton.setFocusable(false);
|
||||
CreateButton.addActionListener(e -> ButtonCreate_Click(e));
|
||||
//
|
||||
// ButtonRight
|
||||
//
|
||||
ButtonRight.setName("ButtonRight");
|
||||
ButtonRight.setBounds(842, 419, 30, 30);
|
||||
ButtonRight.setBackground(new Color(225, 225, 225));
|
||||
ButtonRight.setFont(new Font("Segoe UI", Font.PLAIN, 11));
|
||||
ButtonRight.setFocusable(false);
|
||||
ButtonRight.setIcon(new ImageIcon("src/AirplaneWithRadar/Resources/ArrowRight.png"));
|
||||
ButtonRight.addActionListener(e -> ButtonMove_Click(e));
|
||||
//
|
||||
// ButtonDown
|
||||
//
|
||||
ButtonDown.setName("ButtonDown");
|
||||
ButtonDown.setBounds(806, 419, 30, 30);
|
||||
ButtonDown.setBackground(new Color(225, 225, 225));
|
||||
ButtonDown.setFont(new Font("Segoe UI", Font.PLAIN, 11));
|
||||
ButtonDown.setFocusable(false);
|
||||
ButtonDown.setIcon(new ImageIcon("src/AirplaneWithRadar/Resources/ArrowDown.png"));
|
||||
ButtonDown.addActionListener(e -> ButtonMove_Click(e));
|
||||
//
|
||||
// ButtonLeft
|
||||
//
|
||||
ButtonLeft.setName("ButtonLeft");
|
||||
ButtonLeft.setBounds(770, 419, 30, 30);
|
||||
ButtonLeft.setBackground(new Color(225, 225, 225));
|
||||
ButtonLeft.setFont(new Font("Segoe UI", Font.PLAIN, 11));
|
||||
ButtonLeft.setFocusable(false);
|
||||
ButtonLeft.setIcon(new ImageIcon("src/AirplaneWithRadar/Resources/ArrowLeft.png"));
|
||||
ButtonLeft.addActionListener(e -> ButtonMove_Click(e));
|
||||
//
|
||||
// ButtonUp
|
||||
//
|
||||
ButtonUp.setName("ButtonUp");
|
||||
ButtonUp.setBounds(806, 383, 30, 30);
|
||||
ButtonUp.setBackground(new Color(225, 225, 225));
|
||||
ButtonUp.setFont(new Font("Segoe UI", Font.PLAIN, 11));
|
||||
ButtonUp.setFocusable(false);
|
||||
ButtonUp.setIcon(new ImageIcon("src/AirplaneWithRadar/Resources/ArrowUp.png"));
|
||||
ButtonUp.addActionListener(e -> ButtonMove_Click(e));
|
||||
//
|
||||
// AirplaneWithRadarForm
|
||||
//
|
||||
setTitle("Самолет с радаром");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(900, 500);
|
||||
setLayout(null);
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
add(ButtonUp);
|
||||
add(ButtonLeft);
|
||||
add(ButtonDown);
|
||||
add(ButtonRight);
|
||||
add(CreateButton);
|
||||
add(AirplanePictureBox);
|
||||
}
|
||||
|
||||
private JLabel AirplanePictureBox;
|
||||
private JButton CreateButton;
|
||||
private JButton ButtonRight;
|
||||
private JButton ButtonDown;
|
||||
private JButton ButtonLeft;
|
||||
private JButton ButtonUp;
|
||||
|
||||
private void ButtonMove_Click(ActionEvent e)
|
||||
{
|
||||
if (PaintPlanes == null)
|
||||
return;
|
||||
|
||||
String ButtonName = ((JButton)e.getSource()).getName();
|
||||
|
||||
switch (ButtonName)
|
||||
{
|
||||
case "ButtonUp":
|
||||
PaintPlanes.Move(Movement.Up);
|
||||
break;
|
||||
|
||||
case "ButtonDown":
|
||||
PaintPlanes.Move(Movement.Down);
|
||||
break;
|
||||
|
||||
case "ButtonLeft":
|
||||
PaintPlanes.Move(Movement.Left);
|
||||
break;
|
||||
|
||||
case "ButtonRight":
|
||||
PaintPlanes.Move(Movement.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreate_Click(ActionEvent e)
|
||||
{
|
||||
Random random = new Random();
|
||||
PaintPlanes = new PaintAirplaneWithRadar();
|
||||
|
||||
PaintPlanes.Init(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
true,
|
||||
true,
|
||||
AirplanePictureBox.getWidth(),
|
||||
AirplanePictureBox.getHeight()
|
||||
);
|
||||
PaintPlanes.SetPosition(random.nextInt(20, 100), random.nextInt(20, 100));
|
||||
Draw();
|
||||
}
|
||||
}
|
7
src/AirplaneWithRadar/IlluminatorsCount.java
Normal file
7
src/AirplaneWithRadar/IlluminatorsCount.java
Normal file
@ -0,0 +1,7 @@
|
||||
package AirplaneWithRadar;
|
||||
|
||||
public enum IlluminatorsCount {
|
||||
Ten,
|
||||
Twenty,
|
||||
Thirty
|
||||
}
|
7
src/AirplaneWithRadar/Movement.java
Normal file
7
src/AirplaneWithRadar/Movement.java
Normal file
@ -0,0 +1,7 @@
|
||||
package AirplaneWithRadar;
|
||||
public enum Movement {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
157
src/AirplaneWithRadar/PaintAirplaneWithRadar.java
Normal file
157
src/AirplaneWithRadar/PaintAirplaneWithRadar.java
Normal file
@ -0,0 +1,157 @@
|
||||
package AirplaneWithRadar;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class PaintAirplaneWithRadar {
|
||||
private AirplaneWithRadarEntity airplaneWithRadarEntity;
|
||||
private int pictWidth;
|
||||
private int pictHeight;
|
||||
private int startPosX;
|
||||
private int startPosY;
|
||||
private final int planeWidth = 140;
|
||||
private final int planeHeight = 60;
|
||||
public PaintIlluminators paintIlluminators;
|
||||
|
||||
public boolean Init(int speed, double weight, Color mainColor, Color additColor, boolean radarOnBoard, boolean additFuelPod, int width, int height)
|
||||
{
|
||||
if (planeWidth > width || planeHeight > height) { return false; }
|
||||
|
||||
pictHeight = height;
|
||||
pictWidth = width;
|
||||
airplaneWithRadarEntity = new AirplaneWithRadarEntity();
|
||||
airplaneWithRadarEntity.Init(speed, weight, mainColor, additColor, radarOnBoard, additFuelPod);
|
||||
|
||||
paintIlluminators = new PaintIlluminators();
|
||||
|
||||
Random rnd = new Random();
|
||||
paintIlluminators.setCount(rnd.nextInt(6, 35));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x + planeWidth < pictWidth && y + planeHeight < pictHeight)
|
||||
{
|
||||
startPosX = x;
|
||||
startPosY = y;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x > pictWidth)
|
||||
{
|
||||
while (x + planeWidth > pictWidth)
|
||||
{
|
||||
x -= 1;
|
||||
}
|
||||
}
|
||||
if (y > pictWidth)
|
||||
{
|
||||
while (y + planeHeight > pictHeight)
|
||||
{
|
||||
y -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Move(Movement dir)
|
||||
{
|
||||
if (airplaneWithRadarEntity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (dir)
|
||||
{
|
||||
case Left:
|
||||
if (startPosX - airplaneWithRadarEntity.Step > 0)
|
||||
{
|
||||
startPosX -= (int) airplaneWithRadarEntity.Step;
|
||||
}
|
||||
break;
|
||||
case Up:
|
||||
if (startPosY - airplaneWithRadarEntity.Step > 0)
|
||||
{
|
||||
startPosY -= (int) airplaneWithRadarEntity.Step;
|
||||
}
|
||||
break;
|
||||
case Right:
|
||||
if (startPosX + planeWidth + airplaneWithRadarEntity.Step < pictWidth)
|
||||
{
|
||||
startPosX += (int)airplaneWithRadarEntity.Step;
|
||||
}
|
||||
break;
|
||||
case Down:
|
||||
if (startPosY + planeHeight + airplaneWithRadarEntity.Step < pictHeight)
|
||||
{
|
||||
startPosY += (int)airplaneWithRadarEntity.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (airplaneWithRadarEntity == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//основа
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawLine(startPosX + planeWidth / 44, startPosY + planeHeight / 2, startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight / 2);
|
||||
g.drawLine(startPosX + planeWidth / 44, startPosY + planeHeight - planeHeight / 8, startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight - planeHeight / 8);
|
||||
g.setColor(airplaneWithRadarEntity.getBodyColor());
|
||||
g.fillRect(startPosX + planeWidth / 44, startPosY + planeHeight / 2, planeWidth - 2* planeWidth/11, planeHeight / 2 - planeHeight / 8);
|
||||
g.fillOval(startPosX, startPosY + planeHeight / 2, planeWidth / 24, planeHeight / 2 - planeHeight / 8);
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.drawArc(startPosX, startPosY + planeHeight / 2, planeWidth / 24, planeHeight/2 - planeHeight / 8, 90, 180);
|
||||
|
||||
DrawTriangle(g,
|
||||
startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight / 2, // 1
|
||||
startPosX + planeWidth, startPosY + 5 * planeHeight / 7, // 2
|
||||
startPosX + planeWidth - planeWidth / 6, startPosY + planeHeight - planeHeight / 8); // 3
|
||||
|
||||
DrawTriangle(g,
|
||||
startPosX, startPosY, // 1
|
||||
startPosX + planeWidth/4, startPosY + planeHeight/2, // 2
|
||||
startPosX, startPosY + planeHeight / 2); // 3
|
||||
g.drawLine(startPosX + planeWidth - planeWidth / 6, startPosY + 5 * planeHeight / 7,
|
||||
startPosX + planeWidth, startPosY + 5 * planeHeight / 7);
|
||||
// колеса
|
||||
g.drawLine(startPosX + planeWidth / 4, startPosY + planeHeight - planeHeight / 8,
|
||||
startPosX + planeWidth / 4, startPosY + planeHeight - planeHeight / 11);
|
||||
g.drawLine(startPosX + planeWidth - 2 * planeWidth / 9, startPosY + planeHeight - planeHeight / 8,
|
||||
startPosX + planeWidth - 2 * planeWidth / 9, startPosY + planeHeight - planeHeight / 11);
|
||||
g.drawOval(startPosX + planeWidth / 4 - planeWidth / 23, startPosY + 11 * planeHeight / 12,
|
||||
planeHeight / 12, planeHeight / 12);
|
||||
g.drawOval(startPosX + planeWidth / 4 + planeWidth / 72, startPosY + 11 * planeHeight / 12,
|
||||
planeHeight / 12, planeHeight / 12);
|
||||
|
||||
g.drawOval(startPosX + planeWidth - 5 * planeWidth / 21, startPosY + 11 * planeHeight / 12,
|
||||
planeHeight / 12, planeHeight / 12);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillRoundRect(startPosX + 2*planeWidth / 9, startPosY + planeHeight / 2 + planeHeight / 7, planeWidth/2 ,planeHeight/7, 5, 5);
|
||||
g.fillRoundRect(startPosX, startPosY + planeHeight / 2 - planeHeight/9, planeWidth / 5, planeHeight / 6, 5, 5);
|
||||
|
||||
if (airplaneWithRadarEntity.RadarOnBoard) {
|
||||
g.setColor(airplaneWithRadarEntity.getAdditColor());
|
||||
g.drawLine(startPosX + planeWidth / 3, startPosY + planeHeight / 2, startPosX + planeWidth / 3, startPosY + planeHeight / 3);
|
||||
g.fillArc(startPosX + planeWidth / 4, startPosY + planeHeight / 10, planeWidth / 6, planeHeight / 4, -30, -180);
|
||||
}
|
||||
if (airplaneWithRadarEntity.AdditFuelPod)
|
||||
{
|
||||
g.setColor(airplaneWithRadarEntity.getAdditColor());
|
||||
g.fillRoundRect(startPosX, startPosY + planeHeight - 2*planeHeight / 5, planeWidth / 5, planeHeight / 6, 5, 5);
|
||||
}
|
||||
|
||||
paintIlluminators.drawIlluminators(g, airplaneWithRadarEntity.getAdditColor(), startPosX, startPosY);
|
||||
}
|
||||
|
||||
private void DrawTriangle(Graphics g, int x1, int y1, int x2, int y2, int x3, int y3)
|
||||
{
|
||||
g.drawLine(x1, y1, x2, y2);
|
||||
g.drawLine(x2, y2, x3, y3);
|
||||
g.drawLine(x3, y3, x1, y1);
|
||||
}
|
||||
}
|
45
src/AirplaneWithRadar/PaintIlluminators.java
Normal file
45
src/AirplaneWithRadar/PaintIlluminators.java
Normal file
@ -0,0 +1,45 @@
|
||||
package AirplaneWithRadar;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Color;
|
||||
|
||||
public class PaintIlluminators {
|
||||
private IlluminatorsCount count;
|
||||
public void setCount(int count) {
|
||||
if (count <= 10)
|
||||
this.count = IlluminatorsCount.Ten;
|
||||
else if (count <= 20) {
|
||||
this.count = IlluminatorsCount.Twenty;
|
||||
}
|
||||
else
|
||||
this.count = IlluminatorsCount.Thirty;
|
||||
}
|
||||
public void drawIlluminators(Graphics g, Color color, int startPosX, int startPosY) {
|
||||
g.setColor(color);
|
||||
|
||||
int x = startPosX;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillOval(x + 34, startPosY + 30, 5, 5);
|
||||
x += 7;
|
||||
}
|
||||
|
||||
if (count == IlluminatorsCount.Ten) return;
|
||||
|
||||
x = startPosX;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillOval(x + 34, startPosY + 38, 5, 5);
|
||||
x += 7;
|
||||
}
|
||||
|
||||
if (count == IlluminatorsCount.Twenty) return;
|
||||
|
||||
x = startPosX;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillOval(x + 34, startPosY + 46, 5, 5);
|
||||
x += 7;
|
||||
}
|
||||
}
|
||||
}
|
BIN
src/AirplaneWithRadar/Resources/ArrowDown.png
Normal file
BIN
src/AirplaneWithRadar/Resources/ArrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 557 B |
BIN
src/AirplaneWithRadar/Resources/ArrowLeft.png
Normal file
BIN
src/AirplaneWithRadar/Resources/ArrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 507 B |
BIN
src/AirplaneWithRadar/Resources/ArrowRight.png
Normal file
BIN
src/AirplaneWithRadar/Resources/ArrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 502 B |
BIN
src/AirplaneWithRadar/Resources/ArrowUp.png
Normal file
BIN
src/AirplaneWithRadar/Resources/ArrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 539 B |
7
src/Main.java
Normal file
7
src/Main.java
Normal file
@ -0,0 +1,7 @@
|
||||
import AirplaneWithRadar.AirplaneWithRadarForm;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new AirplaneWithRadarForm();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user