Переделал базовую на Java
This commit is contained in:
parent
c7b13068a1
commit
0a03f8b6d0
@ -1,32 +1,34 @@
|
|||||||
package MonorailHard;
|
package MonorailHard.DrawningObjects;
|
||||||
|
|
||||||
|
import MonorailHard.DirectionType;
|
||||||
|
import MonorailHard.Entities.EntityMonorail;
|
||||||
|
import MonorailHard.MovementStrategy.IMoveableObject;
|
||||||
|
import com.sun.source.tree.ImportTree;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.text.html.parser.Entity;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DrawningMonorail {
|
public class DrawningMonorail {
|
||||||
|
|
||||||
JPanel MonorailPanel;
|
protected JPanel MonorailPanel;
|
||||||
private EntityMonorail EntityMonorail;
|
protected EntityMonorail EntityMonorail;
|
||||||
private int _pictureWidth;
|
private int _pictureWidth;
|
||||||
private int _pictureHeight;
|
private int _pictureHeight;
|
||||||
private int _startPosX = 0;
|
protected int _startPosX;
|
||||||
private int _startPosY = 0;
|
protected int _startPosY;
|
||||||
private int _monorailWidth = 133;
|
protected int _monorailWidth = 133;
|
||||||
private int _monorailHeight = 50;
|
protected int _monorailHeight = 50;
|
||||||
private DrawningWheels DrawningWheels;
|
public DrawningWheels DrawningWheels;
|
||||||
|
|
||||||
protected int wheelSz;
|
protected int wheelSz;
|
||||||
|
|
||||||
|
|
||||||
public EntityMonorail EntityMonorail(){
|
public EntityMonorail EntityMonorail(){
|
||||||
return EntityMonorail;
|
return EntityMonorail;
|
||||||
}
|
}
|
||||||
public boolean Init(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int wheelNumb,
|
public DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor,
|
||||||
int width, int height, boolean secondCabine, boolean magniteRail, JPanel monorailPanel){
|
int width, int height, JPanel monorailPanel){
|
||||||
if(width <= _monorailWidth || height <= _monorailHeight)
|
if(width <= _monorailWidth || height <= _monorailHeight)
|
||||||
return false;
|
return;
|
||||||
_startPosY=0;
|
_startPosY=0;
|
||||||
_startPosX = 0;
|
_startPosX = 0;
|
||||||
monorailPanel.setSize(width, height);
|
monorailPanel.setSize(width, height);
|
||||||
@ -35,14 +37,31 @@ public class DrawningMonorail {
|
|||||||
wheelSz = _monorailHeight - _monorailHeight * 7 / 10;
|
wheelSz = _monorailHeight - _monorailHeight * 7 / 10;
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
EntityMonorail = new EntityMonorail();
|
EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor);
|
||||||
EntityMonorail.Init(speed, weight, bodyColor, wheelColor, tireColor, wheelNumb, secondCabine, magniteRail);
|
|
||||||
int dif = _monorailWidth / 10;
|
int dif = _monorailWidth / 10;
|
||||||
DrawningWheels = new DrawningWheels();
|
DrawningWheels = new DrawningWheels(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel);
|
||||||
DrawningWheels.Init(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel);
|
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
DrawningWheels.ChangeWheelsNumb(rand.nextInt(1, 6));
|
DrawningWheels.ChangeWheelsNumb(rand.nextInt(1, 6));
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
protected DrawningMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor,
|
||||||
|
int width, int height, int monorailWidth, int monorailHeight, JPanel monorailPanel){
|
||||||
|
if(width <= _monorailWidth || height <= _monorailHeight)
|
||||||
|
return;
|
||||||
|
_startPosY=0;
|
||||||
|
_startPosX = 0;
|
||||||
|
monorailPanel.setSize(width, height);
|
||||||
|
MonorailPanel = monorailPanel;
|
||||||
|
monorailPanel.paint(MonorailPanel.getGraphics());
|
||||||
|
wheelSz = _monorailHeight - _monorailHeight * 7 / 10;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_monorailWidth = monorailWidth;
|
||||||
|
_monorailHeight = monorailHeight;
|
||||||
|
EntityMonorail = new EntityMonorail(speed, weight, bodyColor, wheelColor, tireColor);
|
||||||
|
int dif = _monorailWidth / 10;
|
||||||
|
DrawningWheels = new DrawningWheels(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor,monorailPanel);
|
||||||
|
DrawningWheels.ChangeWheelsNumb(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(int x, int y){
|
public void SetPosition(int x, int y){
|
||||||
@ -50,14 +69,43 @@ public class DrawningMonorail {
|
|||||||
return;
|
return;
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
if(x + _monorailWidth <= _pictureWidth|| y + _monorailHeight <= _pictureHeight){
|
if(x + _monorailWidth >= _pictureWidth|| y + _monorailHeight >= _pictureHeight || x < 0 || y < 0){
|
||||||
_startPosX = 0;
|
_startPosX = 0;
|
||||||
_startPosY = 0;
|
_startPosY = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveTransport(DirectionType direction){
|
public int GetPosX(){return _startPosX;}
|
||||||
|
public int GetPosY(){return _startPosY;}
|
||||||
|
public int GetWidth(){return _monorailWidth;}
|
||||||
|
public int GetHeight(){return _monorailHeight;}
|
||||||
|
public boolean CanMove(DirectionType direction)
|
||||||
|
{
|
||||||
if (EntityMonorail == null)
|
if (EntityMonorail == null)
|
||||||
|
return false;
|
||||||
|
boolean can = false;
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Left:
|
||||||
|
can = _startPosX - EntityMonorail.Step() >= 0;
|
||||||
|
break;
|
||||||
|
case Right:
|
||||||
|
can = _startPosX + EntityMonorail.Step() < _pictureWidth;
|
||||||
|
break;
|
||||||
|
case Down:
|
||||||
|
can = _startPosX + EntityMonorail.Step() < _pictureHeight;
|
||||||
|
break;
|
||||||
|
case Up:
|
||||||
|
can = _startPosX - EntityMonorail.Step() >= 0;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
return can;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void MoveTransport(DirectionType direction){
|
||||||
|
if (!CanMove(direction) || EntityMonorail == null)
|
||||||
return;
|
return;
|
||||||
MonorailPanel.paint(MonorailPanel.getGraphics());
|
MonorailPanel.paint(MonorailPanel.getGraphics());
|
||||||
switch (direction)
|
switch (direction)
|
||||||
@ -65,26 +113,18 @@ public class DrawningMonorail {
|
|||||||
case Left:
|
case Left:
|
||||||
if (_startPosX - EntityMonorail.Step() >= 0)
|
if (_startPosX - EntityMonorail.Step() >= 0)
|
||||||
_startPosX -= (int)EntityMonorail.Step();
|
_startPosX -= (int)EntityMonorail.Step();
|
||||||
else
|
|
||||||
_startPosX = 0;
|
|
||||||
break;
|
break;
|
||||||
case Up:
|
case Up:
|
||||||
if (_startPosY - EntityMonorail.Step() >= 0)
|
if (_startPosY - EntityMonorail.Step() >= 0)
|
||||||
_startPosY -= (int)EntityMonorail.Step();
|
_startPosY -= (int)EntityMonorail.Step();
|
||||||
else
|
|
||||||
_startPosY = 0;
|
|
||||||
break;
|
break;
|
||||||
case Right:
|
case Right:
|
||||||
if (_startPosX + EntityMonorail.Step() + _monorailWidth < _pictureWidth)
|
if (_startPosX + EntityMonorail.Step() + _monorailWidth < _pictureWidth)
|
||||||
_startPosX += (int)EntityMonorail.Step();
|
_startPosX += (int)EntityMonorail.Step();
|
||||||
else
|
|
||||||
_startPosX = _pictureWidth - _monorailWidth;
|
|
||||||
break;
|
break;
|
||||||
case Down:
|
case Down:
|
||||||
if (_startPosY + EntityMonorail.Step() + _monorailHeight < _pictureHeight)
|
if (_startPosY + EntityMonorail.Step() + _monorailHeight < _pictureHeight)
|
||||||
_startPosY += (int)EntityMonorail.Step();
|
_startPosY += (int)EntityMonorail.Step();
|
||||||
else
|
|
||||||
_startPosY = _pictureHeight - _monorailHeight;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DrawningWheels.CurX = _startPosX;
|
DrawningWheels.CurX = _startPosX;
|
||||||
@ -193,43 +233,8 @@ public class DrawningMonorail {
|
|||||||
g2d.fillRect(rightRect.x, rightRect.y, rightRect.width, rightRect.height);
|
g2d.fillRect(rightRect.x, rightRect.y, rightRect.width, rightRect.height);
|
||||||
g2d.setColor(Color.BLUE);
|
g2d.setColor(Color.BLUE);
|
||||||
g2d.drawRect(rightRect.x, rightRect.y, rightRect.width, rightRect.height);
|
g2d.drawRect(rightRect.x, rightRect.y, rightRect.width, rightRect.height);
|
||||||
|
//колеса
|
||||||
//вторая кабина
|
|
||||||
if (EntityMonorail.SecondCabine())
|
|
||||||
{
|
|
||||||
int[] pointsSecondCabineX = { _startPosX + _monorailWidth / 20 * 19,
|
|
||||||
_startPosX + _monorailWidth + dif,
|
|
||||||
_startPosX + _monorailWidth + dif,
|
|
||||||
_startPosX + _monorailWidth / 20 * 19};
|
|
||||||
int[] pointsSecondCabineY = { _startPosY + _monorailHeight / 10,
|
|
||||||
_startPosY + _monorailHeight / 5 * 2,
|
|
||||||
_startPosY + _monorailHeight / 10 * 7,
|
|
||||||
_startPosY + _monorailHeight / 10 * 7};
|
|
||||||
g2d.setColor(EntityMonorail.BodyColor());
|
|
||||||
g2d.fillPolygon(pointsSecondCabineX, pointsSecondCabineY, pointsSecondCabineX.length);
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawPolygon(pointsSecondCabineX, pointsSecondCabineY, pointsSecondCabineX.length);
|
|
||||||
Rectangle Rect = new Rectangle();
|
|
||||||
Rect.x = _startPosX + _monorailWidth / 20 * 19;
|
|
||||||
Rect.y = _startPosY + _monorailHeight / 25 * 4 + _monorailHeight / 50 * 3;
|
|
||||||
Rect.width = _monorailWidth / 120 * 6;
|
|
||||||
Rect.height = _monorailHeight / 50 * 7;
|
|
||||||
g2d.setColor(Color.WHITE);
|
|
||||||
g2d.fillRect(Rect.x, Rect.y, Rect.width, Rect.height);
|
|
||||||
g2d.setColor(Color.BLUE);
|
|
||||||
g2d.drawRect(Rect.x, Rect.y, Rect.width, Rect.height);
|
|
||||||
}
|
|
||||||
DrawningWheels.DrawWheels();
|
DrawningWheels.DrawWheels();
|
||||||
|
_monorailWidth += dif;
|
||||||
_monorailWidth+=dif;
|
|
||||||
|
|
||||||
//магнитная линия
|
|
||||||
if (EntityMonorail.MagniteRail())
|
|
||||||
{
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawLine(_startPosX, _startPosY + _monorailHeight, _startPosX + _monorailWidth, _startPosY + _monorailHeight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
package MonorailHard;
|
package MonorailHard.DrawningObjects;
|
||||||
|
|
||||||
|
import MonorailHard.NumberType;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -14,7 +16,7 @@ public class DrawningWheels {
|
|||||||
return WheelSz;
|
return WheelSz;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean Init(int width, int height, int curX, int curY, Color wheelColor, Color tireColor, JPanel monorailPanel){
|
public DrawningWheels(int width, int height, int curX, int curY, Color wheelColor, Color tireColor, JPanel monorailPanel){
|
||||||
Width = width;
|
Width = width;
|
||||||
Height = height;
|
Height = height;
|
||||||
CurX = curX;
|
CurX = curX;
|
||||||
@ -23,7 +25,6 @@ public class DrawningWheels {
|
|||||||
TireColor = tireColor;
|
TireColor = tireColor;
|
||||||
WheelSz = Height - Height * 7 / 10;
|
WheelSz = Height - Height * 7 / 10;
|
||||||
MonorailPanel = monorailPanel;
|
MonorailPanel = monorailPanel;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeWheelsNumb(int x){
|
public void ChangeWheelsNumb(int x){
|
@ -1,20 +1,15 @@
|
|||||||
package MonorailHard;
|
package MonorailHard.Entities;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class EntityMonorail {
|
public class EntityMonorail {
|
||||||
private int Speed, WheelNumb;
|
private int Speed;
|
||||||
private double Weight, Step;
|
private double Weight, Step;
|
||||||
private Color BodyColor, WheelColor, TireColor;
|
private Color BodyColor, WheelColor, TireColor;
|
||||||
private boolean MagniteRail;
|
|
||||||
private boolean SecondCabine;
|
|
||||||
|
|
||||||
public int Speed(){
|
public int Speed(){
|
||||||
return Speed;
|
return Speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int WheelNumb(){
|
|
||||||
return WheelNumb;
|
|
||||||
}
|
|
||||||
public double Weight(){
|
public double Weight(){
|
||||||
return Weight;
|
return Weight;
|
||||||
}
|
}
|
||||||
@ -30,18 +25,12 @@ public class EntityMonorail {
|
|||||||
public Color TireColor(){
|
public Color TireColor(){
|
||||||
return TireColor;
|
return TireColor;
|
||||||
}
|
}
|
||||||
public boolean SecondCabine(){return SecondCabine;}
|
public EntityMonorail(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor){
|
||||||
public boolean MagniteRail(){return MagniteRail;}
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color wheelColor, Color tireColor, int wheelNumb,
|
|
||||||
boolean secondCabine, boolean magniteRail){
|
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
Step = (double)Speed * 100 / Weight;
|
Step = (double)Speed * 100 / Weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
WheelColor = wheelColor;
|
WheelColor = wheelColor;
|
||||||
TireColor = tireColor;
|
TireColor = tireColor;
|
||||||
WheelNumb = wheelNumb;
|
|
||||||
SecondCabine = secondCabine;
|
|
||||||
MagniteRail = magniteRail;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,8 @@
|
|||||||
package MonorailHard;
|
package MonorailHard;
|
||||||
|
import MonorailHard.DrawningObjects.DrawningLocomotive;
|
||||||
|
import MonorailHard.DrawningObjects.DrawningMonorail;
|
||||||
|
import MonorailHard.MovementStrategy.*;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
@ -10,14 +14,20 @@ import javax.imageio.ImageIO;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
static DrawningMonorail DrawningMonorail;
|
||||||
|
static AbstractStrategy _abstractStrategy;
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
String[] items = {"Довести до центра", "Довести до края"};
|
||||||
|
|
||||||
|
JComboBox comboBoxStrategy = new JComboBox(items);
|
||||||
|
comboBoxStrategy.setBounds(562,12,151,28);
|
||||||
JFrame MonorailFrame = new JFrame();
|
JFrame MonorailFrame = new JFrame();
|
||||||
|
MonorailFrame.setResizable(false);
|
||||||
JPanel MonorailPanel = new JPanel();
|
JPanel MonorailPanel = new JPanel();
|
||||||
MonorailFrame.setLayout(new BorderLayout());
|
MonorailFrame.setLayout(new BorderLayout());
|
||||||
MonorailFrame.setSize(900, 500);
|
MonorailFrame.setSize(743, 576);
|
||||||
MonorailFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
MonorailFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
MonorailFrame.setLayout(new BorderLayout(1,1));
|
MonorailFrame.setLayout(new BorderLayout(1,1));
|
||||||
DrawningMonorail DrawningMonorail = new DrawningMonorail();
|
|
||||||
MonorailPanel.setLayout(null);
|
MonorailPanel.setLayout(null);
|
||||||
BufferedImage RightIcon = ImageIO.read(new File("RightButton.png"));
|
BufferedImage RightIcon = ImageIO.read(new File("RightButton.png"));
|
||||||
BufferedImage LeftIcon = ImageIO.read(new File("LeftButton.png"));
|
BufferedImage LeftIcon = ImageIO.read(new File("LeftButton.png"));
|
||||||
@ -29,36 +39,100 @@ public class Main {
|
|||||||
JButton UpButton = new JButton(new ImageIcon(UpIcon));
|
JButton UpButton = new JButton(new ImageIcon(UpIcon));
|
||||||
JButton DownButton = new JButton(new ImageIcon(DownIcon));
|
JButton DownButton = new JButton(new ImageIcon(DownIcon));
|
||||||
JButton CreateButton = new JButton();
|
JButton CreateButton = new JButton();
|
||||||
|
JButton CreateLocomotiveButton = new JButton();
|
||||||
|
JButton buttonStep = new JButton();
|
||||||
|
|
||||||
|
CreateLocomotiveButton.setBounds(198,477,180, 40);
|
||||||
|
CreateLocomotiveButton.setText("Создать локомотив");
|
||||||
CreateButton.setText("Создать");
|
CreateButton.setText("Создать");
|
||||||
CreateButton.setBounds(12, 401, 90, 40);
|
buttonStep.setBounds(619, 46, 94, 29);
|
||||||
RightButton.setBounds(840,411,30,30);
|
buttonStep.setText("шаг");
|
||||||
LeftButton.setBounds(768,411,30,30);
|
CreateButton.setBounds(12, 477, 180, 40);
|
||||||
UpButton.setBounds(804,375,30,30);
|
RightButton.setBounds(683,487,30,30);
|
||||||
DownButton.setBounds(804,411,30,30);
|
LeftButton.setBounds(611,487,30,30);
|
||||||
|
UpButton.setBounds(647,451,30,30);
|
||||||
|
DownButton.setBounds(647,487,30,30);
|
||||||
MonorailPanel.add(CreateButton);
|
MonorailPanel.add(CreateButton);
|
||||||
|
MonorailPanel.add(CreateLocomotiveButton);
|
||||||
MonorailPanel.add(RightButton);
|
MonorailPanel.add(RightButton);
|
||||||
MonorailPanel.add(LeftButton);
|
MonorailPanel.add(LeftButton);
|
||||||
MonorailPanel.add(UpButton);
|
MonorailPanel.add(UpButton);
|
||||||
MonorailPanel.add(DownButton);
|
MonorailPanel.add(DownButton);
|
||||||
|
MonorailPanel.add(comboBoxStrategy);
|
||||||
|
MonorailPanel.add(buttonStep);
|
||||||
|
comboBoxStrategy.setSelectedIndex(-1);
|
||||||
|
|
||||||
|
|
||||||
MonorailFrame.add(MonorailPanel, BorderLayout.CENTER);
|
MonorailFrame.add(MonorailPanel, BorderLayout.CENTER);
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
CreateButton.addActionListener(new ActionListener() {
|
CreateButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
DrawningMonorail.Init(random.nextInt(100, 300), random.nextDouble(1000, 3000),
|
DrawningMonorail = new DrawningMonorail(random.nextInt(100, 300), random.nextDouble(1000, 3000),
|
||||||
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
random.nextInt(2, 5),
|
MonorailPanel.getWidth(), MonorailPanel.getHeight(), MonorailPanel);
|
||||||
MonorailPanel.getWidth(), MonorailPanel.getHeight(), random.nextBoolean(), random.nextBoolean(), MonorailPanel);
|
|
||||||
DrawningMonorail.DrawMonorail();
|
DrawningMonorail.DrawMonorail();
|
||||||
|
comboBoxStrategy.enable(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CreateLocomotiveButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
DrawningMonorail = new DrawningLocomotive(random.nextInt(100, 300), random.nextDouble(1000, 3000),
|
||||||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
|
random.nextInt(1, 6),
|
||||||
|
MonorailPanel.getWidth(), MonorailPanel.getHeight(), random.nextBoolean(), random.nextBoolean(),
|
||||||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
|
MonorailPanel);
|
||||||
|
DrawningMonorail.DrawMonorail();
|
||||||
|
comboBoxStrategy.enable(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonStep.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(DrawningMonorail == null)
|
||||||
|
return;
|
||||||
|
if(comboBoxStrategy.isEnabled()){
|
||||||
|
if(comboBoxStrategy.getSelectedIndex() == 0)
|
||||||
|
_abstractStrategy = new MoveToCenter();
|
||||||
|
else if(comboBoxStrategy.getSelectedIndex() == 1)
|
||||||
|
_abstractStrategy = new MoveToBorder();
|
||||||
|
else
|
||||||
|
_abstractStrategy = null;
|
||||||
|
if(_abstractStrategy == null)
|
||||||
|
return;
|
||||||
|
_abstractStrategy.SetData(new DrawningObjectMonorail(DrawningMonorail), MonorailPanel.getWidth(),
|
||||||
|
MonorailPanel.getHeight());
|
||||||
|
comboBoxStrategy.enable(false);
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
DrawningMonorail.DrawMonorail();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.enable(true);
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
RightButton.addActionListener(new ActionListener() {
|
RightButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if(DrawningMonorail.EntityMonorail() == null)
|
if(DrawningMonorail.EntityMonorail() == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
DrawningMonorail.MoveTransport(DirectionType.Right);
|
DrawningMonorail.MoveTransport(DirectionType.Right);
|
||||||
DrawningMonorail.DrawMonorail();
|
DrawningMonorail.DrawMonorail();
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ public abstract class AbstractStrategy {
|
|||||||
private int FieldWidth;
|
private int FieldWidth;
|
||||||
protected int FieldWidth(){return FieldWidth;}
|
protected int FieldWidth(){return FieldWidth;}
|
||||||
private int FieldHeight;
|
private int FieldHeight;
|
||||||
protected int FieldHeight(){return FieldWidth;}
|
protected int FieldHeight(){return FieldHeight;}
|
||||||
public Status GetStatus() { return _state; }
|
public Status GetStatus() { return _state; }
|
||||||
public void SetData(IMoveableObject moveableObject, int width, int
|
public void SetData(IMoveableObject moveableObject, int width, int
|
||||||
height)
|
height)
|
||||||
@ -29,7 +29,7 @@ public abstract class AbstractStrategy {
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (IsTargetDestinaion())
|
if (IsTargetDestination())
|
||||||
{
|
{
|
||||||
_state = Status.Finish;
|
_state = Status.Finish;
|
||||||
return;
|
return;
|
||||||
@ -57,8 +57,19 @@ public abstract class AbstractStrategy {
|
|||||||
|
|
||||||
protected abstract void MoveToTarget();
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
protected abstract boolean IsTargetDestinaion();
|
protected abstract boolean IsTargetDestination();
|
||||||
|
|
||||||
private
|
private boolean MoveTo(DirectionType directionType) {
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject.CheckCanMove(directionType))
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user