удаление всего
This commit is contained in:
parent
d050b4e748
commit
3f28d33015
@ -1,57 +0,0 @@
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject moveableObject;
|
||||
private Status state = Status.NOTINIT;
|
||||
private int FieldWidth;
|
||||
protected int getFieldWidth(){return FieldWidth;}
|
||||
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){
|
||||
state = Status.NOTINIT;
|
||||
return;
|
||||
}
|
||||
state = Status.INPROGRESS;
|
||||
this.moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
public void MakeStep(){
|
||||
if(state != Status.INPROGRESS)
|
||||
return;
|
||||
if(IsTargetDestination()){
|
||||
state = Status.FINISH;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
protected boolean MoveLeft() {return MoveTo(DirectionType.LEFT);}
|
||||
protected boolean MoveRight() {return MoveTo(DirectionType.RIGHT);}
|
||||
protected boolean MoveUp() {return MoveTo(DirectionType.UP);}
|
||||
protected boolean MoveDown() {return MoveTo(DirectionType.DOWN);}
|
||||
protected Supplier<ObjectParameters> getObjectParameters = () -> moveableObject.getObjectPosition();
|
||||
|
||||
protected Integer GetStep(){
|
||||
if(state != Status.INPROGRESS)
|
||||
return null;
|
||||
return moveableObject.getStep();
|
||||
}
|
||||
|
||||
protected abstract void MoveToTarget();
|
||||
protected abstract boolean IsTargetDestination();
|
||||
|
||||
private boolean MoveTo(DirectionType direction){
|
||||
if(state != Status.INPROGRESS)
|
||||
return false;
|
||||
if(moveableObject.checkCanMove(direction)){
|
||||
moveableObject.moveObject(direction);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
public enum DirectionType {
|
||||
UP,
|
||||
DOWN,
|
||||
LEFT,
|
||||
RIGHT
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingAircraft {
|
||||
protected EntityAircraft entityAircraft ;
|
||||
protected void setEntityShip(EntityAircraft entityShip){
|
||||
this.entityAircraft = entityAircraft;
|
||||
}
|
||||
public EntityAircraft getEntityShip() {
|
||||
return entityAircraft;
|
||||
}
|
||||
private IDrawImprovements drawingImprovements;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
public int getPosX(){
|
||||
return _startPosX;
|
||||
}
|
||||
protected int _startPosY;
|
||||
public int getPosY(){
|
||||
return _startPosY;
|
||||
}
|
||||
private final int _ShipWidth = 164;
|
||||
public int getWidth() {
|
||||
return _ShipWidth;
|
||||
}
|
||||
private final int _ShipHeight = 40;
|
||||
public int getHeight(){
|
||||
return _ShipHeight;
|
||||
}
|
||||
public DrawingAircraft(int speed, double weight, Color bodyColor, int width, int height, int improvementsType, int improvementsNumber) {
|
||||
if (width < _ShipWidth || height < _ShipHeight)
|
||||
return;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
entityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||
switch (improvementsType){
|
||||
case 1:
|
||||
drawingImprovements = new DrawingImprovementsSquare();
|
||||
break;
|
||||
case 2:
|
||||
drawingImprovements = new DrawingImprovementsCircle();
|
||||
break;
|
||||
default:
|
||||
drawingImprovements = new DrawingImprovementsTriangle();
|
||||
break;
|
||||
}
|
||||
drawingImprovements.setNumber(improvementsNumber);
|
||||
}
|
||||
public void setPosition(int x, int y)
|
||||
{
|
||||
if (_startPosX > (_pictureWidth - _ShipWidth) || _startPosY>(_pictureHeight - _ShipHeight) || x <= 0 || y <= 0)
|
||||
x = y = 2;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public void drawTransport(Graphics2D g) {
|
||||
if (entityAircraft == null)
|
||||
return;
|
||||
Color penColor = Color.BLACK;
|
||||
Color bodyColor = entityAircraft.getBodyColor();
|
||||
g.setColor(penColor);
|
||||
g.drawLine(_startPosX+4, _startPosY, _startPosX + 124, _startPosY);
|
||||
g.drawLine(_startPosX+124, _startPosY, _startPosX + 164, _startPosY+20);
|
||||
g.drawLine(_startPosX + 164, _startPosY+20, _startPosX + 124, _startPosY + 40);
|
||||
g.drawLine(_startPosX + 164, _startPosY + 20, _startPosX + 124, _startPosY + 40);
|
||||
g.drawLine(_startPosX + 124, _startPosY + 40, _startPosX + 4, _startPosY + 40);
|
||||
g.drawLine(_startPosX+4, _startPosY + 40, _startPosX + 4, _startPosY);
|
||||
g.setColor(bodyColor);
|
||||
g.fillRect(_startPosX, _startPosY + 6, 4, 12);
|
||||
g.fillRect(_startPosX, _startPosY + 24, 4, 12);
|
||||
g.setColor(penColor);
|
||||
g.drawOval(_startPosX + 115, _startPosY + 13, 14, 14);
|
||||
g.drawRect(_startPosX + 63, _startPosY + 13, 27, 14);
|
||||
g.drawRect(_startPosX + 90, _startPosY + 9, 14, 22);
|
||||
g.setColor(bodyColor);
|
||||
drawingImprovements.drawImprovements(g, _startPosX, _startPosY);
|
||||
}
|
||||
public boolean canMove(DirectionType direction) {
|
||||
if (entityAircraft == null) {
|
||||
return false;
|
||||
}
|
||||
switch(direction) {
|
||||
case LEFT:
|
||||
return _startPosX - entityAircraft.step.get().intValue() > 0;
|
||||
case UP:
|
||||
return _startPosY - entityAircraft.step.get().intValue() > 0;
|
||||
case RIGHT:
|
||||
return _startPosX + entityAircraft.step.get().intValue() + _ShipWidth < _pictureWidth;
|
||||
case DOWN:
|
||||
return _startPosY + entityAircraft.step.get().intValue() + _ShipWidth < _pictureWidth;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void moveTransport(DirectionType direction)
|
||||
{
|
||||
if (entityAircraft == null)
|
||||
return;
|
||||
int step = entityAircraft.step.get().intValue();
|
||||
switch (direction)
|
||||
{
|
||||
case LEFT:
|
||||
if (_startPosX - step > 0)
|
||||
_startPosX -= step;
|
||||
break;
|
||||
case UP:
|
||||
if (_startPosY - step > 0)
|
||||
_startPosY -= step;
|
||||
break;
|
||||
case RIGHT:
|
||||
if (_startPosX + _ShipWidth + step < _pictureWidth)
|
||||
_startPosX += step;
|
||||
break;
|
||||
case DOWN:
|
||||
if (_startPosY + _ShipHeight + step < _pictureHeight)
|
||||
_startPosY += step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingAircraftCarrier extends DrawingAircraft {
|
||||
public DrawingAircraftCarrier(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, boolean cabin, boolean runway, int width, int height, int improvementsType, int improvementsNumber){
|
||||
super(speed, weight, bodyColor, width, height, improvementsType, improvementsNumber);
|
||||
if(entityAircraft != null)
|
||||
entityAircraft = new EntityAircraftCarrier(speed, weight, bodyColor, additionalColor,cabin, runway);
|
||||
}
|
||||
public void drawTransport(Graphics2D g)
|
||||
{
|
||||
if (!(entityAircraft instanceof EntityAircraftCarrier))
|
||||
return;
|
||||
EntityAircraftCarrier entityAircraftCarrier = (EntityAircraftCarrier) entityAircraft;
|
||||
Color additionalColor = entityAircraftCarrier.getAdditionalColor();
|
||||
super.drawTransport(g);
|
||||
if(entityAircraftCarrier.getRunway()){
|
||||
g.setColor(additionalColor);
|
||||
g.fillRect(_startPosX + 4, _startPosY + 13, 59, 14);
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawLine(_startPosX + 62, _startPosY + 19, _startPosX + 52, _startPosY + 19);
|
||||
g.drawLine(_startPosX + 47, _startPosY + 19, _startPosX + 37, _startPosY + 19);
|
||||
g.drawLine(_startPosX + 32, _startPosY + 19, _startPosX + 22, _startPosY + 19);
|
||||
g.drawLine(_startPosX + 17, _startPosY + 19, _startPosX + 7, _startPosY + 19);
|
||||
}
|
||||
if (entityAircraftCarrier.getCabin())
|
||||
{
|
||||
g.setColor(additionalColor);
|
||||
g.fillRect(_startPosX + 90, _startPosY, 15, 9);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
import java.awt.*;
|
||||
public class DrawingImprovementsCircle implements IDrawImprovements{
|
||||
private NumberImprovement number;
|
||||
public void setNumber(int x){
|
||||
if(x <= 2)
|
||||
number = NumberImprovement.TWO;
|
||||
if(x == 4)
|
||||
number = NumberImprovement.FOUR;
|
||||
if(x >= 6)
|
||||
number = NumberImprovement.SIX;
|
||||
}
|
||||
public void drawImprovements(Graphics2D g, int _startPosX, int _startPosY){
|
||||
g.fillOval(_startPosX+5, _startPosY+1, 15, 12);
|
||||
g.fillOval(_startPosX+5, _startPosY+27, 15, 13);
|
||||
if (number == NumberImprovement.FOUR || number == NumberImprovement.SIX){
|
||||
g.fillOval(_startPosX+26, _startPosY+1, 15, 12);
|
||||
g.fillOval(_startPosX+26, _startPosY+27, 15, 13);
|
||||
}
|
||||
if (number == NumberImprovement.SIX){
|
||||
g.fillOval(_startPosX+48, _startPosY+1, 15, 12);
|
||||
g.fillOval(_startPosX+48, _startPosY+27, 15, 13);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingImprovementsSquare implements IDrawImprovements{
|
||||
private NumberImprovement number;
|
||||
public void setNumber(int x){
|
||||
if(x <= 2)
|
||||
number = NumberImprovement.TWO;
|
||||
if(x == 4)
|
||||
number = NumberImprovement.FOUR;
|
||||
if(x >= 6)
|
||||
number = NumberImprovement.SIX;
|
||||
}
|
||||
public void drawImprovements(Graphics2D g, int _startPosX, int _startPosY){
|
||||
g.fillRect(_startPosX+5, _startPosY+1, 15, 12);
|
||||
g.fillRect(_startPosX+5, _startPosY+27, 15, 13);
|
||||
if (number == NumberImprovement.FOUR || number == NumberImprovement.SIX){
|
||||
g.fillRect(_startPosX+26, _startPosY+1, 15, 12);
|
||||
g.fillRect(_startPosX+26, _startPosY+27, 15, 13);
|
||||
}
|
||||
if (number == NumberImprovement.SIX){
|
||||
g.fillRect(_startPosX+48, _startPosY+1, 15, 12);
|
||||
g.fillRect(_startPosX+48, _startPosY+27, 15, 13);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
import java.awt.*;
|
||||
public class DrawingImprovementsTriangle implements IDrawImprovements{
|
||||
private NumberImprovement number;
|
||||
public void setNumber(int x){
|
||||
if(x <= 2)
|
||||
number = NumberImprovement.TWO;
|
||||
if(x == 4)
|
||||
number = NumberImprovement.FOUR;
|
||||
if(x >= 6)
|
||||
number = NumberImprovement.SIX;
|
||||
}
|
||||
public void drawImprovements(Graphics2D g, int _startPosX, int _startPosY){
|
||||
int[] pointX = new int[]{ _startPosX+5, _startPosX+13, _startPosX+ 21};
|
||||
int[] pointY = new int[]{ _startPosY + 1, _startPosY+13, _startPosY+1};
|
||||
g.fillPolygon(pointX, pointY, 3);
|
||||
pointX = new int[]{ _startPosX+5, _startPosX+13, _startPosX+ 21};
|
||||
pointY = new int[]{ _startPosY + 40, _startPosY+27, _startPosY+40};
|
||||
g.fillPolygon(pointX, pointY, 3);
|
||||
if (number == NumberImprovement.FOUR || number == NumberImprovement.SIX){
|
||||
pointX = new int[]{ _startPosX+26, _startPosX+34, _startPosX+ 42};
|
||||
pointY = new int[]{ _startPosY + 1, _startPosY+13, _startPosY+1};
|
||||
g.fillPolygon(pointX, pointY, 3);
|
||||
pointX = new int[]{ _startPosX+26, _startPosX+34, _startPosX+ 42};
|
||||
pointY = new int[]{ _startPosY + 40, _startPosY+27, _startPosY+40};
|
||||
g.fillPolygon(pointX, pointY, 3);
|
||||
}
|
||||
if (number == NumberImprovement.SIX){
|
||||
pointX = new int[]{ _startPosX+47, _startPosX+55, _startPosX+ 63};
|
||||
pointY = new int[]{ _startPosY + 1, _startPosY+13, _startPosY+1};
|
||||
g.fillPolygon(pointX, pointY, 3);
|
||||
pointX = new int[]{ _startPosX+47, _startPosX+55, _startPosX+ 63};
|
||||
pointY = new int[]{ _startPosY + 40, _startPosY+27, _startPosY+40};
|
||||
g.fillPolygon(pointX, pointY, 3);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
public class DrawingObjectAircraftCarrier implements IMoveableObject{
|
||||
private final DrawingAircraft drawingAircraft;
|
||||
|
||||
public DrawingObjectAircraftCarrier(DrawingAircraft drawingShip){
|
||||
this.drawingAircraft = drawingShip;
|
||||
}
|
||||
public ObjectParameters getObjectPosition(){
|
||||
if(drawingAircraft == null || drawingAircraft.getEntityShip() == null)
|
||||
return null;
|
||||
return new ObjectParameters(drawingAircraft.getPosX(), drawingAircraft.getPosY(),
|
||||
drawingAircraft.getWidth(), drawingAircraft.getHeight());
|
||||
}
|
||||
public int getStep(){
|
||||
if(drawingAircraft.getEntityShip() == null)
|
||||
return 0;
|
||||
return drawingAircraft.getEntityShip().step.get().intValue();
|
||||
}
|
||||
public boolean checkCanMove(DirectionType direction){
|
||||
if(drawingAircraft == null)
|
||||
return false;
|
||||
return drawingAircraft.canMove(direction);
|
||||
}
|
||||
public void moveObject(DirectionType direction){
|
||||
drawingAircraft.moveTransport(direction);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class EntityAircraft {
|
||||
private int speed;
|
||||
public int getSpeed(){
|
||||
return speed;
|
||||
}
|
||||
private double weight;
|
||||
public double getWeight(){
|
||||
return weight;
|
||||
}
|
||||
private Color bodyColor;
|
||||
public Color getBodyColor(){
|
||||
return bodyColor;
|
||||
}
|
||||
public Supplier<Double> step = () ->(double) speed * 100 / weight;
|
||||
|
||||
public EntityAircraft(int speed, double weight, Color bodyColor){
|
||||
this.speed = speed;
|
||||
this.weight = weight;
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAircraftCarrier extends EntityAircraft{
|
||||
private Color additionalColor;
|
||||
public Color getAdditionalColor(){
|
||||
return additionalColor;
|
||||
}
|
||||
private boolean Cabin;
|
||||
public boolean getCabin() {
|
||||
return Cabin;
|
||||
}
|
||||
private boolean Runway;
|
||||
public boolean getRunway() {
|
||||
return Runway;
|
||||
}
|
||||
public EntityAircraftCarrier(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, boolean Cabin, boolean Runway) {
|
||||
super(speed, weight, bodyColor);
|
||||
this.additionalColor = additionalColor;
|
||||
this.Cabin = Cabin;
|
||||
this.Runway = Runway;
|
||||
}
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
public class FrameAircraftCarrier extends JFrame {
|
||||
private DrawingAircraft drawingAircraft;
|
||||
private AbstractStrategy abstractStrategy;
|
||||
private JComboBox comboBoxStrategy;
|
||||
private final JComponent pictureBox;
|
||||
public FrameAircraftCarrier() throws IOException {
|
||||
super("Военный корабль");
|
||||
setSize(new Dimension(900,500));
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
pictureBox = new JComponent(){
|
||||
public void paintComponent(Graphics graphics){
|
||||
super.paintComponent(graphics);
|
||||
Graphics2D graphics2D = (Graphics2D) graphics;
|
||||
if (drawingAircraft!= null) drawingAircraft.drawTransport(graphics2D);
|
||||
super.repaint();
|
||||
}
|
||||
};
|
||||
comboBoxStrategy = new JComboBox<>(new String[]{"К центру", "К границе"});
|
||||
JButton stepButton = new JButton("Шаг");
|
||||
JButton createShipButton = new JButton("Создать корабль");
|
||||
JButton createAircraftCarrierButton = new JButton("Создать Военный корабль");
|
||||
JButton rightButton = new JButton(new ImageIcon(ImageIO.read(new File("C:\\Users\\79962\\Desktop\\arrows\\right.png"))));
|
||||
JButton leftButton = new JButton(new ImageIcon(ImageIO.read(new File("C:\\Users\\79962\\Desktop\\arrows\\left.png"))));
|
||||
JButton upButton = new JButton(new ImageIcon(ImageIO.read(new File("C:\\Users\\79962\\Desktop\\arrows\\up.png"))));
|
||||
JButton downButton = new JButton(new ImageIcon(ImageIO.read(new File("C:\\Users\\79962\\Desktop\\arrows\\down.png"))));
|
||||
pictureBox.setBounds( 0, 0, getContentPane().getWidth(), getContentPane().getHeight());
|
||||
createShipButton.addActionListener(e -> buttonCreateShipClick());
|
||||
createAircraftCarrierButton.addActionListener(e -> buttonCreateAircraftCarrierClick());
|
||||
stepButton.addActionListener(e -> buttonStepClick());
|
||||
rightButton.setActionCommand("right");
|
||||
rightButton.addActionListener(this::buttonMoveClick);
|
||||
leftButton.setActionCommand("left");
|
||||
leftButton.addActionListener(this::buttonMoveClick);
|
||||
upButton.setActionCommand("up");
|
||||
upButton.addActionListener(this::buttonMoveClick);
|
||||
downButton.setActionCommand("down");
|
||||
downButton.addActionListener(this::buttonMoveClick);
|
||||
//component addition
|
||||
setLayout(new BorderLayout());
|
||||
JPanel panelAircraftCarrier = new JPanel(new BorderLayout());
|
||||
JPanel rightPanel = new JPanel(new BorderLayout());
|
||||
JPanel leftPanel = new JPanel(new BorderLayout());
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
constraints.insets.left = constraints.insets.top = constraints.insets.bottom = constraints.insets.right = 2;
|
||||
JPanel createPanel = new JPanel(new GridBagLayout());
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
createPanel.add(createShipButton, constraints);
|
||||
constraints.gridx = 1;
|
||||
constraints.gridy = 0;
|
||||
createPanel.add(createAircraftCarrierButton, constraints);
|
||||
JPanel movementPanel = new JPanel(new GridBagLayout());
|
||||
rightButton.setPreferredSize(new Dimension(30,30));
|
||||
constraints.gridx = 2;
|
||||
constraints.gridy = 1;
|
||||
movementPanel.add(rightButton, constraints);
|
||||
leftButton.setPreferredSize(new Dimension(30,30));
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 1;
|
||||
movementPanel.add(leftButton, constraints);
|
||||
upButton.setPreferredSize(new Dimension(30,30));
|
||||
constraints.gridx = 1;
|
||||
constraints.gridy = 0;
|
||||
movementPanel.add(upButton, constraints);
|
||||
downButton.setPreferredSize(new Dimension(30,30));
|
||||
constraints.gridx = 1;
|
||||
constraints.gridy = 1;
|
||||
movementPanel.add(downButton, constraints);
|
||||
JPanel stepPanel = new JPanel(new GridBagLayout());
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
stepPanel.add(comboBoxStrategy, constraints);
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 1;
|
||||
stepPanel.add(stepButton, constraints);
|
||||
add(pictureBox);
|
||||
rightPanel.add(movementPanel, BorderLayout.SOUTH);
|
||||
rightPanel.add(stepPanel, BorderLayout.NORTH);
|
||||
leftPanel.add(createPanel, BorderLayout.SOUTH);
|
||||
panelAircraftCarrier.add(rightPanel, BorderLayout.EAST);
|
||||
panelAircraftCarrier.add(leftPanel, BorderLayout.WEST);
|
||||
add(panelAircraftCarrier,BorderLayout.CENTER);
|
||||
setVisible(true);
|
||||
}
|
||||
private void buttonCreateAircraftCarrierClick() {
|
||||
Random random = new Random();
|
||||
pictureBox.setBounds(0,0,getContentPane().getWidth(),getContentPane().getHeight());
|
||||
drawingAircraft = new DrawingAircraftCarrier(random.nextInt(200) + 100, 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)), random.nextBoolean(), random.nextBoolean(), pictureBox.getWidth(), pictureBox.getHeight(), random.nextInt(3),(random.nextInt(3)+1)*2);
|
||||
drawingAircraft.setPosition(random.nextInt(90) + 10, random.nextInt(90) + 10);
|
||||
draw();
|
||||
}
|
||||
private void buttonCreateShipClick(){
|
||||
Random random = new Random();
|
||||
pictureBox.setBounds(0,0,getContentPane().getWidth(),getContentPane().getHeight());
|
||||
drawingAircraft = new DrawingAircraft(random.nextInt(200) + 100, random.nextInt(2000) + 1000, new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
pictureBox.getWidth(), pictureBox.getHeight(), random.nextInt(3),(random.nextInt(3)+1)*2);
|
||||
drawingAircraft.setPosition(random.nextInt(90) + 10, random.nextInt(90) + 10);
|
||||
draw();
|
||||
}
|
||||
private void buttonStepClick() {
|
||||
if (drawingAircraft == null) {
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
switch(comboBoxStrategy.getSelectedIndex()) {
|
||||
case 0:
|
||||
abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
abstractStrategy = null;
|
||||
break;
|
||||
};
|
||||
if (abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
abstractStrategy.SetData(new DrawingObjectAircraftCarrier(drawingAircraft), pictureBox.getWidth(),
|
||||
pictureBox.getHeight());
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
abstractStrategy.MakeStep();
|
||||
draw();
|
||||
if (abstractStrategy.GetStatus() == Status.FINISH)
|
||||
{
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
private void buttonMoveClick(ActionEvent event) {
|
||||
if(drawingAircraft == null || drawingAircraft.getEntityShip() == null)
|
||||
return;
|
||||
switch (event.getActionCommand())
|
||||
{
|
||||
case "left":
|
||||
drawingAircraft.moveTransport(DirectionType.LEFT);
|
||||
break;
|
||||
case "right":
|
||||
drawingAircraft.moveTransport(DirectionType.RIGHT);
|
||||
break;
|
||||
case "up":
|
||||
drawingAircraft.moveTransport(DirectionType.UP);
|
||||
break;
|
||||
case "down":
|
||||
drawingAircraft.moveTransport(DirectionType.DOWN);
|
||||
break;
|
||||
}
|
||||
draw();
|
||||
}
|
||||
private void draw() {
|
||||
if (drawingAircraft == null)
|
||||
return;
|
||||
pictureBox.repaint();
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawImprovements {
|
||||
public void setNumber(int x);
|
||||
public void drawImprovements(Graphics2D graphics2D, int _startX, int _startY);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters getObjectPosition();
|
||||
int getStep();
|
||||
boolean checkCanMove(DirectionType direction);
|
||||
void moveObject(DirectionType direction);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException{
|
||||
new FrameAircraftCarrier();
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
public class MoveToBorder extends AbstractStrategy{
|
||||
@Override
|
||||
protected boolean IsTargetDestination() {
|
||||
var objParams = getObjectParameters.get();
|
||||
if(objParams == null)
|
||||
return false;
|
||||
return objParams.getRightBorder() + GetStep() >= getFieldWidth() &&
|
||||
objParams.getDownBorder() + GetStep() >= getFieldHeight();
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget() {
|
||||
var objParams = getObjectParameters.get();
|
||||
if(objParams == null)
|
||||
return;
|
||||
var diffX = objParams.getRightBorder() - getFieldWidth();
|
||||
var diffY = objParams.getDownBorder() - getFieldHeight();
|
||||
if(diffX >= 0)
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
else if(diffY >= 0)
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
else if(Math.abs(diffX) > Math.abs(diffY))
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
public class MoveToCenter extends AbstractStrategy{
|
||||
@Override
|
||||
protected boolean IsTargetDestination() {
|
||||
var objParams = getObjectParameters.get();
|
||||
if(objParams == null)
|
||||
return false;
|
||||
return objParams.getObjectMiddleHorizontal() <= getFieldWidth() / 2 &&
|
||||
objParams.getObjectMiddleHorizontal()+GetStep() >= getFieldWidth() / 2 &&
|
||||
objParams.getObjectMiddleVertical() <= getFieldHeight() / 2 &&
|
||||
objParams.getObjectMiddleVertical() + GetStep() >= getFieldHeight() / 2;
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget() {
|
||||
var objParams = getObjectParameters.get();
|
||||
if(objParams == null)
|
||||
return;
|
||||
var diffX = objParams.getObjectMiddleHorizontal() - getFieldWidth() / 2;
|
||||
if(Math.abs(diffX) > GetStep()){
|
||||
if(diffX > 0)
|
||||
MoveLeft();
|
||||
else
|
||||
MoveRight();
|
||||
}
|
||||
var diffY = objParams.getObjectMiddleVertical() - getFieldHeight() / 2;
|
||||
if(Math.abs(diffY) > GetStep()){
|
||||
if(diffY > 0)
|
||||
MoveUp();
|
||||
else
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
public enum NumberImprovement {
|
||||
TWO,
|
||||
FOUR,
|
||||
SIX
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
public class ObjectParameters {
|
||||
private final int _x;
|
||||
private final int _y;
|
||||
private final int _width;
|
||||
private final int _height;
|
||||
public int getLeftBorder() {return _x;}
|
||||
public int getTopBorder() {return _y;}
|
||||
public int getRightBorder() {return _x + _width;}
|
||||
public int getDownBorder() {return _y + _height;}
|
||||
public int getObjectMiddleHorizontal() {return _x + this._width / 2;}
|
||||
public int getObjectMiddleVertical() {return _y + this._height / 2;}
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
public enum Status {
|
||||
NOTINIT,
|
||||
INPROGRESS,
|
||||
FINISH
|
||||
}
|
Loading…
Reference in New Issue
Block a user