This commit is contained in:
Alenka 2023-12-09 00:17:07 +04:00
parent d90af74620
commit 2577e0d879
16 changed files with 171 additions and 399 deletions

View File

@ -1,30 +1,9 @@
public abstract class AbstractStrategy {
/// <summary>
/// Перемещаемый объект
/// </summary>
private IMoveableObject _moveableObject;
/// <summary>
/// Статус перемещения
/// </summary>
private Status _state = Status.NotInit;
/// <summary>
/// Ширина поля
/// </summary>
protected int FieldWidth;
/// <summary>
/// Высота поля
/// </summary>
protected int FieldHeight;
/// <summary>
/// Статус перемещения
/// </summary>
public Status GetStatus() { return _state; }
/// <summary>
/// Установка данных
/// </summary>
/// <param name="moveableObject">Перемещаемый объект</param>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
public void SetData(IMoveableObject moveableObject, int width, int
height)
{
@ -38,12 +17,8 @@ public abstract class AbstractStrategy {
FieldWidth = width;
FieldHeight = height;
}
/// <summary>
/// Шаг перемещения
/// </summary>
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
@ -55,10 +30,6 @@ public abstract class AbstractStrategy {
}
MoveToTarget();
}
/// <summary>
/// Перемещение влево
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected boolean MoveLeft() { return MoveTo(Direction.Left);};
protected boolean MoveRight(){return MoveTo(Direction.Right);}
protected boolean MoveUp(){return MoveTo(Direction.Up);}
@ -72,20 +43,8 @@ public abstract class AbstractStrategy {
}
return _moveableObject.GetStep();
}
/// <summary>
/// Перемещение к цели
/// </summary>
protected abstract void MoveToTarget();
/// <summary>
/// Достигнута ли цель
/// </summary>
/// <returns></returns>
protected abstract boolean IsTargetDestinaion();
/// <summary>
/// Попытка перемещения в требуемом направлении
/// </summary>
/// <param name="directionType">Направление</param>
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
private boolean MoveTo(Direction directionType)
{
if (_state != Status.InProgress)
@ -100,7 +59,5 @@ public abstract class AbstractStrategy {
else {
return false;
}
}
}

34
DopClassMixed.java Normal file
View File

@ -0,0 +1,34 @@
import java.awt.*;
public class DopClassMixed implements IDop{
public int numOfWheels;
public DopClassMixed(int num){
numOfWheels = num;
}
public void setNumOfWheels(String num){
switch (Integer.valueOf(num)){
case 2:
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
break;
case 3:
numOfWheels = NumberOfWheelsEnum.wheel_3.value;
break;
case 4:
numOfWheels = NumberOfWheelsEnum.wheel_4.value;
break;
default:
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
}
}
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c) {
g.setColor(c);
if (numOfWheels >= 2) {
g.fillRect(_startPosX+55, _startPosY+20, 20, 15);
g.fillRect(_startPosX+55, _startPosY+40, 20, 15);
} if (numOfWheels >= 3) {
g.fillOval(_startPosX+30, _startPosY+20, 20, 15);
} if (numOfWheels >= 4) {
g.fillRect(_startPosX+85, _startPosY+20, 20, 15);
}
}
}

View File

@ -1,7 +1,5 @@
import java.awt.*;
public class DopClassRect implements IDop{
public int numOfWheels;
public DopClassRect(int num){
numOfWheels = num;
@ -20,23 +18,16 @@ public class DopClassRect implements IDop{
default:
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
}
}
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c) {
g.setColor(c);
System.out.println("WHITE");
if (numOfWheels >= 2) {
g.fillRect(_startPosX, _startPosY + 35 + 10, 15, 15);
g.fillRect(_startPosX + 95, _startPosY + 35 + 10, 15, 15);
g.fillRect(_startPosX+55, _startPosY+15, 20, 15);
g.fillRect(_startPosX+55, _startPosY+30, 20, 15);
} if (numOfWheels >= 3) {
g.fillRect(_startPosX, _startPosY + 35 + 10, 15, 15);
g.fillRect(_startPosX + 15, _startPosY + 35 + 10, 15, 15);
g.fillRect(_startPosX+30, _startPosY+15, 20, 15);
} if (numOfWheels >= 4) {
g.fillRect(_startPosX + 95 - 20, _startPosY + 35 + 10, 15, 15);
g.fillRect(_startPosX + 60, _startPosY + 35, 15, 15);
}
}
}

View File

@ -1,39 +0,0 @@
import java.awt.*;
public class DopClassTriangle implements IDop{
public int numOfWheels;
public DopClassTriangle(int num){
numOfWheels = num;
}
public void setNumOfWheels(String num){
switch (Integer.valueOf(num)){
case 2:
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
break;
case 3:
numOfWheels = NumberOfWheelsEnum.wheel_3.value;
break;
case 4:
numOfWheels = NumberOfWheelsEnum.wheel_4.value;
break;
default:
numOfWheels = NumberOfWheelsEnum.wheel_2.value;
}
}
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c) {
g.setColor(c);
if (numOfWheels >= 2) {
g.fillPolygon(new int[]{_startPosX, _startPosX + 15/2, _startPosX + 15}, new int[]{_startPosY + 35 + 10, _startPosY + 35 + 10 + 15/2, _startPosY + 35 + 10}, 3);
g.fillPolygon( new int[]{_startPosX + 95, _startPosX + 95 + 15/2, _startPosX + 95 + 15}, new int[]{_startPosY + 35 + 10, _startPosY + 35 + 10 + 15/2, _startPosY + 35 + 10}, 3);
} if (numOfWheels >= 3) {
g.fillPolygon(new int[]{_startPosX + 15, _startPosX + 15 + 15/2, _startPosX + 15 + 15}, new int[]{_startPosY + 35 + 10, _startPosY + 35 + 10 + 15/2, _startPosY + 35 + 10}, 3);
} if (numOfWheels >= 4) {
g.fillPolygon(new int[]{_startPosX + 95 - 20, _startPosX + 95 - 20 + 15/2, _startPosX + 95 - 20 + 15}, new int[]{_startPosY + 35 + 10, _startPosY + 35 + 10 + 15/2, _startPosY + 35 + 10}, 3);
}
}
}

View File

@ -1,76 +1,46 @@
import java.awt.*;
public class DrawingAdvancedCruiser extends DrawingCruiser{
EntityAdvancedCruiser EntityCar;
public DrawingAdvancedCruiser(int speed, double weight, Color bodyColor, Color additionalColor, boolean bodyKit, boolean tent, boolean ornamentWheels, int width, int height) {
EntityAdvancedCruiser EntityCruiser;
public DrawingAdvancedCruiser(int speed, double weight, Color bodyColor, Color additionalColor, boolean helicopterPad, boolean coating, boolean ornamentWheels, int width, int height) {
super(speed, weight, bodyColor, width, height, 110, 60);
{
EntityCar = new EntityAdvancedCruiser(speed, weight, bodyColor, additionalColor, bodyKit, tent);
EntityCruiser = new EntityAdvancedCruiser(speed, weight, bodyColor, additionalColor, helicopterPad, coating);
}
}
public DrawingAdvancedCruiser(EntityAdvancedCruiser entityDumpTruck, IDop wheels)
public DrawingAdvancedCruiser(EntityAdvancedCruiser entityAdvancedCruiser, IDop wheels)
{
super(entityDumpTruck, wheels);
super(entityAdvancedCruiser, wheels);
{
EntityCar = entityDumpTruck;
EntityCruiser = entityAdvancedCruiser;
this.wheels = wheels;
}
}
public EntityAdvancedCruiser getEntityDumpTruck(){
return EntityCar;
public EntityAdvancedCruiser getentityAdvancedCruiser(){
return EntityCruiser;
}
public void DrawTransport(Graphics g)
{
EntityAdvancedCruiser dumpTruck;
if (EntityCar == null )
EntityAdvancedCruiser advancedCruiser;
if (EntityCruiser == null )
{
return;
}
Color addBrush = EntityCar.AdditionalColor;
Color brush = EntityCar.BodyColor;
Color addBrush = EntityCruiser.AdditionalColor;
Color brush = EntityCruiser.BodyColor;
super.DrawTransport(g);
if (EntityCar.HelicopterPad)
if (EntityCruiser.HelicopterPad)
{
g.setColor(addBrush);
int[] pointsX = new int[3];
int[] pointsY = new int[3];
pointsX[0] = _startPosX; pointsY[0] = _startPosY + 35;
pointsX[1] = _startPosX + 85; pointsY[1] = _startPosY;
pointsX[2] = _startPosX + 85; pointsY[2] = _startPosY + 35;
g.fillPolygon(pointsX, pointsY, 3);
g.drawRect(_startPosX + 35,
_startPosY + 23, 15, 15);
g.drawRect(_startPosX + 50,
_startPosY + 19, 30, 25);
}
if (EntityCar.Coating)
if (EntityCruiser.Coating)
{
g.setColor(addBrush);
int[] pointsX = new int[4];
int[] pointsY = new int[4];
pointsX[0] = _startPosX; pointsY[0] = _startPosY + 35;
pointsX[1] = _startPosX; pointsY[1] = _startPosY;
pointsX[2] = _startPosX + 85; pointsY[2] = _startPosY;
pointsX[3] = _startPosX + 85; pointsY[3] = _startPosY + 35;
g.fillPolygon(pointsX, pointsY, 4);
g.drawOval(_startPosX + 70,
_startPosY + 29, 20, 20);
}
if (EntityCar.HelicopterPad && EntityCar.Coating)
{
g.setColor(brush);
int x = _startPosX;
int y = _startPosY - 8;
g.fillRect(_startPosX, _startPosY, 95, 3);
}
if (wheels == null){return;}
wheels.drawWheels(g, _startPosX, _startPosY, brush);
}

View File

@ -2,84 +2,71 @@ import java.awt.*;
public class DrawingCruiser {
public EntityCruiser EntityCruiser;
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
private int _cruiserWidth = 110;
private int _cruiserHeight = 60;
private int _carWidth = 110;
public int GetPosX() {
return _startPosX;
}
private int _carHeight = 60;
;
public int GetPosY() {
return _startPosY;
}
public int GetWidth() {
return _cruiserWidth;
}
;
public int GetHeight() {
return _cruiserHeight;
}
/// <summary>
/// РљРѕРѕСЂРґРёРЅР°СР° X объекСР°
/// </summary>
public int GetPosX(){return _startPosX;};
/// <summary>
/// РљРѕРѕСЂРґРёРЅР°СР° Y объекСР°
/// </summary>
public int GetPosY(){return _startPosY;}
/// <summary>
/// РЁРёСЂРёРЅР° объекСР°
/// </summary>
public int GetWidth(){return _carWidth;};
/// <summary>
/// РССЃРѕСР° объекСР°
/// </summary>
public int GetHeight(){return _carHeight;}
public IDop wheels;
public DrawingCruiser(int speed, double weight, Color bodyColor, int width, int height)
{
if(width < _carWidth || height < _carHeight)
{
public DrawingCruiser(int speed, double weight, Color bodyColor, int width, int height) {
if (width < _cruiserWidth || height < _cruiserHeight) {
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
}
public EntityCruiser getEntity(){
public EntityCruiser getEntity() {
return EntityCruiser;
}
protected DrawingCruiser(int speed, double weight, Color bodyColor, int
width, int height, int carWidth, int carHeight)
{
if (width <= _carWidth || height <= _carHeight)
{
width, int height, int cruiserWidth, int cruiserHeight) {
if (width <= _cruiserWidth || height <= _cruiserHeight) {
return;
}
_pictureWidth = width;
_pictureHeight = height;
_carWidth = carWidth;
_carHeight = carHeight;
_cruiserWidth = cruiserWidth;
_cruiserHeight = cruiserHeight;
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
}
public DrawingCruiser(EntityCruiser entityCar, IDop wheels)
{
EntityCruiser = entityCar;
public DrawingCruiser(EntityCruiser entityCruiser, IDop wheels) {
EntityCruiser = entityCruiser;
this.wheels = wheels;
_pictureWidth = 1000;
_pictureHeight = 1000;
_carWidth = 110;
_carHeight = 60;
_cruiserWidth = 110;
_cruiserHeight = 60;
}
public void SetPosition(int x, int y)
{
if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight)
{
public void SetPosition(int x, int y) {
if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight) {
_startPosX = 0;
_startPosY = 0;
}
@ -87,84 +74,72 @@ public class DrawingCruiser {
_startPosY = y;
}
public void MoveTransport(Direction direction)
{
if (!CanMove(direction) || EntityCruiser == null)
{
public void MoveTransport(Direction direction) {
if (!CanMove(direction) || EntityCruiser == null) {
return;
}
switch (direction)
{
//влево
switch (direction) {
case Left:
_startPosX -= (int)EntityCruiser.Step();
_startPosX -= (int) EntityCruiser.Step();
break;
//вверС
case Up:
_startPosY -= (int)EntityCruiser.Step();
_startPosY -= (int) EntityCruiser.Step();
break;
// вправо
case Right:
_startPosX += (int)EntityCruiser.Step();
_startPosX += (int) EntityCruiser.Step();
break;
//РІРЅРёР·
case Down:
_startPosY += (int)EntityCruiser.Step();
_startPosY += (int) EntityCruiser.Step();
break;
}
}
public boolean CanMove(Direction direction)
{
if (EntityCruiser == null)
{
public boolean CanMove(Direction direction) {
if (EntityCruiser == null) {
return false;
}
switch (direction)
{
//влево
switch (direction) {
case Left:
return (_startPosX - EntityCruiser.Step()) > 0;
//вверС
return (_startPosX - EntityCruiser.Step()) > 0;
case Up:
return _startPosY - EntityCruiser.Step() > 0;
// вправо
case Right:
return _startPosX + EntityCruiser.Step() + _carWidth < _pictureWidth;
//РІРЅРёР·
return _startPosX + EntityCruiser.Step() + _cruiserWidth < _pictureWidth;
case Down:
return _startPosY + EntityCruiser.Step() + _carHeight < _pictureHeight;
return _startPosY + EntityCruiser.Step() + _cruiserHeight < _pictureHeight;
default:
return false;
}
}
public void DrawTransport(Graphics g)
{
if (EntityCruiser == null)
{
public void DrawTransport(Graphics g) {
if (EntityCruiser == null) {
return;
}
g.setColor(EntityCruiser.BodyColor);
g.drawRect(_startPosX + 9, _startPosY + 15, 10, 30);
g.drawRect(_startPosX + 90, _startPosY + 15, 10,
30);
g.drawRect(_startPosX + 20, _startPosY + 4, 70, 52);
//граниСС Р°РІСомобиля
g.fillRect(_startPosX, _startPosY + 35, 110, 10);
g.fillRect( _startPosX + 85, _startPosY, 25, 35);
/*g.fillOval( _startPosX, _startPosY + 35 + 10, 15, 15);
g.fillOval( _startPosX + 15, _startPosY + 35 + 10, 15, 15);
g.fillOval( _startPosX + 95, _startPosY + 35 + 10, 15, 15);*/
g.fillRect(_startPosX + 10, _startPosY + 15, 10, 30);
g.fillRect(_startPosX + 90, _startPosY + 15, 10, 30);
g.fillRect(_startPosX + 20, _startPosY + 5, 70, 50);
g.fillRect(_startPosX + 10, _startPosY + 15, 10, 30);
g.fillRect(_startPosX + 90, _startPosY + 15, 10, 30);
g.fillRect(_startPosX + 20, _startPosY + 5, 70, 50);
if (wheels == null){return;}
Point[] points1 = new Point[3];
points1[0] = new Point(_startPosX + 100, _startPosY + 5);
points1[1] = new Point(_startPosX + 100, _startPosY + 55);
points1[2] = new Point(_startPosX + 150, _startPosY + 30);
g.fillPolygon(new int[]{points1[0].x, points1[1].x, points1[2].x},
new int[]{points1[0].y, points1[1].y, points1[2].y}, 3);
g.fillRect(_startPosX + 5, _startPosY + 15, 10, 10);
g.fillRect(_startPosX + 5, _startPosY + 35, 10, 10);
if (wheels == null) {
return;
}
wheels.drawWheels(g, _startPosX, _startPosY, EntityCruiser.BodyColor);
}
public IMoveableObject GetMoveableObject(){return new DrawingObjectCruiser(this);}
}

View File

@ -1,28 +1,23 @@
public class DrawingObjectCruiser implements IMoveableObject {
private DrawingCruiser _drawningCruiser = null;
public DrawingObjectCruiser(DrawingCruiser drawningCruiser) {
_drawningCruiser = drawningCruiser;
}
public ObjectParameters GetObjectPosition() {
if (_drawningCruiser == null || _drawningCruiser.EntityCruiser == null) {
return null;
}
return new ObjectParameters(_drawningCruiser.GetPosX(), _drawningCruiser.GetPosY(), _drawningCruiser.GetWidth(), _drawningCruiser.GetHeight());
}
public int GetStep() {
return (int) (_drawningCruiser.EntityCruiser.Step());
}
public boolean CheckCanMove(Direction direction) {
if (_drawningCruiser.CanMove(direction)){
return true;
}
return false;
}
public void MoveObject(Direction direction) {
_drawningCruiser.MoveTransport(direction);
}

View File

@ -1,22 +1,8 @@
import java.awt.*;
public class EntityAdvancedCruiser extends EntityCruiser{
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor;
/// <summary>
/// Признак (опция) наличия кузова
/// </summary>
public boolean HelicopterPad ;
/// <summary>
/// Признак (опция) наличия tent
/// </summary>
public boolean Coating ;
public EntityAdvancedCruiser(int speed, double weight, Color bodyColor, Color
additionalColor, boolean helicopterPad, boolean coating)
{
@ -27,5 +13,3 @@ public class EntityAdvancedCruiser extends EntityCruiser{
}
}

View File

@ -1,12 +1,10 @@
import java.awt.*;
public class EntityCruiser {
public int Speed;
public double Weight;
public Color BodyColor;
public double Step() {return (double)Speed * 100 / Weight;};
public boolean OrnamentWheels;
public EntityCruiser(int speed, double weight, Color bodyColor)
{
Speed = speed;

View File

@ -9,7 +9,7 @@ public class GameFrame extends JFrame {
GameFrame() {
this.setSize(710, 535);
this.setTitle("DumpTruck");
this.setTitle("Cruiser");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setLocationRelativeTo(null);
@ -29,8 +29,8 @@ public class GameFrame extends JFrame {
static final int SCREEN_H = 500;
int xx = 0;
int yy = 0;
private DrawingAdvancedCruiser _drawningDumpTruck;
private DrawingCruiser _drawningCar;
private DrawingAdvancedCruiser _drawningAdvancedCruiser;
private DrawingCruiser _drawningCruiser;
private AbstractStrategy _abstractStrategy;
GamePanel() {
@ -38,81 +38,76 @@ public class GameFrame extends JFrame {
this.setPreferredSize(new Dimension(SCREEN_W, SCREEN_H));
GridBagConstraints layers = new GridBagConstraints();
JButton buttonCar = new JButton("Создать грузовик");
buttonCar.addActionListener(new ActionListener() {
JButton buttonCruiser = new JButton("Создать простой объект");
buttonCruiser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
_drawningCar = new DrawingCruiser(random.nextInt(100, 300),
_drawningCruiser = new DrawingCruiser(random.nextInt(100, 300),
random.nextInt(1000, 3000),
Color.getHSBColor(random.nextInt(0, 256), random.nextInt(0, 256),
random.nextInt(0, 256)),
GamePanel.SCREEN_W, GamePanel.SCREEN_H);
_drawningCar.SetPosition(random.nextInt(10, 100), random.nextInt(10,
_drawningCruiser.SetPosition(random.nextInt(10, 100), random.nextInt(10,
100));
int ornament = random.nextInt(1, 4);
switch (ornament){
case 1:
_drawningCar.wheels = new NumberOfWheels(random.nextInt(2, 5));
_drawningCruiser.wheels = new NumberOfWheels(random.nextInt(2, 5));
break;
case 2:
_drawningCar.wheels = new DopClassRect(random.nextInt(2, 5));
_drawningCruiser.wheels = new DopClassRect(random.nextInt(2, 5));
break;
default:
_drawningCar.wheels = new DopClassTriangle(random.nextInt(2, 5));
_drawningCruiser.wheels = new DopClassMixed(random.nextInt(2, 5));
break;
}
repaint();
}
});
buttonCar.setBounds(20 + 150, 390, 120, 30);
this.add(buttonCar);
buttonCruiser.setBounds(20 + 150, 390, 120, 30);
this.add(buttonCruiser);
JButton buttonDumpCar = new JButton("Создать самосвал");
buttonDumpCar.addActionListener(new ActionListener() {
JButton buttonAdvancedCruiser = new JButton("Создать продвинутый объект");
buttonAdvancedCruiser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
System.out.println("F");
_drawningCar = new DrawingAdvancedCruiser(random.nextInt(100, 300),
_drawningCruiser = new DrawingAdvancedCruiser(random.nextInt(100, 300),
random.nextInt(1000, 3000),
Color.getHSBColor(random.nextInt(0, 256), random.nextInt(0, 256),
random.nextInt(0, 256)), Color.getHSBColor(random.nextInt(0, 256), random.nextInt(0, 256),
random.nextInt(0, 256)), random.nextBoolean(),random.nextBoolean(),random.nextBoolean(),
GamePanel.SCREEN_W, GamePanel.SCREEN_H); //TODO
_drawningCar.SetPosition(random.nextInt(10, 100), random.nextInt(10,
_drawningCruiser.SetPosition(random.nextInt(10, 100), random.nextInt(10,
100));
int ornament = random.nextInt(1, 4);
switch (ornament){
case 1:
_drawningCar.wheels = new NumberOfWheels(random.nextInt(2, 5));
_drawningCruiser.wheels = new NumberOfWheels(random.nextInt(2, 5));
break;
case 2:
_drawningCar.wheels = new DopClassRect(random.nextInt(2, 5));
_drawningCruiser.wheels = new DopClassRect(random.nextInt(2, 5));
break;
default:
_drawningCar.wheels = new DopClassTriangle(random.nextInt(2, 5));
_drawningCruiser.wheels = new DopClassMixed(random.nextInt(2, 5));
break;
}
repaint();
}
});
buttonDumpCar.setBounds( 20, 390, 120, 30);
this.add(buttonDumpCar);
buttonAdvancedCruiser.setBounds( 20, 390, 120, 30);
this.add(buttonAdvancedCruiser);
JTextField textStrategy = new JTextField();
textStrategy.setBounds(550, 20, 120, 30);
this.add(textStrategy);
JButton buttonStep = new JButton("Шаг");
buttonStep.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_drawningCar == null)
if (_drawningCruiser == null)
{
return;
}
@ -131,39 +126,30 @@ public class GameFrame extends JFrame {
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new DrawingObjectCruiser(_drawningCar), SCREEN_W, SCREEN_H);
//textStrategy.setText();
_abstractStrategy.SetData(new DrawingObjectCruiser(_drawningCruiser), SCREEN_W, SCREEN_H);
}
if (_abstractStrategy == null)
{
return;
}
System.out.println("step");
_abstractStrategy.MakeStep();
repaint();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
//comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
});
buttonStep.setBounds(550, 60, 70, 30);
this.add(buttonStep);
JPanel panel = new JPanel(new GridBagLayout());
JButton up = new BasicArrowButton(BasicArrowButton.NORTH);
up.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_drawningCar.MoveTransport(Direction.Up);
_drawningCruiser.MoveTransport(Direction.Up);
repaint();
}
});
@ -171,7 +157,7 @@ public class GameFrame extends JFrame {
left.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_drawningCar.MoveTransport(Direction.Left);
_drawningCruiser.MoveTransport(Direction.Left);
repaint();
}
});
@ -179,7 +165,7 @@ public class GameFrame extends JFrame {
down.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_drawningCar.MoveTransport(Direction.Down);
_drawningCruiser.MoveTransport(Direction.Down);
repaint();
}
});
@ -187,12 +173,10 @@ public class GameFrame extends JFrame {
right.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_drawningCar.MoveTransport(Direction.Right);
_drawningCruiser.MoveTransport(Direction.Right);
repaint();
}
});
up.setBounds(570, 350, 30, 30);
this.add(up);
@ -205,35 +189,15 @@ public class GameFrame extends JFrame {
right.setBounds(570 + 40, 350 + 40, 30, 30);
this.add(right);
}
void setTruck(DrawingAdvancedCruiser _truck) {
_drawningDumpTruck = _truck;
}
private void Draw()
{
if (_drawningCar == null)
{
return;
}
Graphics gr =new DebugGraphics();
_drawningCar.DrawTransport(gr);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
draw(g);
}
public void draw(Graphics g) {
if (_drawningCar != null) {
_drawningCar.DrawTransport(g);
if (_drawningCruiser != null) {
_drawningCruiser.DrawTransport(g);
}
}
}
}

View File

@ -1,17 +1,6 @@
public interface IMoveableObject {
/// <summary>
/// Получение координаты X объекта
/// </summary>
public ObjectParameters GetObjectPosition();
/// <summary>
/// Шаг объекта
/// </summary>
public int GetStep();
boolean CheckCanMove(Direction direction);
/// <summary>
/// Изменение направления пермещения объекта
/// </summary>
/// <param name="direction">Направление</param>
void MoveObject(Direction direction);
}

View File

@ -11,27 +11,19 @@ public class MoveToBorder extends AbstractStrategy {
objParams.DownBorder() <= FieldHeight &&
objParams.DownBorder() + GetStep() >= FieldHeight;
}
protected void MoveToTarget()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return;
}
var diffX = FieldWidth - objParams.ObjectMiddleHorizontal();
if (Math.abs(diffX) > GetStep()) {
MoveRight();
}
var diffY = FieldHeight - objParams.ObjectMiddleVertical();
if (Math.abs(diffY) > GetStep()) {
MoveDown();
}
}
}

View File

@ -10,15 +10,12 @@ public class MoveToCenter extends AbstractStrategy {
objParams.ObjectMiddleVertical() <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
}
protected void MoveToTarget()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return;
}
var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
if (Math.abs(diffX) > GetStep()) {
if (diffX > 0) {
@ -38,7 +35,4 @@ public class MoveToCenter extends AbstractStrategy {
}
}
}
}

View File

@ -24,12 +24,12 @@ public class NumberOfWheels implements IDop{
public void drawWheels(Graphics g, int _startPosX, int _startPosY, Color c) {
g.setColor(c);
if (numOfWheels >= 2) {
g.fillOval(_startPosX, _startPosY + 35 + 10, 15, 15);
g.fillOval(_startPosX + 95, _startPosY + 35 + 10, 15, 15);
g.fillOval(_startPosX+55, _startPosY+15, 20, 15);
g.fillOval(_startPosX+55, _startPosY+30, 20, 15);
} if (numOfWheels >= 3) {
g.fillOval(_startPosX + 15, _startPosY + 35 + 10, 15, 15);
g.fillOval(_startPosX+30, _startPosY+15, 20, 15);
} if(numOfWheels >= 4){
g.fillOval(_startPosX + 95 - 20, _startPosY + 35 + 10, 15, 15);
g.fillOval(_startPosX+85, _startPosY+15, 20, 15);
}
}
}

View File

@ -4,40 +4,12 @@ public class ObjectParameters {
private final int _y;
private final int _width;
private final int _height;
/// <summary>
/// Левая граница
/// </summary>
public int LeftBorder(){return _x;}
/// <summary>
/// Верхняя граница
/// </summary>
public int TopBorder(){return _y;}
/// <summary>
/// Правая граница
/// </summary>
public int RightBorder(){return _x + _width;}
/// <summary>
/// Нижняя граница
/// </summary>
public int DownBorder(){return _y + _height;}
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleHorizontal(){return _x + _width / 2;}
/// <summary>
/// Середина объекта
/// </summary>
public int ObjectMiddleVertical(){return _y + _height / 2;}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
/// <param name="width">Ширина</param>
/// <param name="height">Высота</param>
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
@ -46,4 +18,3 @@ public class ObjectParameters {
_height = height;
}
}

View File

@ -1,8 +1,5 @@
public enum Status {
NotInit,
InProgress,
Finish
}