PIBD-13_Fomichev_V.S._LabWork02_Hard #2
@ -21,7 +21,7 @@ public class DrawningRollersCircle implements IDifferentRollers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawRoller(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
||||
public void DrawRollers(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(x, y, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
|
@ -21,7 +21,7 @@ public class DrawningRollersHeart implements IDifferentRollers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawPorthole(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
||||
public void DrawRollers(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
||||
int[] HeartX = {x + 2, x, x, x + 1, x + 2, x + 3, x + 5, x + 5};
|
||||
int[] HeartY = {y + 4, y + 2, y, y, y + 1, y, y, y + 2};
|
||||
g.setColor(Color.cyan);
|
||||
|
@ -0,0 +1,30 @@
|
||||
package DrawningRollers;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningRollersSquare implements IDifferentRollers{
|
||||
private CountRollers _roller;
|
||||
|
||||
@Override
|
||||
public void setNumberRollers(int numberofportholes) {
|
||||
for (CountRollers numofenum : CountRollers.values()) {
|
||||
if (numofenum.getCountRollers() == numberofportholes) {
|
||||
_roller = numofenum;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountRollers getNumberOfRollers() {
|
||||
return _roller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawRollers(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(x, y, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(x, y, 3, 3);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package DrawningRollers;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDifferentRollers {
|
||||
void setNumberRollers(int numberofrollers);
|
||||
CountRollers getNumberOfRollers();
|
||||
void DrawRollers(Graphics2D g, int x, int y, int width, int height, Color bodyColor);
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package DrawningRollers;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawningsRollers {
|
||||
void setCountRollers(int numRollers);
|
||||
void DrawRollers(Graphics g, int startPosX, int startPosY);
|
||||
}
|
@ -5,15 +5,15 @@ import Drawnings.DrawningAntiAircraftGun;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class CanvasAntiAircraftGun extends JComponent {
|
||||
public DrawningAntiAircraftGun _drawingAntiAircraftGun;
|
||||
public DrawningArmoredCar _drawingArmoredCar;
|
||||
public CanvasAntiAircraftGun(){}
|
||||
public void paintComponent(Graphics g) {
|
||||
if (_drawingAntiAircraftGun == null) {
|
||||
if (_drawingArmoredCar == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_drawingAntiAircraftGun.DrawTransport(g2d);
|
||||
_drawingArmoredCar.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,26 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.EntityAntiAircraftGun;
|
||||
import Entities.*;
|
||||
import Entities.EntityArmoredCar;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.html.parser.Entity;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
public class DrawningAntiAircraftGun extends DrawningArmoredCar{
|
||||
public DrawningAntiAircraftGun(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isCompartment, boolean isAdditionalEngine) {
|
||||
EntityArmoredCar = new DrawningAntiAircraftGun(speed, weight, bodycolor, additionalcolor, isCompartment, isAdditionalEngine);
|
||||
SetAmountAndTypePortholes();
|
||||
public DrawningAntiAircraftGun(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isTower, boolean isRadar) {
|
||||
EntityArmoredCar = new EntityAntiAircraftGun(speed, weight, bodycolor, additionalcolor, isTower, isRadar);
|
||||
SetAmountAndTypeRollers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g) {
|
||||
|
||||
_rollers.DrawRollers(g,_StartPosX, _StartPosY);
|
||||
if (EntityArmoredCar == null || !(EntityArmoredCar instanceof EntityAntiAircraftGun AntiAircraftGun)
|
||||
|| _StartPosX == null || _StartPosY == null)
|
||||
return;
|
||||
g.setColor(Color.BLACK);
|
||||
super.DrawTransport(g);
|
||||
//отрисовки башни
|
||||
if (EntityAntiAircraftGun.getIsTower())
|
||||
{
|
||||
|
@ -1,21 +1,25 @@
|
||||
package Drawnings;
|
||||
|
||||
import DrawningRollers.DrawningRollers;
|
||||
import Entities.EntityArmoredCar;
|
||||
import DrawningRollers.*;
|
||||
import Entities.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningArmoredCar extends JPanel {
|
||||
public Entities.EntityAntiAircraftGun EntityAntiAircraftGun;
|
||||
public DrawningRollers _rollers = null;
|
||||
public Entities.EntityArmoredCar EntityArmoredCar;
|
||||
public IDifferentRollers drawningRollers;
|
||||
private Integer picture_width;
|
||||
private Integer picture_height;
|
||||
private Integer _StartPosX;
|
||||
private Integer _StartPosY;
|
||||
private int drawningCarWidth = 120;
|
||||
private int drawningCarHeight = 90;
|
||||
protected Integer _StartPosX;
|
||||
public Integer GetPosX() {return _StartPosX;}
|
||||
protected Integer _StartPosY;
|
||||
public Integer GetPosY() {return _StartPosY;}
|
||||
protected int drawningCarWidth = 120;
|
||||
public Integer GetWidth() {return drawningCarWidth;}
|
||||
protected int drawningCarHeight = 90;
|
||||
public Integer GetHeight() {return drawningCarHeight;}
|
||||
protected DrawningArmoredCar() {
|
||||
picture_width = null;
|
||||
picture_height = null;
|
||||
@ -23,29 +27,29 @@ public class DrawningArmoredCar extends JPanel {
|
||||
_StartPosY = null;
|
||||
}
|
||||
|
||||
protected void SetAmountAndTypePortholes() {
|
||||
protected void SetAmountAndTypeRollers() {
|
||||
Random random = new Random();
|
||||
int numberofportholes = random.nextInt(0,3);
|
||||
switch (numberofportholes) {
|
||||
int numberofrollers = random.nextInt(0,3);
|
||||
switch (numberofrollers) {
|
||||
case 1:
|
||||
drawingPortholes = new DrawingPortholesCircle();
|
||||
drawningRollers = new DrawningRollersCircle();
|
||||
break;
|
||||
case 2:
|
||||
drawingPortholes = new DrawingPortholesSquare();
|
||||
drawningRollers = new DrawningRollersSquare();
|
||||
break;
|
||||
case 3:
|
||||
drawingPortholes = new DrawingPortholesHeart();
|
||||
drawningRollers = new DrawningRollersHeart();
|
||||
break;
|
||||
default:
|
||||
numberofportholes = 0;
|
||||
numberofrollers = 0;
|
||||
break;
|
||||
}
|
||||
drawingPortholes.setNumberPortholes(numberofportholes);
|
||||
drawningRollers.setNumberRollers(numberofrollers);
|
||||
}
|
||||
public DrawningArmoredCar(int speed, double weight, Color bodycolor) {
|
||||
super();
|
||||
EntityArmoredCar = new EntityArmoredCar(speed, weight, bodycolor);
|
||||
SetAmountAndTypePortholes();
|
||||
SetAmountAndTypeRollers();
|
||||
}
|
||||
public boolean SetPictureSize(int width, int height) {
|
||||
if (width < drawningCarWidth || height < drawningCarHeight) return false;
|
||||
@ -83,27 +87,27 @@ public class DrawningArmoredCar extends JPanel {
|
||||
public boolean MoveTransport(DirectionType direction) {
|
||||
if (EntityArmoredCar == null || _StartPosX == null || _StartPosY == null) return false;
|
||||
switch (direction) {
|
||||
case DirectionType.Left:
|
||||
if (_StartPosX - EntityAntiAircraftGun.Step > 0) {
|
||||
_StartPosX -= (int)EntityAntiAircraftGun.Step;
|
||||
case Left:
|
||||
if (_StartPosX - EntityArmoredCar.Step > 0) {
|
||||
_StartPosX -= (int)EntityArmoredCar.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Up:
|
||||
if (_StartPosY - EntityAntiAircraftGun.Step > 0)
|
||||
case Up:
|
||||
if (_StartPosY - EntityArmoredCar.Step > 0)
|
||||
{
|
||||
_StartPosY -= (int)EntityAntiAircraftGun.Step;
|
||||
_StartPosY -= (int)EntityArmoredCar.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Right:
|
||||
if (_StartPosX + drawningCarWidth + (int)EntityAntiAircraftGun.Step < picture_width - EntityAntiAircraftGun.Step)
|
||||
case Right:
|
||||
if (_StartPosX + drawningCarWidth + (int)EntityArmoredCar.Step < picture_width - EntityArmoredCar.Step)
|
||||
{
|
||||
_StartPosX += (int)EntityAntiAircraftGun.Step;
|
||||
_StartPosX += (int)EntityArmoredCar.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Down:
|
||||
if (_StartPosY + drawningCarHeight + (int)EntityAntiAircraftGun.Step < picture_height - EntityAntiAircraftGun.Step)
|
||||
case Down:
|
||||
if (_StartPosY + drawningCarHeight + (int)EntityArmoredCar.Step < picture_height - EntityArmoredCar.Step)
|
||||
{
|
||||
_StartPosY += (int)EntityAntiAircraftGun.Step;
|
||||
_StartPosY += (int)EntityArmoredCar.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -112,7 +116,7 @@ public class DrawningArmoredCar extends JPanel {
|
||||
}
|
||||
public void DrawTransport(Graphics2D g) {
|
||||
|
||||
if (EntityAntiAircraftGun == null ) {
|
||||
if (EntityArmoredCar == null ) {
|
||||
return;
|
||||
}
|
||||
;
|
||||
|
@ -1,19 +1,19 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
public class EntityAntiAircraftGun {
|
||||
public class EntityAntiAircraftGun extends EntityArmoredCar{
|
||||
private static Color AdditionalColor;
|
||||
public static Color getAdditionalColor() {return AdditionalColor;}
|
||||
private static boolean IsCompartment;
|
||||
public static boolean getIsCompartment() {return IsCompartment;}
|
||||
private static boolean IsAdditionalEngine;
|
||||
public static boolean getIsAdditionalEngine() {return IsAdditionalEngine;}
|
||||
private static boolean IsTower;
|
||||
public static boolean getIsTower() {return IsTower;}
|
||||
private static boolean IsRadar;
|
||||
public static boolean getIsRadar() {return IsRadar;}
|
||||
|
||||
public EntityAntiAircraftGun(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isCompartment, boolean isAdditionalEngine)
|
||||
public EntityAntiAircraftGun(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isTower, boolean isRadar)
|
||||
{
|
||||
super(speed,weight,bodycolor);
|
||||
AdditionalColor = additionalcolor;
|
||||
IsCompartment = isCompartment;
|
||||
IsAdditionalEngine = isAdditionalEngine;
|
||||
IsTower = isTower;
|
||||
IsRadar = isRadar;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import Drawnings.CanvasAntiAircraftGun;
|
||||
import Drawnings.DirectionType;
|
||||
import Drawnings.DrawningAntiAircraftGun;
|
||||
import Drawnings.DrawningArmoredCar;
|
||||
import MovementStrategy.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -15,23 +17,55 @@ public class FormAntiAircraftGun extends JFrame {
|
||||
private Dimension dimension;
|
||||
private int Width, Height;
|
||||
private CanvasAntiAircraftGun canvasAntiAircraftGun = new CanvasAntiAircraftGun();
|
||||
private JButton CreateButton = new JButton("Создать");;
|
||||
private JButton CreateButton = new JButton("Создать зенитную установку");;
|
||||
private JButton CreateArmoredCarButton = new JButton("Создать бронированную машину");
|
||||
private JButton UpButton = new JButton();
|
||||
private JButton DownButton = new JButton();;
|
||||
private JButton LeftButton = new JButton();;
|
||||
private JButton RightButton = new JButton();
|
||||
private AbstractStrategy _strategy;
|
||||
private JComboBox ComboBoxStrategy = new JComboBox(new String[]{"К центру", "К краю"});
|
||||
private JButton ButtonStrategy = new JButton("Шаг");
|
||||
public FormAntiAircraftGun(String title, Dimension dimension) {
|
||||
this.title = title;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
private void CreateObject(String typeOfClass) {
|
||||
int StartPositionX = (int)(Math.random() * 90 + 10);
|
||||
int StartPositionY = (int)(Math.random() * 90 + 10);
|
||||
int speed = (int)(Math.random() * 300 + 100);
|
||||
double weight = (double)(Math.random() * 3000 + 1000);
|
||||
Color bodyColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));
|
||||
switch (typeOfClass) {
|
||||
case "DrawningArmoredCar":
|
||||
canvasAntiAircraftGun._drawingArmoredCar = new DrawningArmoredCar(speed, weight, bodyColor);
|
||||
canvasAntiAircraftGun._drawingArmoredCar.SetPictureSize(Width, Height);
|
||||
canvasAntiAircraftGun._drawingArmoredCar.SetPosition(StartPositionX, StartPositionY);
|
||||
canvasAntiAircraftGun.repaint();
|
||||
break;
|
||||
case "DrawningAntiAircraftGun":
|
||||
Color additionalColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));;
|
||||
boolean IsCompartment = new Random().nextBoolean();
|
||||
boolean isAdditionalEngine = new Random().nextBoolean();;
|
||||
canvasAntiAircraftGun._drawingArmoredCar = new DrawningAntiAircraftGun(speed, weight, bodyColor, additionalColor, IsCompartment , isAdditionalEngine);
|
||||
canvasAntiAircraftGun._drawingArmoredCar.SetPictureSize(Width, Height);
|
||||
canvasAntiAircraftGun._drawingArmoredCar.SetPosition(StartPositionX, StartPositionY);
|
||||
canvasAntiAircraftGun.repaint();
|
||||
break;
|
||||
default: return;
|
||||
}
|
||||
_strategy = null;
|
||||
ComboBoxStrategy.setEnabled(true);
|
||||
}
|
||||
public void Init() {
|
||||
setTitle(title);
|
||||
setMinimumSize(dimension);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Width = getWidth() - 15;
|
||||
Height = getHeight() - 35;
|
||||
|
||||
_strategy = null;
|
||||
CreateButton.setName("CREATE");
|
||||
CreateArmoredCarButton.setName("CREATE ARMORED CAR BUTTON");
|
||||
Icon iconUp = new ImageIcon("src/images/up.jpg");
|
||||
UpButton.setIcon(iconUp);
|
||||
UpButton.setName("UP");
|
||||
@ -48,39 +82,72 @@ public class FormAntiAircraftGun extends JFrame {
|
||||
CreateButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int StartPositionX = (int)(Math.random() * 90 + 10);
|
||||
int StartPositionY = (int)(Math.random() * 90 + 10);
|
||||
int speed = (int)(Math.random() * 300 + 100);
|
||||
double weight = (double)(Math.random() * 3000 + 1000);
|
||||
Color bodyColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));
|
||||
Color additionalColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));;
|
||||
boolean tower = new Random().nextBoolean();
|
||||
boolean radar = new Random().nextBoolean();;
|
||||
canvasAntiAircraftGun._drawingAntiAircraftGun = new DrawningAntiAircraftGun();
|
||||
canvasAntiAircraftGun._drawingAntiAircraftGun.Init(speed, weight, bodyColor, additionalColor, tower, radar);
|
||||
canvasAntiAircraftGun._drawingAntiAircraftGun.SetPictureSize(Width, Height);
|
||||
canvasAntiAircraftGun._drawingAntiAircraftGun.SetPosition( StartPositionX, StartPositionY);
|
||||
canvasAntiAircraftGun.repaint();
|
||||
CreateObject("DrawningArmoredCar");
|
||||
}
|
||||
});
|
||||
|
||||
CreateArmoredCarButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CreateObject("DrawningAntiAircraftGun");
|
||||
}
|
||||
});
|
||||
ButtonStrategy.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (canvasAntiAircraftGun._drawingArmoredCar == null) return;
|
||||
if (ComboBoxStrategy.isEnabled())
|
||||
{
|
||||
int index = ComboBoxStrategy.getSelectedIndex();
|
||||
switch(index)
|
||||
{
|
||||
case 0:
|
||||
_strategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_strategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
_strategy = null;
|
||||
break;
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableArmoredCar(canvasAntiAircraftGun._drawingArmoredCar), Width, Height);
|
||||
}
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComboBoxStrategy.setEnabled(false);
|
||||
_strategy.MakeStep();
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
ComboBoxStrategy.setEnabled(true);
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ActionListener actionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
if (canvasAntiAircraftGun._drawingAntiAircraftGun == null) return;
|
||||
if (canvasAntiAircraftGun._drawingArmoredCar == null) return;
|
||||
boolean result = false;
|
||||
switch ((((JButton)(event.getSource())).getName())) {
|
||||
case "UP":
|
||||
result = canvasAntiAircraftGun._drawingAntiAircraftGun.MoveTransport(DirectionType.Up);
|
||||
result = canvasAntiAircraftGun._drawingArmoredCar.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "DOWN":
|
||||
result = canvasAntiAircraftGun._drawingAntiAircraftGun.MoveTransport(DirectionType.Down);
|
||||
result = canvasAntiAircraftGun._drawingArmoredCar.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "LEFT":
|
||||
result = canvasAntiAircraftGun._drawingAntiAircraftGun.MoveTransport(DirectionType.Left);
|
||||
result = canvasAntiAircraftGun._drawingArmoredCar.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "RIGHT":
|
||||
result = canvasAntiAircraftGun._drawingAntiAircraftGun.MoveTransport(DirectionType.Right);
|
||||
result = canvasAntiAircraftGun._drawingArmoredCar.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result) {
|
||||
@ -96,16 +163,22 @@ public class FormAntiAircraftGun extends JFrame {
|
||||
setSize(dimension.width,dimension.height);
|
||||
setLayout(null);
|
||||
canvasAntiAircraftGun.setBounds(0,0, getWidth(), getHeight());
|
||||
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
||||
CreateButton.setBounds(10, getHeight() - 90, 125, 40);
|
||||
CreateArmoredCarButton.setBounds(160, getHeight() - 90, 125, 40);
|
||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
||||
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
||||
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
||||
ComboBoxStrategy.setBounds(getWidth() - 170, 10, 140, 35);
|
||||
ButtonStrategy.setBounds(getWidth() - 130, 55, 100, 25);
|
||||
add(CreateButton);
|
||||
add(CreateArmoredCarButton);
|
||||
add(UpButton);
|
||||
add(DownButton);
|
||||
add(RightButton);
|
||||
add(LeftButton);
|
||||
add(ComboBoxStrategy);
|
||||
add(ButtonStrategy);
|
||||
add(canvasAntiAircraftGun);
|
||||
setVisible(true);
|
||||
//обработка события изменения размеров окна
|
||||
@ -113,8 +186,8 @@ public class FormAntiAircraftGun extends JFrame {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Width = getWidth() - 15;
|
||||
Height = getHeight() - 35;
|
||||
if (canvasAntiAircraftGun._drawingAntiAircraftGun != null)
|
||||
canvasAntiAircraftGun._drawingAntiAircraftGun.SetPictureSize(Width, Height);
|
||||
if (canvasAntiAircraftGun._drawingArmoredCar != null)
|
||||
canvasAntiAircraftGun._drawingArmoredCar.SetPictureSize(Width, Height);
|
||||
canvasAntiAircraftGun.setBounds(0,0, getWidth(), getHeight());
|
||||
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
||||
|
@ -7,37 +7,37 @@ public class MoveableArmoredCar implements IMoveableObject{
|
||||
private CanvasAntiAircraftGun canvas = new CanvasAntiAircraftGun();
|
||||
public MoveableArmoredCar(DrawningArmoredCar drawningairplan)
|
||||
{
|
||||
canvas._drawingAirplan = drawningairplan;
|
||||
canvas._drawingArmoredCar = drawningairplan;
|
||||
}
|
||||
@Override
|
||||
public ObjectParameters GetObjectPosition() {
|
||||
if (canvas._drawingAirplan == null || canvas._drawingAirplan.EntityAirplan == null ||
|
||||
canvas._drawingAirplan.GetPosX() == null || canvas._drawingAirplan.GetPosY() == null)
|
||||
if (canvas._drawingArmoredCar == null || canvas._drawingArmoredCar.EntityArmoredCar == null ||
|
||||
canvas._drawingArmoredCar.GetPosX() == null || canvas._drawingArmoredCar.GetPosY() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(canvas._drawingAirplan.GetPosX(), canvas._drawingAirplan.GetPosY(),
|
||||
canvas._drawingAirplan.GetWidth(), canvas._drawingAirplan.GetHeight());
|
||||
return new ObjectParameters(canvas._drawingArmoredCar.GetPosX(), canvas._drawingArmoredCar.GetPosY(),
|
||||
canvas._drawingArmoredCar.GetWidth(), canvas._drawingArmoredCar.GetHeight());
|
||||
}
|
||||
@Override
|
||||
public int GetStep() {
|
||||
return (int)(canvas._drawingAirplan.EntityAirplan.Step);
|
||||
return (int)(canvas._drawingArmoredCar.EntityArmoredCar.Step);
|
||||
}
|
||||
@Override
|
||||
public boolean TryMoveObject(MovementDirection direction) {
|
||||
if (canvas._drawingAirplan == null || canvas._drawingAirplan.EntityAirplan == null)
|
||||
if (canvas._drawingArmoredCar == null || canvas._drawingArmoredCar.EntityArmoredCar == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return canvas._drawingAirplan.MoveTransport(GetDirectionType(direction));
|
||||
return canvas._drawingArmoredCar.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
switch (direction) {
|
||||
case MovementDirection.Left: return DirectionType.Left;
|
||||
case MovementDirection.Right: return DirectionType.Right;
|
||||
case MovementDirection.Up: return DirectionType.Up;
|
||||
case MovementDirection.Down: return DirectionType.Down;
|
||||
case Left: return DirectionType.Left;
|
||||
case Right: return DirectionType.Right;
|
||||
case Up: return DirectionType.Up;
|
||||
case Down: return DirectionType.Down;
|
||||
default: return DirectionType.Unknown;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user