Lab2+++
This commit is contained in:
parent
43d4951e5d
commit
dc8923d850
@ -6,6 +6,7 @@ public abstract class AbstractStrategy {
|
||||
private int fieldHeight;
|
||||
protected int getFieldHeight(){return fieldHeight;}
|
||||
public Status getStatus() {return state;}
|
||||
|
||||
public void setData(IMoveableObject moveableObject, int width, int height){
|
||||
if (moveableObject == null)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingBus {
|
||||
protected EntityBus entityBus;
|
||||
public EntityBus getEntityBus() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingDoors implements IDrawDoors{
|
||||
private DoorsNumber number;
|
||||
@Override
|
||||
|
@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingDoorsRoundedUp implements IDrawDoors{
|
||||
private DoorsNumber number;
|
||||
@Override
|
||||
|
@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingDoorsRoundedUpAndDown implements IDrawDoors{
|
||||
private DoorsNumber number;
|
||||
@Override
|
||||
|
@ -3,6 +3,7 @@ public class DrawingObjectBus implements IMoveableObject{
|
||||
public DrawingObjectBus(DrawingBus drawingBus){
|
||||
this.drawingBus = drawingBus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectParameters getObjectPosition(){
|
||||
if(drawingBus == null || drawingBus.getEntityBus() == null)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingTrolleybus extends DrawingBus{
|
||||
public DrawingTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean roga, boolean battery, int width, int height, int doorsNumber, int doorsType)
|
||||
|
@ -1,5 +1,6 @@
|
||||
import java.awt.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class EntityBus {
|
||||
private int speed;
|
||||
public int getSpeed() {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityTrolleybus extends EntityBus{
|
||||
private Color additionalColor;
|
||||
public Color getAdditionalColor(){return additionalColor;}
|
||||
|
@ -5,6 +5,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
public class FrameTrolleybus extends JFrame {
|
||||
private DrawingBus drawingBus;
|
||||
private AbstractStrategy abstractStrategy;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawDoors {
|
||||
void setNumber(int x);
|
||||
void drawDoors(Graphics2D graphics2D, int _startX, int _startY);
|
||||
|
@ -1,5 +1,6 @@
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters getObjectPosition();
|
||||
|
||||
int getStep();
|
||||
boolean checkCanMove(DirectionType direction);
|
||||
void moveObject(DirectionType direction);
|
||||
|
@ -8,6 +8,7 @@ public class MoveToBorder extends AbstractStrategy{
|
||||
return objParams.getRightBorder() + getStep() >= getFieldWidth() &&
|
||||
objParams.getDownBorder() + getStep() >= getFieldHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveToTarget() {
|
||||
var objParams = getObjectParameters();
|
||||
|
@ -9,6 +9,7 @@ public class MoveToCenter extends AbstractStrategy{
|
||||
objParams.getObjectMiddleVertical() <= getFieldHeight() / 2 &&
|
||||
objParams.getObjectMiddleVertical() + getStep() >= getFieldHeight() / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveToTarget() {
|
||||
ObjectParameters objParams = getObjectParameters();
|
||||
|
@ -9,6 +9,7 @@ public class ObjectParameters {
|
||||
public int getDownBorder() {return POS_Y + HEIGHT;}
|
||||
public int getObjectMiddleHorizontal() {return POS_X + this.WIDTH / 2;}
|
||||
public int getObjectMiddleVertical() {return POS_Y + this.HEIGHT / 2;}
|
||||
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
POS_X = x;
|
||||
|
@ -2,4 +2,5 @@ public enum Status {
|
||||
NOT_INIT,
|
||||
IN_PROGRESS,
|
||||
FINISH
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user