Lab3 Java HARD Петрушин Егор ПИбд-22 #3

Closed
Egor_Petrushin wants to merge 5 commits from Lab3 into Lab2
7 changed files with 301 additions and 5 deletions
Showing only changes of commit 4892fb36de - Show all commits

View File

@ -31,6 +31,80 @@ public class DrawningClamps implements IDrawable {
setNum(numRollers);
}
public DrawningClamps(){}
@Override
public void Draw(Graphics2D g2d, int startPosX, int startPosY, Color color){
this.color = color;
this.g2d = g2d;
this.startPosX = startPosX;
this.startPosY = startPosY;
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
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);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
g2d.draw(ellipse7);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
break;
case Mid:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
break;
case Max:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
g2d.fill(ellipse6);
break;
}
Ellipse2D ellipse11 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 10, 10);
Ellipse2D ellipse12 = new Ellipse2D.Double(startPosX + 35, startPosY + 55, 10, 10);
Ellipse2D ellipse13 = new Ellipse2D.Double(startPosX + 60, startPosY + 55, 10, 10);
Ellipse2D ellipse14 = new Ellipse2D.Double(startPosX + 85, startPosY + 55, 10, 10);
Ellipse2D ellipse15 = new Ellipse2D.Double(startPosX + 110, startPosY + 55, 10, 10);
Ellipse2D ellipse16 = new Ellipse2D.Double(startPosX + 127, startPosY + 60, 5, 5);
g2d.setPaint(color);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
break;
case Mid:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
break;
case Max:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
g2d.fill(ellipse16);
break;
}
}
@Override
public void Draw(){
g2d.setPaint(Color.BLACK);

View File

@ -31,6 +31,80 @@ public class DrawningNails implements IDrawable {
setNum(numRollers);
}
public DrawningNails(){}
@Override
public void Draw(Graphics2D g2d, int startPosX, int startPosY, Color color){
this.color = color;
this.g2d = g2d;
this.startPosX = startPosX;
this.startPosY = startPosY;
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
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);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
g2d.draw(ellipse7);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
break;
case Mid:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
break;
case Max:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
g2d.fill(ellipse6);
break;
}
Ellipse2D ellipse11 = new Ellipse2D.Double(startPosX + 15, startPosY + 62, 2, 2);
Ellipse2D ellipse12 = new Ellipse2D.Double(startPosX + 40, startPosY + 62, 2, 2);
Ellipse2D ellipse13 = new Ellipse2D.Double(startPosX + 65, startPosY + 62, 2, 2);
Ellipse2D ellipse14 = new Ellipse2D.Double(startPosX + 90, startPosY + 62, 2, 2);
Ellipse2D ellipse15 = new Ellipse2D.Double(startPosX + 115, startPosY + 62, 2, 2);
Ellipse2D ellipse16 = new Ellipse2D.Double(startPosX + 130, startPosY + 65, 1, 1);
g2d.setPaint(color);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
break;
case Mid:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
break;
case Max:
g2d.fill(ellipse11);
g2d.fill(ellipse12);
g2d.fill(ellipse13);
g2d.fill(ellipse14);
g2d.fill(ellipse15);
g2d.fill(ellipse16);
break;
}
}
@Override
public void Draw(){

View File

@ -30,11 +30,52 @@ public class DrawningRollers implements IDrawable{
setNum(numRollers);
}
public DrawningRollers(){}
@Override
public void Draw(Graphics2D g2d, int startPosX, int startPosY, Color color){
this.color = color;
this.g2d = g2d;
this.startPosX = startPosX;
this.startPosY = startPosY;
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
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);
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
g2d.draw(ellipse7);
switch (_numbeRollers) {
case Min:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
break;
case Mid:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
break;
case Max:
g2d.fill(ellipse1);
g2d.fill(ellipse2);
g2d.fill(ellipse3);
g2d.fill(ellipse4);
g2d.fill(ellipse5);
g2d.fill(ellipse6);
break;
}
}
@Override
public void Draw(){
g2d.setPaint(Color.BLACK);
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
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);

View File

@ -63,7 +63,7 @@ public class DrawningSPAU {
}
EntitySPAU = new EntitySPAU(speed, weight, bodyColor);
}
public DrawningSPAU(EntitySPAU sPAU,IDrawable roll, int width, int height)
public DrawningSPAU(EntitySPAU sPAU, IDrawable roll, int width, int height)
{ if (this.carHeight >= height)
{
return;
@ -132,7 +132,8 @@ public class DrawningSPAU {
Path2D.Double path = new Path2D.Double();
//гусеницы
Rollers = new DrawningRollers(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
if (Rollers == null){
Rollers = new DrawningRollers(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
switch (rollVar) {
case 2:
Rollers = new DrawningClamps(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
@ -142,9 +143,12 @@ public class DrawningSPAU {
break;
default:
break;
}
Rollers.Draw();
}
else{
Rollers.Draw(g2d, startPosX, startPosY, bodyColor);
}
Rollers.Draw();
// пушка
path.moveTo(startPosX + 35, startPosY + 40);

View File

@ -1,6 +1,10 @@
package SelfPropelledArtilleryUnit.DrawningObjects;
import java.awt.Color;
import java.awt.Graphics2D;
public interface IDrawable {
public void setNum(int num);
public void Draw();
public void Draw(Graphics2D g2d, int startPosX, int startPosY, Color color);
}

View File

@ -0,0 +1,98 @@
package SelfPropelledArtilleryUnit;
import javax.swing.*;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningClamps;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningNails;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningRollers;
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
import SelfPropelledArtilleryUnit.DrawningObjects.IDrawable;
import SelfPropelledArtilleryUnit.Entities.EntitySPAU;
import SelfPropelledArtilleryUnit.Generics.RandomParts;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
public class FormHard {
private JFrame frameMain;
private JPanel panelMain;
private JButton buttonCreate;
private RandomParts<EntitySPAU, IDrawable> generator;
public FormHard() {
InitializeComponent();
Random rand = new Random();
// макс. кол-во вариаций форм дверей/видов автобуса
int maxCnt = rand.nextInt(5, 11);
generator = new RandomParts<>(maxCnt, maxCnt, panelMain.getWidth(), panelMain.getHeight());
// добавление в массивы с дверьми/сущностями рандомные варианты
for (int i = 0; i < maxCnt; i++) {
generator.Add(createRandomEntitySPAU());
generator.Add(createRandomDop());
}
}
private void InitializeComponent() {
//Само окно
frameMain = new JFrame("Усложнённая лаб 3");
frameMain.setSize(900, 500);
frameMain.setLayout(new BorderLayout());
frameMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Панель, на которой отрисовывается
panelMain = new JPanel();
panelMain.setLayout(null);
buttonCreate = new JButton("Создать");
buttonCreate.setBounds(10,400,150,30);
buttonCreate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
createRandomDrawingBus(e);
}
});
frameMain.add(panelMain, BorderLayout.CENTER);
panelMain.add(buttonCreate);
frameMain.setVisible(true);
}
private void Draw(DrawningSPAU drawingSPAU){
if (drawingSPAU == null) {
return;
}
Graphics g = panelMain.getGraphics();
// Очистка перед перерисовкой
panelMain.paint(g);
drawingSPAU.DrawTransport(g);
}
private void createRandomDrawingBus(ActionEvent e) {
DrawningSPAU drawingBus = generator.CreateObject();
drawingBus.SetPosition(50, 50);
Draw(drawingBus);
}
private EntitySPAU createRandomEntitySPAU() {
Random rand = new Random();
Color color = new Color(rand.nextInt(0, 256), rand.nextInt(0, 256), rand.nextInt(0, 256));
EntitySPAU entityBus = new EntitySPAU(rand.nextInt(100, 300), rand.nextDouble(1000, 3000), color);
return entityBus;
}
private IDrawable createRandomDop() {
IDrawable dops;
Random rand = new Random();
int shape = rand.nextInt(1, 3);
if (shape == 1) {
dops = new DrawningClamps();
}
else if (shape == 2) {
dops = new DrawningNails();
}
else {
dops = new DrawningRollers();
}
dops.setNum(rand.nextInt(4, 6));
return dops;
}
}

View File

@ -5,6 +5,7 @@ public class SelfPropelledArtilleryUnit {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
FormSPAUCollection form = new FormSPAUCollection();
FormHard formHard = new FormHard();
form.setSize(900, 500);
form.setVisible(true);
});