Compare commits

...

5 Commits

9 changed files with 0 additions and 365 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 281 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 B

View File

@ -1,13 +0,0 @@
public enum DirectionType
{
Up(1),
Down(2),
Left(3),
Right(4);
private final int DirectionTypeCode;
private DirectionType(int DirectionTypeCode){
this.DirectionTypeCode = DirectionTypeCode;
}
}

View File

@ -1,172 +0,0 @@
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
public class DrawingSPAU {
private EntitySPAU EntitySPAU;
private int pictureWidth;
private int pictureHeight;
private int startPosX;
private int startPosY;
private final int carWidth = 135;
private final int carHeight = 75;
public void setEntitySPAU(EntitySPAU entitySPAU) {
this.EntitySPAU = entitySPAU;
}
public boolean Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean bodyKit, boolean wing, boolean sportLine, int width, int height)
{
this.pictureWidth = width;
this.pictureHeight = height;
if (this.carHeight >= height)
{
return false;
}
if (this.carWidth >= width)
{
return false;
}
EntitySPAU = new EntitySPAU();
EntitySPAU.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
return true;
}
public void SetPosition(int x, int y)
{
if (x < 0 || x > this.pictureWidth - this.carWidth)
{
x = 0;
}
if (y < 0 || y > this.pictureHeight - this.carHeight)
{
y = 0;
}
this.startPosX = x;
this.startPosY = y;
}
public void MoveTransport(DirectionType direction)
{
if (EntitySPAU == null)
{
return;
}
switch (direction)
{
//влево
case Left:
if (this.startPosX - EntitySPAU.Step > 0)
{
this.startPosX -= (int)EntitySPAU.Step;
}
break;
//вверх
case Up:
if (this.startPosY - EntitySPAU.Step > 0)
{
this.startPosY -= (int)EntitySPAU.Step;
}
break;
// вправо
case Right:
if (this.startPosX + EntitySPAU.Step < this.pictureWidth - this.carWidth)
{
this.startPosX += (int)EntitySPAU.Step;
}
break;
//вниз
case Down:
if (this.startPosY + EntitySPAU.Step < this.pictureHeight - this.carHeight)
{
this.startPosY += (int)EntitySPAU.Step;
}
break;
}
}
public void DrawTransport(Graphics g) {
if (EntitySPAU == null) {
return;
}
Graphics2D g2d = (Graphics2D) g;
BasicStroke penBlack = new BasicStroke(1);
Color additionalColor = EntitySPAU.AdditionalColor;
Color bodyColor = EntitySPAU.BodyColor;
boolean hasBodyKit = EntitySPAU.BodyKit;
Path2D.Double path = new Path2D.Double();
// Обвесы
if (hasBodyKit) {
path.moveTo(startPosX + 15, startPosY + 20);
path.lineTo(startPosX + 35, startPosY + 20);
path.lineTo(startPosX + 35, startPosY + 60);
path.lineTo(startPosX + 15, startPosY + 60);
path.closePath();
g2d.setPaint(additionalColor);
g2d.fill(path);
g2d.setPaint(Color.BLACK);
g2d.setStroke(penBlack);
g2d.draw(path);
path.reset();
Line2D line = new Line2D.Double(startPosX + 5, startPosY + 20, startPosX + 15, startPosY + 25);
g2d.draw(line);
}
// Гусеницы
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
g2d.setPaint(Color.BLACK);
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 113, 20);
g2d.draw(ellipse6);
// пушка
path.moveTo(startPosX + 35, startPosY + 40);
path.lineTo(startPosX + 40, startPosY + 45);
path.lineTo(startPosX + 135, startPosY + 5);
path.lineTo(startPosX + 130, startPosY + 0);
path.closePath();
g2d.setPaint(bodyColor);
g2d.fill(path);
g2d.draw(path);
path.reset();
// корпус
path.moveTo(startPosX, startPosY + 60);
path.lineTo(startPosX + 10, startPosY + 30);
path.lineTo(startPosX + 130, startPosY + 30);
path.lineTo(startPosX + 135, startPosY + 60);
path.closePath();
g2d.setPaint(bodyColor);
g2d.fill(path);
g2d.draw(path);
path.reset();
// башня
path.moveTo(startPosX + 40, startPosY + 30);
path.lineTo(startPosX + 45, startPosY + 15);
path.lineTo(startPosX + 70, startPosY + 15);
path.lineTo(startPosX + 75, startPosY + 30);
path.closePath();
g2d.setPaint(bodyColor);
g2d.fill(path);
g2d.draw(path);
}
}

View File

@ -1,24 +0,0 @@
import java.awt.Color;
public class EntitySPAU {
public int Speed;
public double Weight;
public Color BodyColor;
public Color AdditionalColor;
public boolean BodyKit;
public boolean Wing;
public boolean SportLine;
public double Step = (double)Speed * 100 / Weight;
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean bodyKit, boolean wing, boolean sportLine) {
Speed = speed;
Weight = weight;
Step = (double)Speed * 100 / Weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Wing = wing;
SportLine = sportLine;
}
}

145
Form.java
View File

@ -1,145 +0,0 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.Random;
public class Form extends JFrame {
private JPanel mainPanel;
private JButton buttonCreate;
private JButton buttonUp;
private JButton buttonDown;
private JButton buttonLeft;
private JButton buttonRight;
private JLabel pictureBoxSPAU;
private DrawingSPAU drawingSPAU;
public Form() {
initComponents();
}
private void Draw() {
if (drawingSPAU == null) {
return;
}
BufferedImage bmp = new BufferedImage(pictureBoxSPAU.getWidth(),
pictureBoxSPAU.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D gr = bmp.createGraphics();
drawingSPAU.DrawTransport(gr);
ImageIcon imageIcon = new ImageIcon(bmp);
pictureBoxSPAU.setIcon(imageIcon);
}
private void initComponents() {
mainPanel = new JPanel();
buttonCreate = new JButton("Создать");
buttonUp = new JButton(new ImageIcon("resources/upper_arrow.png"));
buttonDown = new JButton(new ImageIcon("resources/down_arrow.png"));
buttonLeft = new JButton(new ImageIcon("resources/left_arrow.png"));
buttonRight = new JButton(new ImageIcon("resources/right_arrow.png"));
pictureBoxSPAU = new JLabel();
setLayout(new BorderLayout());
add(mainPanel, BorderLayout.CENTER);
mainPanel.setLayout(null);
pictureBoxSPAU.setBounds(0, 0, 882, 453);
mainPanel.add(pictureBoxSPAU);
buttonCreate.setBounds(22, 410, 82, 29);
mainPanel.add(buttonCreate);
buttonCreate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonCreateActionPerformed(e);
}
});
buttonUp.setBounds(804, 336, 30, 30);
mainPanel.add(buttonUp);
ImageIcon iconUp = new ImageIcon("Arrows/upper-arrow.png");
buttonUp.setIcon(iconUp);
buttonUp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonMoveActionPerformed(buttonUp, e);
}
});
buttonDown.setBounds(804, 409, 30, 30);
mainPanel.add(buttonDown);
ImageIcon iconDown = new ImageIcon("Arrows/down-arrow.png");
buttonDown.setIcon(iconDown);
buttonDown.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonMoveActionPerformed(buttonDown, e);
}
});
buttonLeft.setBounds(768, 372, 30, 30);
mainPanel.add(buttonLeft);
ImageIcon iconLeft = new ImageIcon("Arrows/left-arrow.png");
buttonLeft.setIcon(iconLeft);
buttonLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonMoveActionPerformed(buttonLeft, e);
}
});
buttonRight.setBounds(840, 372, 30, 30);
mainPanel.add(buttonRight);
ImageIcon iconRight = new ImageIcon("Arrows/right-arrow.png");
buttonRight.setIcon(iconRight);
buttonRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
buttonMoveActionPerformed(buttonRight, e);
}
});
buttonUp.setName("buttonUp");
buttonDown.setName("buttonDown");
buttonLeft.setName("buttonLeft");
buttonRight.setName("buttonRight");
setPreferredSize(new Dimension(882, 453));
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
}
protected void buttonCreateActionPerformed(ActionEvent e) {
Random random = new Random();
drawingSPAU = new DrawingSPAU();
drawingSPAU.Init(random.nextInt(200) + 100,
random.nextInt(2000) + 1000,
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
random.nextBoolean(),
random.nextBoolean(),
random.nextBoolean(),
pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
drawingSPAU.SetPosition(random.nextInt(90) + 10,
random.nextInt(90) + 10);
Draw();
}
protected void buttonMoveActionPerformed(Object sender, ActionEvent e) {
if (drawingSPAU == null) {
return;
}
String name = (sender instanceof JButton) ? ((JButton) sender).getName() : "";
switch (name) {
case "buttonUp":
drawingSPAU.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
drawingSPAU.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
drawingSPAU.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
drawingSPAU.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
}

View File

@ -1,11 +0,0 @@
import javax.swing.*;
public class SelfPropelledArtilleryUnit {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
Form form = new Form();
form.setSize(900, 500);
form.setVisible(true);
});
}
}