This commit is contained in:
Yunusov_Niyaz 2023-11-04 02:32:04 +04:00
parent 43d4951e5d
commit dc8923d850
16 changed files with 16 additions and 0 deletions

View File

@ -6,6 +6,7 @@ public abstract class AbstractStrategy {
private int fieldHeight; private int fieldHeight;
protected int getFieldHeight(){return fieldHeight;} protected int getFieldHeight(){return fieldHeight;}
public Status getStatus() {return state;} public Status getStatus() {return state;}
public void setData(IMoveableObject moveableObject, int width, int height){ public void setData(IMoveableObject moveableObject, int width, int height){
if (moveableObject == null) if (moveableObject == null)
{ {

View File

@ -1,4 +1,5 @@
import java.awt.*; import java.awt.*;
public class DrawingBus { public class DrawingBus {
protected EntityBus entityBus; protected EntityBus entityBus;
public EntityBus getEntityBus() { public EntityBus getEntityBus() {

View File

@ -1,4 +1,5 @@
import java.awt.*; import java.awt.*;
public class DrawingDoors implements IDrawDoors{ public class DrawingDoors implements IDrawDoors{
private DoorsNumber number; private DoorsNumber number;
@Override @Override

View File

@ -1,4 +1,5 @@
import java.awt.*; import java.awt.*;
public class DrawingDoorsRoundedUp implements IDrawDoors{ public class DrawingDoorsRoundedUp implements IDrawDoors{
private DoorsNumber number; private DoorsNumber number;
@Override @Override

View File

@ -1,4 +1,5 @@
import java.awt.*; import java.awt.*;
public class DrawingDoorsRoundedUpAndDown implements IDrawDoors{ public class DrawingDoorsRoundedUpAndDown implements IDrawDoors{
private DoorsNumber number; private DoorsNumber number;
@Override @Override

View File

@ -3,6 +3,7 @@ public class DrawingObjectBus implements IMoveableObject{
public DrawingObjectBus(DrawingBus drawingBus){ public DrawingObjectBus(DrawingBus drawingBus){
this.drawingBus = drawingBus; this.drawingBus = drawingBus;
} }
@Override @Override
public ObjectParameters getObjectPosition(){ public ObjectParameters getObjectPosition(){
if(drawingBus == null || drawingBus.getEntityBus() == null) if(drawingBus == null || drawingBus.getEntityBus() == null)

View File

@ -1,4 +1,5 @@
import java.awt.*; import java.awt.*;
public class DrawingTrolleybus extends DrawingBus{ public class DrawingTrolleybus extends DrawingBus{
public DrawingTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor, public DrawingTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor,
boolean roga, boolean battery, int width, int height, int doorsNumber, int doorsType) boolean roga, boolean battery, int width, int height, int doorsNumber, int doorsType)

View File

@ -1,5 +1,6 @@
import java.awt.*; import java.awt.*;
import java.util.function.Supplier; import java.util.function.Supplier;
public class EntityBus { public class EntityBus {
private int speed; private int speed;
public int getSpeed() { public int getSpeed() {

View File

@ -1,4 +1,5 @@
import java.awt.*; import java.awt.*;
public class EntityTrolleybus extends EntityBus{ public class EntityTrolleybus extends EntityBus{
private Color additionalColor; private Color additionalColor;
public Color getAdditionalColor(){return additionalColor;} public Color getAdditionalColor(){return additionalColor;}

View File

@ -5,6 +5,7 @@ import java.awt.event.ActionEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
public class FrameTrolleybus extends JFrame { public class FrameTrolleybus extends JFrame {
private DrawingBus drawingBus; private DrawingBus drawingBus;
private AbstractStrategy abstractStrategy; private AbstractStrategy abstractStrategy;

View File

@ -1,4 +1,5 @@
import java.awt.*; import java.awt.*;
public interface IDrawDoors { public interface IDrawDoors {
void setNumber(int x); void setNumber(int x);
void drawDoors(Graphics2D graphics2D, int _startX, int _startY); void drawDoors(Graphics2D graphics2D, int _startX, int _startY);

View File

@ -1,5 +1,6 @@
public interface IMoveableObject { public interface IMoveableObject {
ObjectParameters getObjectPosition(); ObjectParameters getObjectPosition();
int getStep(); int getStep();
boolean checkCanMove(DirectionType direction); boolean checkCanMove(DirectionType direction);
void moveObject(DirectionType direction); void moveObject(DirectionType direction);

View File

@ -8,6 +8,7 @@ public class MoveToBorder extends AbstractStrategy{
return objParams.getRightBorder() + getStep() >= getFieldWidth() && return objParams.getRightBorder() + getStep() >= getFieldWidth() &&
objParams.getDownBorder() + getStep() >= getFieldHeight(); objParams.getDownBorder() + getStep() >= getFieldHeight();
} }
@Override @Override
protected void moveToTarget() { protected void moveToTarget() {
var objParams = getObjectParameters(); var objParams = getObjectParameters();

View File

@ -9,6 +9,7 @@ public class MoveToCenter extends AbstractStrategy{
objParams.getObjectMiddleVertical() <= getFieldHeight() / 2 && objParams.getObjectMiddleVertical() <= getFieldHeight() / 2 &&
objParams.getObjectMiddleVertical() + getStep() >= getFieldHeight() / 2; objParams.getObjectMiddleVertical() + getStep() >= getFieldHeight() / 2;
} }
@Override @Override
protected void moveToTarget() { protected void moveToTarget() {
ObjectParameters objParams = getObjectParameters(); ObjectParameters objParams = getObjectParameters();

View File

@ -9,6 +9,7 @@ public class ObjectParameters {
public int getDownBorder() {return POS_Y + HEIGHT;} public int getDownBorder() {return POS_Y + HEIGHT;}
public int getObjectMiddleHorizontal() {return POS_X + this.WIDTH / 2;} public int getObjectMiddleHorizontal() {return POS_X + this.WIDTH / 2;}
public int getObjectMiddleVertical() {return POS_Y + this.HEIGHT / 2;} public int getObjectMiddleVertical() {return POS_Y + this.HEIGHT / 2;}
public ObjectParameters(int x, int y, int width, int height) public ObjectParameters(int x, int y, int width, int height)
{ {
POS_X = x; POS_X = x;

View File

@ -2,4 +2,5 @@ public enum Status {
NOT_INIT, NOT_INIT,
IN_PROGRESS, IN_PROGRESS,
FINISH FINISH
} }