Продолжение работы
This commit is contained in:
parent
0338792f12
commit
ce4309fe95
@ -13,15 +13,17 @@ public class DrawningMonorail extends JPanel {
|
|||||||
private int pictureHeight;
|
private int pictureHeight;
|
||||||
private int _startPosX;
|
private int _startPosX;
|
||||||
private int _startPos ;
|
private int _startPos ;
|
||||||
|
private int rollVar;
|
||||||
public int relWidth = 150;
|
public int relWidth = 150;
|
||||||
private int relHeight = 46;
|
private int relHeight = 46;
|
||||||
Random rd = new Random();
|
Random rd = new Random();
|
||||||
public DrawingWheels _drawingWheels;
|
public DrawingWheels _drawingWheels;
|
||||||
public DrawningMonorail(int wheelCount ,int speed, double weight, Color bodyColor, int width, int height){
|
public DrawningMonorail(int wheelCount ,int rollVar,int speed, double weight, Color bodyColor, int width, int height){
|
||||||
if (relWidth >= width || relHeight >= height)
|
if (relWidth >= width || relHeight >= height)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.rollVar = rollVar;
|
||||||
pictureWidth = width;
|
pictureWidth = width;
|
||||||
pictureHeight = height;
|
pictureHeight = height;
|
||||||
entity = new EntityMonorail(wheelCount, speed, weight, bodyColor);
|
entity = new EntityMonorail(wheelCount, speed, weight, bodyColor);
|
||||||
@ -35,12 +37,13 @@ public class DrawningMonorail extends JPanel {
|
|||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrawningMonorail(int wheelCount, int speed, double weight, Color bodyColor, int width,
|
protected DrawningMonorail(int wheelCount, int rollVar, int speed, double weight, Color bodyColor, int width,
|
||||||
int height, int carWidth, int carHeight){
|
int height, int carWidth, int carHeight){
|
||||||
if (relWidth >= width || relHeight >= height)
|
if (relWidth >= width || relHeight >= height)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.rollVar = rollVar;
|
||||||
pictureWidth = width;
|
pictureWidth = width;
|
||||||
pictureHeight = height;
|
pictureHeight = height;
|
||||||
relWidth = carWidth;
|
relWidth = carWidth;
|
||||||
|
@ -2,12 +2,10 @@ package DrawningObjects;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import Entities.*;
|
import Entities.*;
|
||||||
|
|
||||||
import Entities.EntitySecondMonorail;
|
|
||||||
|
|
||||||
public class DrawningSecondMonorail extends DrawningMonorail{
|
public class DrawningSecondMonorail extends DrawningMonorail{
|
||||||
public DrawningSecondMonorail(int wheelCount, int speed, double weight, Color bodyColor, Color
|
public DrawningSecondMonorail(int wheelCount, int rollVar, int speed, double weight, Color bodyColor, Color
|
||||||
additionalColor, boolean monorails, boolean secondCabin, int width, int height){
|
additionalColor, boolean monorails, boolean secondCabin, int width, int height){
|
||||||
super(wheelCount, speed, weight, bodyColor, width, height, 110, 60);
|
super(wheelCount, rollVar, speed, weight, bodyColor, width, height, 110, 60);
|
||||||
if(secondCabin){
|
if(secondCabin){
|
||||||
relWidth = 290;
|
relWidth = 290;
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,29 @@ import javax.swing.*;
|
|||||||
|
|
||||||
import Directions.Direction;
|
import Directions.Direction;
|
||||||
import DrawningObjects.DrawningMonorail;
|
import DrawningObjects.DrawningMonorail;
|
||||||
|
import DrawningObjects.DrawningSecondMonorail;
|
||||||
|
import MovementStrategy.*;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
class Form extends JFrame{
|
class Form extends JFrame{
|
||||||
|
private DrawningMonorail _drawningMonorail;
|
||||||
|
private AbstractStrategy abstractStrategy;
|
||||||
private JLabel pictureBoxMonorail;
|
private JLabel pictureBoxMonorail;
|
||||||
|
private JLabel wheelsLabel;
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
private JButton btUp;
|
private JButton btUp;
|
||||||
private JButton btDown;
|
private JButton btDown;
|
||||||
private JButton btRight;
|
private JButton btRight;
|
||||||
private JButton btLeft;
|
private JButton btLeft;
|
||||||
private JButton btCreate;
|
private JButton btCreateMonorail;
|
||||||
private JLabel wheelsLabel;
|
private JButton btCreateSecondMonorail;
|
||||||
|
private JButton btStep;
|
||||||
|
private JComboBox<String> comboBoxWheel;
|
||||||
|
private JComboBox<String> comboBoxStrategy;
|
||||||
private JTextField wheelsTextField;
|
private JTextField wheelsTextField;
|
||||||
|
|
||||||
Random rd = new Random();
|
Random rd = new Random();
|
||||||
private DrawningMonorail _drawningMonorail;
|
|
||||||
|
|
||||||
public Form(){
|
public Form(){
|
||||||
initComponents();
|
initComponents();
|
||||||
@ -33,13 +40,14 @@ class Form extends JFrame{
|
|||||||
BufferedImage bmp = new BufferedImage(pictureBoxMonorail.getWidth(),
|
BufferedImage bmp = new BufferedImage(pictureBoxMonorail.getWidth(),
|
||||||
pictureBoxMonorail.getHeight(),BufferedImage.TYPE_INT_ARGB);
|
pictureBoxMonorail.getHeight(),BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics2D gr = bmp.createGraphics();
|
Graphics2D gr = bmp.createGraphics();
|
||||||
_drawningMonorail.drawMonorail(gr);
|
_drawningMonorail.DrawTransport(gr);
|
||||||
ImageIcon imageIcon = new ImageIcon(bmp);
|
ImageIcon imageIcon = new ImageIcon(bmp);
|
||||||
pictureBoxMonorail.setIcon(imageIcon);
|
pictureBoxMonorail.setIcon(imageIcon);
|
||||||
}
|
}
|
||||||
private void initComponents(){
|
private void initComponents(){
|
||||||
mainPanel = new JPanel();
|
mainPanel = new JPanel();
|
||||||
btCreate = new JButton("Создать");
|
btCreateMonorail = new JButton("Создать Монорельс");
|
||||||
|
btCreateSecondMonorail = new JButton("Создать два монорельса");
|
||||||
|
|
||||||
btUp = new JButton(new ImageIcon("resources/upper-arrow.png"));
|
btUp = new JButton(new ImageIcon("resources/upper-arrow.png"));
|
||||||
btDown = new JButton(new ImageIcon("resources/down-arrow.png"));
|
btDown = new JButton(new ImageIcon("resources/down-arrow.png"));
|
||||||
@ -63,14 +71,41 @@ class Form extends JFrame{
|
|||||||
wheelsTextField.setBounds(150, 410, 80, 29);
|
wheelsTextField.setBounds(150, 410, 80, 29);
|
||||||
mainPanel.add(wheelsTextField);
|
mainPanel.add(wheelsTextField);
|
||||||
|
|
||||||
btCreate.setBounds(250, 410, 100, 29);
|
btCreateMonorail.setBounds(250, 410, 100, 29);
|
||||||
mainPanel.add(btCreate);
|
mainPanel.add(btCreateMonorail);
|
||||||
btCreate.addActionListener(new ActionListener() {
|
btCreateMonorail.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
buttonCreateActionPerformed(e);
|
buttonCreateActionPerformed(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
btCreateSecondMonorail.setBounds(500, 409, 150, 30);
|
||||||
|
mainPanel.add(btCreateSecondMonorail);
|
||||||
|
btCreateSecondMonorail.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
btCreateSecondMonorail_Click(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btStep = new JButton("Шаг");
|
||||||
|
mainPanel.add(btStep);
|
||||||
|
btStep.setBounds(794, 55, 76, 30);
|
||||||
|
btStep.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
btStep_Click(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
comboBoxWheel = new JComboBox<>();
|
||||||
|
mainPanel.add(comboBoxWheel);
|
||||||
|
comboBoxWheel.setModel(new DefaultComboBoxModel<>(new String[] { "1", "2", "3" }));
|
||||||
|
comboBoxWheel.setBounds(767, 232, 103, 28);
|
||||||
|
|
||||||
|
comboBoxStrategy = new JComboBox<>();
|
||||||
|
mainPanel.add(comboBoxStrategy);
|
||||||
|
comboBoxStrategy.setModel(new DefaultComboBoxModel<>(new String[] { "0", "1" }));
|
||||||
|
comboBoxStrategy.setBounds(767, 12, 103, 28);
|
||||||
|
|
||||||
btUp.setBounds(790, 355, 40, 40);
|
btUp.setBounds(790, 355, 40, 40);
|
||||||
mainPanel.add(btUp);
|
mainPanel.add(btUp);
|
||||||
ImageIcon iconUp = new ImageIcon("resources/upper-arrow.png");
|
ImageIcon iconUp = new ImageIcon("resources/upper-arrow.png");
|
||||||
@ -131,18 +166,71 @@ class Form extends JFrame{
|
|||||||
|
|
||||||
if (wheelCount > 0) {
|
if (wheelCount > 0) {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_drawningMonorail = new DrawningMonorail();
|
_drawningMonorail = new DrawningMonorail(wheelCount, Integer.parseInt((String) comboBoxWheel.getSelectedItem()),
|
||||||
_drawningMonorail.init(wheelCount, random.nextInt(500,800),
|
random.nextInt(200) + 100, (double)random.nextInt(2000) + 1000,
|
||||||
random.nextInt(1000,3000),
|
|
||||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
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(),
|
|
||||||
pictureBoxMonorail.getWidth(), pictureBoxMonorail.getHeight());
|
pictureBoxMonorail.getWidth(), pictureBoxMonorail.getHeight());
|
||||||
_drawningMonorail.setPosition(random.nextInt(90) + 10,
|
_drawningMonorail.setPosition(random.nextInt(90) + 10,
|
||||||
random.nextInt(90) + 10); Draw();
|
random.nextInt(90) + 10);
|
||||||
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected void btCreateSecondMonorail_Click(ActionEvent e) {
|
||||||
|
int wheelCount;
|
||||||
|
try {
|
||||||
|
wheelCount = Integer.parseInt(wheelsTextField.getText());
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
wheelCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wheelCount > 0) {
|
||||||
|
Random random = new Random();
|
||||||
|
_drawningMonorail = new DrawningSecondMonorail(wheelCount, Integer.parseInt((String) comboBoxWheel.getSelectedItem()),
|
||||||
|
random.nextInt(200) + 100,
|
||||||
|
(double) 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)),
|
||||||
|
true, true,
|
||||||
|
pictureBoxMonorail.getWidth(), pictureBoxMonorail.getHeight());
|
||||||
|
_drawningMonorail.setPosition(random.nextInt(90) + 20, random.nextInt(90) + 20);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void btStep_Click (ActionEvent e) {
|
||||||
|
if (_drawningMonorail == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.isEnabled()) {
|
||||||
|
int selectedIndex = comboBoxStrategy.getSelectedIndex();
|
||||||
|
switch (selectedIndex) {
|
||||||
|
case 0:
|
||||||
|
abstractStrategy = new MoveToCenter();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
abstractStrategy = new MoveToBorder();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abstractStrategy = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (abstractStrategy == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
abstractStrategy.setData(new DrawingObjectMonorail(_drawningMonorail), pictureBoxMonorail.getWidth(), pictureBoxMonorail.getHeight());
|
||||||
|
comboBoxStrategy.setEnabled(false);
|
||||||
|
}
|
||||||
|
if (abstractStrategy == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
abstractStrategy.makeStep();
|
||||||
|
Draw();
|
||||||
|
if (abstractStrategy.getStatus() == Status.Finish) {
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void buttonMoveActionPerformed(Object sender, ActionEvent e) {
|
protected void buttonMoveActionPerformed(Object sender, ActionEvent e) {
|
||||||
if (_drawningMonorail == null) {
|
if (_drawningMonorail == null) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user