Лабораторная работа 02
This commit is contained in:
parent
ca418658ac
commit
ca0c850f7c
@ -1,65 +0,0 @@
|
|||||||
package ChoiseAndDrawingPortholes;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class DrawingPortholes {
|
|
||||||
private CountPortholes _porthole;
|
|
||||||
|
|
||||||
public CountPortholes getCount() {
|
|
||||||
return _porthole;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetCount(int count) {
|
|
||||||
switch (count) {
|
|
||||||
case 1: // 10
|
|
||||||
_porthole = CountPortholes.TenPortholes;
|
|
||||||
break;
|
|
||||||
case 2: // 20
|
|
||||||
_porthole = CountPortholes.TwentyPortholes;
|
|
||||||
break;
|
|
||||||
case 3: // 30
|
|
||||||
_porthole = CountPortholes.ThirtyPortholes;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
_porthole = CountPortholes.TenPortholes;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(Graphics2D g, int _startPosx, int _startPoxY) {
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
if (_porthole == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 10; ++i) {
|
|
||||||
g.setColor(Color.cyan);
|
|
||||||
g.fillOval(_startPosx + 19 + i * 8, _startPoxY + 21, 3, 3);
|
|
||||||
g.setColor(Color.black);
|
|
||||||
g.drawOval(_startPosx + 19 + i * 8, _startPoxY + 21, 3, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_porthole != CountPortholes.TenPortholes) {
|
|
||||||
for (int i = 0; i < 5; ++i) {
|
|
||||||
g.setColor(Color.cyan);
|
|
||||||
g.fillOval(_startPosx - 15 + i * 5, _startPoxY + 28, 3, 3);
|
|
||||||
g.setColor(Color.black);
|
|
||||||
g.drawOval(_startPosx - 15 + i * 5, _startPoxY + 28, 3, 3);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 5; ++i) {
|
|
||||||
g.setColor(Color.cyan);
|
|
||||||
g.fillOval(_startPosx + 115 + i * 5, _startPoxY + 28, 3, 3);
|
|
||||||
g.setColor(Color.black);
|
|
||||||
g.drawOval(_startPosx + 115 + i * 5, _startPoxY + 28, 3, 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (_porthole == CountPortholes.ThirtyPortholes) {
|
|
||||||
for (int i = 0; i < 10; ++i) {
|
|
||||||
g.setColor(Color.cyan);
|
|
||||||
g.fillOval(_startPosx + 19 + i * 8, _startPoxY + 37, 3, 3);
|
|
||||||
g.setColor(Color.black);
|
|
||||||
g.drawOval(_startPosx + 19 + i * 8, _startPoxY + 37, 3, 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,26 +6,52 @@ import Entities.*;
|
|||||||
public class DrawingPortholesCircle implements IDifferentPortholes {
|
public class DrawingPortholesCircle implements IDifferentPortholes {
|
||||||
private CountPortholes _porthole;
|
private CountPortholes _porthole;
|
||||||
|
|
||||||
@Override
|
public CountPortholes getCount() {
|
||||||
public void setNumberPortholes(int numberofportholes) {
|
|
||||||
for (CountPortholes numofenum : CountPortholes.values()) {
|
|
||||||
if (numofenum.getNumportholes() == numberofportholes) {
|
|
||||||
_porthole = numofenum;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CountPortholes getNumberOfPortholes() {
|
|
||||||
return _porthole;
|
return _porthole;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void SetCount(int count) {
|
||||||
public void DrawPorthole(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
switch (count) {
|
||||||
|
case 10:
|
||||||
|
_porthole = CountPortholes.TenPortholes;
|
||||||
|
break;
|
||||||
|
case 20:
|
||||||
|
_porthole = CountPortholes.TwentyPortholes;
|
||||||
|
break;
|
||||||
|
case 30:
|
||||||
|
_porthole = CountPortholes.ThirtyPortholes;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_porthole = CountPortholes.TenPortholes;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void drawPortholes(Graphics2D g, int posX, int posY) {
|
||||||
g.setColor(Color.cyan);
|
g.setColor(Color.cyan);
|
||||||
g.fillOval(x, y, 3, 3);
|
g.fillOval(posX, posY, 3, 3);
|
||||||
g.setColor(Color.black);
|
g.setColor(Color.black);
|
||||||
g.drawOval(x, y, 3, 3);
|
g.drawOval(posX, posY, 3, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(Graphics2D g, int _startPosX, int _startPosY) {
|
||||||
|
if (_porthole == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
drawPortholes(g, _startPosX + 19 + i * 8, _startPosY + 21);
|
||||||
|
}
|
||||||
|
if (_porthole != CountPortholes.TenPortholes) {
|
||||||
|
for (int i = 0; i < 5; ++i) {
|
||||||
|
drawPortholes(g, _startPosX - 15 + i * 5, _startPosY + 28);
|
||||||
|
drawPortholes(g, _startPosX + 115 + i * 5, _startPosY + 28);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_porthole == CountPortholes.ThirtyPortholes) {
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
drawPortholes(g, _startPosX + 19 + i * 8, _startPosY + 37);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,32 +2,13 @@ package ChoiseAndDrawingPortholes;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingPortholesHeart implements IDifferentPortholes {
|
public class DrawingPortholesHeart extends DrawingPortholesCircle {
|
||||||
private CountPortholes _porthole;
|
protected void drawPortholes(Graphics2D g, int posX, int posY) {
|
||||||
|
int[] HeartX = {posX + 2, posX, posX, posX + 1, posX + 2, posX + 3, posX + 5, posX + 5};
|
||||||
@Override
|
int[] HeartY = {posY + 4, posY + 2, posY, posY, posY + 1, posY, posY, posY + 2};
|
||||||
public void setNumberPortholes(int numberofportholes) {
|
|
||||||
for (CountPortholes numofenum : CountPortholes.values()) {
|
|
||||||
if (numofenum.getNumportholes() == numberofportholes) {
|
|
||||||
_porthole = numofenum;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CountPortholes getNumberOfPortholes() {
|
|
||||||
return _porthole;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void DrawPorthole(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);
|
g.setColor(Color.cyan);
|
||||||
g.fillPolygon(HeartX, HeartY, HeartX.length);
|
g.fillPolygon(HeartX, HeartY, HeartX.length);
|
||||||
g.setColor(Color.black);
|
g.setColor(Color.black);
|
||||||
g.drawPolygon(HeartX, HeartY, HeartX.length);
|
g.drawPolygon(HeartX, HeartY, HeartX.length);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,29 +2,11 @@ package ChoiseAndDrawingPortholes;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingPortholesSquare implements IDifferentPortholes {
|
public class DrawingPortholesSquare extends DrawingPortholesCircle {
|
||||||
private CountPortholes _porthole;
|
protected void drawPortholes(Graphics2D g, int posX, int posY){
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setNumberPortholes(int numberofportholes) {
|
|
||||||
for (CountPortholes numofenum : CountPortholes.values()) {
|
|
||||||
if (numofenum.getNumportholes() == numberofportholes) {
|
|
||||||
_porthole = numofenum;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CountPortholes getNumberOfPortholes() {
|
|
||||||
return _porthole;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void DrawPorthole(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
|
||||||
g.setColor(Color.cyan);
|
g.setColor(Color.cyan);
|
||||||
g.fillRect(x, y, 3, 3);
|
g.fillRect(posX, posY, 3, 3);
|
||||||
g.setColor(Color.black);
|
g.setColor(Color.black);
|
||||||
g.drawRect(x, y, 3, 3);
|
g.drawRect(posX, posY, 3, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package ChoiseAndDrawingPortholes;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public interface IDifferentPortholes {
|
public interface IDifferentPortholes {
|
||||||
void setNumberPortholes(int numberofportholes);
|
public CountPortholes getCount();
|
||||||
CountPortholes getNumberOfPortholes();
|
public void SetCount (int count);
|
||||||
void DrawPorthole(Graphics2D g, int x, int y, int width, int height, Color bodyColor);
|
public void Draw (Graphics2D g, int _startPosX, int _startPoxY);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package Drawings;
|
|
||||||
|
|
||||||
public enum DirectionType {
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
Unknown
|
|
||||||
}
|
|
@ -1,38 +1,40 @@
|
|||||||
package Drawings;
|
package Drawings;
|
||||||
|
|
||||||
import Entities.*;
|
import Drawings.DrawingAirplan;
|
||||||
|
import Entities.EntityAirbus;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingAirbus extends DrawingAirplan {
|
public class DrawingAirbus extends DrawingAirplan {
|
||||||
|
|
||||||
public DrawingAirbus(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isCompartment, boolean isAdditionalEngine) {
|
public DrawingAirbus(int speed, int weight, Color bodyColor, int countPortholes, Color additionalColor, boolean isCompartment, boolean isAdditionalEngine, int width, int height) {
|
||||||
EntityAirplan = new EntityAirbus(speed, weight, bodycolor, additionalcolor, isCompartment, isAdditionalEngine);
|
super(speed, weight, bodyColor, countPortholes, width, height);
|
||||||
SetAmountAndTypePortholes();
|
if (entityAirplan != null) {
|
||||||
|
entityAirplan = new EntityAirbus(speed, weight, bodyColor, additionalColor, isCompartment, isAdditionalEngine);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void DrawTransport(Graphics2D g) {
|
public void DrawTransport(Graphics2D g) {
|
||||||
|
|
||||||
if (EntityAirplan == null || !(EntityAirplan instanceof EntityAirbus airbus)
|
if (entityAirplan == null) {
|
||||||
|| _StartPosX == null || _StartPosY == null)
|
|
||||||
return;
|
return;
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
super.DrawTransport(g);
|
|
||||||
|
|
||||||
//Пассажирсакий доп. отсек
|
|
||||||
if (EntityAirbus.getIsCompartment())
|
|
||||||
{
|
|
||||||
g.setColor(EntityAirbus.getAdditionalColor());
|
|
||||||
g.drawArc(_StartPosX + 60, _StartPosY + 28, 115, 45, 0, 180);
|
|
||||||
g.fillArc(_StartPosX + 60, _StartPosY + 28, 115, 45, 0, 180);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Color additionalColor = ((EntityAirbus) entityAirplan).getAdditionalColor();
|
||||||
|
//Пассажирсакий доп. отсек
|
||||||
|
if (((EntityAirbus) entityAirplan).IsCompartment()) {
|
||||||
|
g.setColor(additionalColor);
|
||||||
|
g.drawArc(_startPosX + 60, _startPosY + 28, 115, 45, 0, 180);
|
||||||
|
g.fillArc(_startPosX + 60, _startPosY + 28, 115, 45, 0, 180);
|
||||||
|
}
|
||||||
|
super.DrawTransport(g);
|
||||||
// Доп. двигатели
|
// Доп. двигатели
|
||||||
if (EntityAirbus.getIsAdditionalEngine())
|
if (((EntityAirbus) entityAirplan).IsAdditionalEngine()) {
|
||||||
{
|
g.drawLine(_startPosX + 95, _startPosY + 68, _startPosX + 95, _startPosY + 75);
|
||||||
g.drawLine(_StartPosX + 95, _StartPosY + 68, _StartPosX + 95, _StartPosY + 75);
|
g.setColor(additionalColor);
|
||||||
g.setColor(EntityAirbus.getAdditionalColor());
|
int[] xPolygon = {_startPosX + 83, _startPosX + 103, _startPosX + 103, _startPosX + 83, _startPosX + 83};
|
||||||
int[] xPolygon = { _StartPosX + 83, _StartPosX + 103, _StartPosX + 103, _StartPosX + 83, _StartPosX + 83};
|
int[] yPolygon = {_startPosY + 78, _startPosY + 73, _startPosY + 93, _startPosY + 88, _startPosY + 78};
|
||||||
int[] yPolygon = {_StartPosY + 78, _StartPosY + 73, _StartPosY + 93, _StartPosY + 88, _StartPosY + 78};
|
|
||||||
g.drawPolygon(xPolygon, yPolygon, xPolygon.length);
|
g.drawPolygon(xPolygon, yPolygon, xPolygon.length);
|
||||||
g.fillPolygon(xPolygon, yPolygon, xPolygon.length);
|
g.fillPolygon(xPolygon, yPolygon, xPolygon.length);
|
||||||
}
|
}
|
||||||
|
@ -2,155 +2,166 @@ package Drawings;
|
|||||||
|
|
||||||
import Entities.*;
|
import Entities.*;
|
||||||
import ChoiseAndDrawingPortholes.*;
|
import ChoiseAndDrawingPortholes.*;
|
||||||
|
import MovementStrategy.Direction;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DrawingAirplan extends JPanel {
|
public class DrawingAirplan {
|
||||||
public Entities.EntityAirplan EntityAirplan;
|
|
||||||
public IDifferentPortholes drawingPortholes;
|
|
||||||
private Integer picture_width;
|
|
||||||
private Integer picture_height;
|
|
||||||
protected Integer _StartPosX;
|
|
||||||
public Integer GetPosX() {return _StartPosX;}
|
|
||||||
protected Integer _StartPosY;
|
|
||||||
public Integer GetPosY() {return _StartPosY;}
|
|
||||||
protected int drawingAirplanWidth = 190;
|
|
||||||
public Integer GetWidth() {return drawingAirplanWidth;}
|
|
||||||
protected int drawingAirplanHeight = 100;
|
|
||||||
public Integer GetHeight() {return drawingAirplanHeight;}
|
|
||||||
|
|
||||||
protected DrawingAirplan() {
|
public EntityAirplan entityAirplan;
|
||||||
picture_width = null;
|
public IDifferentPortholes _portholes;
|
||||||
picture_height = null;
|
private int _pictureWidth;
|
||||||
_StartPosX = null;
|
private int _pictureHeight;
|
||||||
_StartPosY = null;
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
|
private int _airbusWidth = 210;
|
||||||
|
private int _airbusHeight = 100;
|
||||||
|
|
||||||
|
public int GetPosX() {
|
||||||
|
return _startPosX;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetAmountAndTypePortholes() {
|
public int GetPosY() {
|
||||||
|
return _startPosY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetWidth() {
|
||||||
|
return _airbusWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHeight() {
|
||||||
|
return _airbusHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingAirplan(int speed, float weight, Color bodyColor, int countPortholes, int width, int height) {
|
||||||
|
if (width < _airbusHeight || height < _airbusWidth)
|
||||||
|
return;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
entityAirplan = new EntityAirplan(speed, weight, bodyColor);
|
||||||
|
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
int numberofportholes = random.nextInt(0,3);
|
switch (random.nextInt(0, 3)) {
|
||||||
switch (numberofportholes) {
|
case 0:
|
||||||
|
_portholes = new DrawingPortholesCircle();
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
drawingPortholes = new DrawingPortholesCircle();
|
_portholes = new DrawingPortholesHeart();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
drawingPortholes = new DrawingPortholesSquare();
|
_portholes = new DrawingPortholesSquare();
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
drawingPortholes = new DrawingPortholesHeart();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
numberofportholes = 0;
|
_portholes = new DrawingPortholesCircle();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
drawingPortholes.setNumberPortholes(numberofportholes);
|
_portholes.SetCount(countPortholes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DrawingAirplan(int speed, double weight, Color bodycolor) {
|
|
||||||
super();
|
|
||||||
EntityAirplan = new EntityAirplan(speed, weight, bodycolor);
|
|
||||||
SetAmountAndTypePortholes();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean SetPictureSize(int width, int height) {
|
|
||||||
if (width < drawingAirplanWidth || height < drawingAirplanHeight) return false;
|
|
||||||
picture_width = width;
|
|
||||||
picture_height = height;
|
|
||||||
if (_StartPosX != null || _StartPosY != null) {
|
|
||||||
if (_StartPosX + drawingAirplanWidth > picture_width)
|
|
||||||
{
|
|
||||||
_StartPosX = _StartPosX - (_StartPosX + drawingAirplanWidth - picture_width);
|
|
||||||
}
|
|
||||||
else if (_StartPosX < 0) _StartPosX = 0;
|
|
||||||
if (_StartPosY + drawingAirplanHeight > picture_height)
|
|
||||||
{
|
|
||||||
_StartPosY = _StartPosY - (_StartPosY + drawingAirplanHeight - picture_height);
|
|
||||||
}
|
|
||||||
else if (_StartPosY < 0) _StartPosY = 0;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public void SetPosition(int x, int y) {
|
public void SetPosition(int x, int y) {
|
||||||
if (!(picture_width != null && picture_height != null)) return;
|
if (x > _pictureWidth || y > _pictureHeight || x < 0 || y < 0) {
|
||||||
if (x + drawingAirplanWidth > picture_width)
|
_startPosX = 0;
|
||||||
{
|
_startPosY = 0;
|
||||||
_StartPosX = x - (x + drawingAirplanWidth - picture_width);
|
} else {
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
else if (x < 0) _StartPosX = 0;
|
|
||||||
else _StartPosX = x;
|
|
||||||
if (y + drawingAirplanHeight > picture_height)
|
|
||||||
{
|
|
||||||
_StartPosY = y - (y + drawingAirplanHeight - picture_height);
|
|
||||||
}
|
|
||||||
else if (y < 0) _StartPosY = 0;
|
|
||||||
else _StartPosY = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean MoveTransport(DirectionType direction) {
|
public boolean CanMove(Direction direction) {
|
||||||
if (EntityAirplan == null || _StartPosX == null || _StartPosY == null) return false;
|
if (entityAirplan == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case DirectionType.Left:
|
case Left:
|
||||||
if (_StartPosX - EntityAirplan.Step > 0) {
|
return _startPosX - entityAirplan.Step > 5;
|
||||||
_StartPosX -= (int)EntityAirplan.Step;
|
case Right:
|
||||||
}
|
return _startPosX + _airbusWidth + entityAirplan.Step < _pictureWidth;
|
||||||
return true;
|
case Up:
|
||||||
case DirectionType.Up:
|
return _startPosY - entityAirplan.Step > 0;
|
||||||
if (_StartPosY - EntityAirplan.Step > 0)
|
case Down:
|
||||||
{
|
return _startPosY + _airbusHeight + entityAirplan.Step < _pictureHeight;
|
||||||
_StartPosY -= (int)EntityAirplan.Step;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case DirectionType.Right:
|
|
||||||
if (_StartPosX + drawingAirplanWidth + (int)EntityAirplan.Step < picture_width - EntityAirplan.Step)
|
|
||||||
{
|
|
||||||
_StartPosX += (int)EntityAirplan.Step;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case DirectionType.Down:
|
|
||||||
if (_StartPosY + drawingAirplanHeight + (int)EntityAirplan.Step < picture_height - EntityAirplan.Step)
|
|
||||||
{
|
|
||||||
_StartPosY += (int)EntityAirplan.Step;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawTransport(Graphics2D g) {
|
public void MoveTransport(Direction direction) {
|
||||||
|
if (!CanMove(direction) || entityAirplan == null) {
|
||||||
if (EntityAirplan == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case Left:
|
||||||
|
_startPosX -= entityAirplan.Step;
|
||||||
|
break;
|
||||||
|
case Right:
|
||||||
|
_startPosX += entityAirplan.Step;
|
||||||
|
break;
|
||||||
|
case Up:
|
||||||
|
_startPosY -= entityAirplan.Step;
|
||||||
|
break;
|
||||||
|
case Down:
|
||||||
|
_startPosY += entityAirplan.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(Graphics2D g) {
|
||||||
|
|
||||||
|
if (entityAirplan == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
//Тело
|
//Тело
|
||||||
g.drawRect(_StartPosX + 5, _StartPosY + 50, 170, 30);
|
g.setColor(entityAirplan.getBodyColor());
|
||||||
g.drawArc(_StartPosX - 5, _StartPosY + 50, 20, 30, 90, 180);
|
g.fillRect(_startPosX + 5, _startPosY + 50, 170, 30);
|
||||||
|
g.fillArc(_startPosX - 5, _startPosY + 50, 20, 30, 90, 180);
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawRect(_startPosX + 5, _startPosY + 50, 170, 30);
|
||||||
|
g.drawArc(_startPosX - 5, _startPosY + 50, 20, 30, 90, 180);
|
||||||
|
|
||||||
|
_portholes.Draw(g, _startPosX + 30, _startPosY + 34);
|
||||||
//Заднее крыло
|
//Заднее крыло
|
||||||
g.drawLine(_StartPosX, _StartPosY, _StartPosX + 50, _StartPosY + 50);
|
g.setColor(Color.BLACK);
|
||||||
g.drawLine(_StartPosX, _StartPosY, _StartPosX, _StartPosY + 52);
|
g.drawPolygon(new int[]{_startPosX + 50, _startPosX, _startPosX}, new int[]{_startPosY + 50, _startPosY, _startPosY + 50}, 3);
|
||||||
|
g.setColor(entityAirplan.getBodyColor());
|
||||||
|
g.fillPolygon(new int[]{_startPosX + 50, _startPosX, _startPosX}, new int[]{_startPosY + 50, _startPosY, _startPosY + 50}, 3);
|
||||||
//Заднее боковые крылья
|
//Заднее боковые крылья
|
||||||
g.drawOval(_StartPosX - 7, _StartPosY + 45, 30, 8);
|
g.setColor(Color.BLACK);
|
||||||
g.fillOval(_StartPosX - 7, _StartPosY + 45, 30, 8);
|
g.drawOval(_startPosX - 7, _startPosY + 45, 30, 8);
|
||||||
|
g.setColor(entityAirplan.getBodyColor());
|
||||||
|
g.fillOval(_startPosX - 7, _startPosY + 45, 30, 8);
|
||||||
//Нос
|
//Нос
|
||||||
g.drawLine(_StartPosX + 175, _StartPosY + 50, _StartPosX + 200, _StartPosY + 65);
|
g.setColor(Color.BLACK);
|
||||||
g.drawLine(_StartPosX + 200, _StartPosY + 65, _StartPosX + 175, _StartPosY + 80);
|
g.drawPolygon(new int[]{_startPosX + 175, _startPosX + 200, _startPosX + 175}, new int[]{_startPosY + 50, _startPosY + 65, _startPosY + 65}, 3);
|
||||||
g.drawLine(_StartPosX + 175, _StartPosY + 50, _StartPosX + 175, _StartPosY + 80);
|
g.drawPolygon(new int[]{_startPosX + 175, _startPosX + 200, _startPosX + 175}, new int[]{_startPosY + 80, _startPosY + 65, _startPosY + 65}, 3);
|
||||||
g.drawLine(_StartPosX + 175, _StartPosY + 65, _StartPosX + 200, _StartPosY + 65);
|
g.setColor(entityAirplan.getBodyColor());
|
||||||
|
g.fillPolygon(new int[]{_startPosX + 175, _startPosX + 200, _startPosX + 175}, new int[]{_startPosY + 50, _startPosY + 65, _startPosY + 65}, 3);
|
||||||
|
g.fillPolygon(new int[]{_startPosX + 175, _startPosX + 200, _startPosX + 175}, new int[]{_startPosY + 80, _startPosY + 65, _startPosY + 65}, 3);
|
||||||
//Крылья
|
//Крылья
|
||||||
g.drawArc(_StartPosX + 49, _StartPosY + 62, 5, 5, 90, 180);
|
g.setColor(Color.BLACK);
|
||||||
g.drawLine(_StartPosX + 51, _StartPosY + 62, _StartPosX + 140, _StartPosY + 62);
|
g.drawArc(_startPosX + 49, _startPosY + 62, 5, 5, 90, 180);
|
||||||
g.drawArc(_StartPosX + 137, _StartPosY + 62, 5, 5, 2790, 180);
|
g.drawLine(_startPosX + 51, _startPosY + 62, _startPosX + 140, _startPosY + 62);
|
||||||
g.drawLine(_StartPosX + 51, _StartPosY + 67, _StartPosX + 140, _StartPosY + 67);
|
g.drawArc(_startPosX + 137, _startPosY + 62, 5, 5, 2790, 180);
|
||||||
|
g.drawLine(_startPosX + 51, _startPosY + 67, _startPosX + 140, _startPosY + 67);
|
||||||
//Задние шасси
|
//Задние шасси
|
||||||
g.drawLine(_StartPosX + 55, _StartPosY + 80, _StartPosX + 55, _StartPosY + 90);
|
g.drawLine(_startPosX + 55, _startPosY + 80, _startPosX + 55, _startPosY + 90);
|
||||||
g.drawOval(_StartPosX + 47, _StartPosY + 90, 5, 5);
|
g.drawOval(_startPosX + 47, _startPosY + 90, 5, 5);
|
||||||
g.drawOval(_StartPosX + 57, _StartPosY + 90, 5, 5);
|
g.drawOval(_startPosX + 57, _startPosY + 90, 5, 5);
|
||||||
|
g.setColor(entityAirplan.getBodyColor());
|
||||||
|
g.fillOval(_startPosX + 47, _startPosY + 90, 5, 5);
|
||||||
|
g.fillOval(_startPosX + 57, _startPosY + 90, 5, 5);
|
||||||
//Передние шасси
|
//Передние шасси
|
||||||
g.drawLine(_StartPosX + 165, _StartPosY + 80, _StartPosX + 165, _StartPosY + 90);
|
g.setColor(Color.BLACK);
|
||||||
g.drawOval(_StartPosX + 163, _StartPosY + 91, 5, 5);
|
g.drawLine(_startPosX + 165, _startPosY + 80, _startPosX + 165, _startPosY + 90);
|
||||||
|
g.drawOval(_startPosX + 163, _startPosY + 91, 5, 5);
|
||||||
|
g.setColor(entityAirplan.getBodyColor());
|
||||||
|
g.fillOval(_startPosX + 163, _startPosY + 91, 5, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,19 +2,18 @@ package Entities;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
public class EntityAirbus extends EntityAirplan {
|
public class EntityAirbus extends EntityAirplan {
|
||||||
|
private Color AdditionalColor;
|
||||||
|
private boolean IsCompartment;
|
||||||
|
private boolean IsAdditionalEngine;
|
||||||
|
|
||||||
private static Color AdditionalColor;
|
public EntityAirbus(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isAdditionalEngine) {
|
||||||
public static Color getAdditionalColor() {return AdditionalColor;}
|
super(speed, weight, bodyColor);
|
||||||
private static boolean IsCompartment;
|
AdditionalColor = additionalColor;
|
||||||
public static boolean getIsCompartment() {return IsCompartment;}
|
|
||||||
private static boolean IsAdditionalEngine;
|
|
||||||
public static boolean getIsAdditionalEngine() {return IsAdditionalEngine;}
|
|
||||||
|
|
||||||
public EntityAirbus(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isCompartment, boolean isAdditionalEngine)
|
|
||||||
{
|
|
||||||
super(speed,weight,bodycolor);
|
|
||||||
AdditionalColor = additionalcolor;
|
|
||||||
IsCompartment = isCompartment;
|
IsCompartment = isCompartment;
|
||||||
IsAdditionalEngine = isAdditionalEngine;
|
IsAdditionalEngine = isAdditionalEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color getAdditionalColor() { return AdditionalColor; }
|
||||||
|
public boolean IsCompartment() { return IsCompartment; }
|
||||||
|
public boolean IsAdditionalEngine() { return IsAdditionalEngine; }
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,27 @@ package Entities;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
public class EntityAirplan {
|
public class EntityAirplan {
|
||||||
private int Speed;
|
private int Speed;
|
||||||
private double Weight;
|
private float Weight;
|
||||||
private Color BodyColor;
|
private Color BodyColor;
|
||||||
public Color getBodyColor() {return BodyColor;}
|
public float Step;
|
||||||
public double Step;
|
|
||||||
public EntityAirplan(int speed, double weight, Color bodycolor)
|
public int getSpeed() {
|
||||||
|
return Speed;
|
||||||
|
}
|
||||||
|
public float getWeight() {
|
||||||
|
return Weight;
|
||||||
|
}
|
||||||
|
public Color getBodyColor() {
|
||||||
|
return BodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public EntityAirplan(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodycolor;
|
Speed = speed;
|
||||||
Step = Speed * 100 / Weight;
|
BodyColor = bodyColor;
|
||||||
|
Step = Speed * 200 / (int) Weight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,206 +1,250 @@
|
|||||||
import Drawings.CanvasAirbus;
|
|
||||||
import Drawings.DirectionType;
|
|
||||||
import Drawings.DrawingAirbus;
|
import Drawings.DrawingAirbus;
|
||||||
import Drawings.DrawingAirplan;
|
import Drawings.DrawingAirplan;
|
||||||
import MovementStrategy.*;
|
import MovementStrategy.AbstractStrategy;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ComponentAdapter;
|
|
||||||
import java.awt.event.ComponentEvent;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import MovementStrategy.*;
|
||||||
|
|
||||||
public class FormAirbus extends JFrame {
|
public class FormAirbus extends JFrame {
|
||||||
private String title;
|
private int width;
|
||||||
private Dimension dimension;
|
private int height;
|
||||||
private int Width, Height;
|
private DrawingAirplan _drawingAirbus;
|
||||||
public CanvasAirbus canvasAirbus = new CanvasAirbus();
|
private AbstractStrategy _abstractStrategy;
|
||||||
private JButton CreateButton = new JButton("Create airbus");;
|
private Canvas canvas;
|
||||||
private JButton CreateAirplanButton = new JButton("Create airplan");
|
|
||||||
private JButton UpButton = new JButton();
|
// выбор кол-ва иллюминаторов
|
||||||
private JButton DownButton = new JButton();;
|
JLabel labelCount;
|
||||||
private JButton LeftButton = new JButton();;
|
private JTextField fieldCount;
|
||||||
private JButton RightButton = new JButton();
|
|
||||||
private AbstractStrategy _strategy;
|
// выбор стратегии
|
||||||
private JComboBox ComboBoxStrategy = new JComboBox(new String[]{"К центру", "К краю"});
|
JLabel labelStrategy;
|
||||||
private JButton ButtonStrategy = new JButton("Шаг");
|
JComboBox comboBoxStrategy;
|
||||||
public FormAirbus(String title, Dimension dimension) {
|
JButton buttonStrategy;
|
||||||
this.title = title;
|
|
||||||
this.dimension = dimension;
|
private JButton buttonCreateAirbus;
|
||||||
|
private JButton buttonCreatePlane;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
|
||||||
|
public FormAirbus() {
|
||||||
|
super("Создание самолёта");
|
||||||
|
InitializeComponent();
|
||||||
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateObject(String typeOfClass) {
|
private void InitializeComponent() {
|
||||||
int StartPositionX = (int)(Math.random() * 90 + 10);
|
canvas = new Canvas();
|
||||||
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 "DrawingAirplan":
|
|
||||||
canvasAirbus._drawingAirplan = new DrawingAirplan(speed, weight, bodyColor);
|
|
||||||
canvasAirbus._drawingAirplan.SetPictureSize(Width, Height);
|
|
||||||
canvasAirbus._drawingAirplan.SetPosition(StartPositionX, StartPositionY);
|
|
||||||
canvasAirbus.repaint();
|
|
||||||
break;
|
|
||||||
case "DrawingAirbus":
|
|
||||||
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();;
|
|
||||||
canvasAirbus._drawingAirplan = new DrawingAirbus(speed, weight, bodyColor, additionalColor, IsCompartment , isAdditionalEngine);
|
|
||||||
canvasAirbus._drawingAirplan.SetPictureSize(Width, Height);
|
|
||||||
canvasAirbus._drawingAirplan.SetPosition(StartPositionX, StartPositionY);
|
|
||||||
canvasAirbus.repaint();
|
|
||||||
break;
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
_strategy = null;
|
|
||||||
ComboBoxStrategy.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init() {
|
labelCount = new JLabel("Введите число иллюминаторов:");
|
||||||
setTitle(title);
|
fieldCount = new JTextField();
|
||||||
setMinimumSize(dimension);
|
|
||||||
|
labelStrategy = new JLabel("Шаг стратегии:");
|
||||||
|
comboBoxStrategy = new JComboBox(new String[]{"К центру", "К краю"});
|
||||||
|
buttonStrategy = new JButton("Выбрать стратегию");
|
||||||
|
buttonStrategy.setMargin(new Insets(0, 0, 0, 0));
|
||||||
|
|
||||||
|
buttonCreateAirbus = new JButton("Создать аэробус");
|
||||||
|
buttonCreateAirbus.setMargin(new Insets(0, 0, 0, 0));
|
||||||
|
|
||||||
|
buttonCreatePlane = new JButton("Создать самолёт");
|
||||||
|
buttonCreatePlane.setMargin(new Insets(0, 0, 0, 0));
|
||||||
|
|
||||||
|
buttonUp = new JButton();
|
||||||
|
buttonUp.setName("up");
|
||||||
|
buttonUp.setIcon(new ImageIcon("images\\KeyUp.png"));
|
||||||
|
|
||||||
|
buttonRight = new JButton();
|
||||||
|
buttonRight.setName("right");
|
||||||
|
buttonRight.setIcon(new ImageIcon("images\\KeyRight.png"));
|
||||||
|
|
||||||
|
buttonLeft = new JButton();
|
||||||
|
buttonLeft.setName("left");
|
||||||
|
buttonLeft.setIcon(new ImageIcon("images\\KeyLeft.png"));
|
||||||
|
|
||||||
|
buttonDown = new JButton();
|
||||||
|
buttonDown.setName("down");
|
||||||
|
buttonDown.setIcon(new ImageIcon("images\\KeyDown.png"));
|
||||||
|
|
||||||
|
setSize(800, 500);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
Width = getWidth() - 15;
|
setLayout(null);
|
||||||
Height = getHeight() - 35;
|
|
||||||
_strategy = null;
|
|
||||||
CreateButton.setName("CREATE");
|
|
||||||
CreateAirplanButton.setName("CREATESAIRPLANBUTTON");
|
|
||||||
Icon iconUp = new ImageIcon("src\\image\\up.jpg");
|
|
||||||
UpButton.setIcon(iconUp);
|
|
||||||
UpButton.setName("UP");
|
|
||||||
DownButton.setName("DOWN");
|
|
||||||
Icon iconDown = new ImageIcon("src\\image\\down.jpg");
|
|
||||||
DownButton.setIcon(iconDown);
|
|
||||||
LeftButton.setName("LEFT");
|
|
||||||
Icon iconLeft = new ImageIcon("src\\image\\left.jpg");
|
|
||||||
LeftButton.setIcon(iconLeft);
|
|
||||||
RightButton.setName("RIGHT");
|
|
||||||
Icon iconRight = new ImageIcon("src\\image\\right.jpg");
|
|
||||||
RightButton.setIcon(iconRight);
|
|
||||||
|
|
||||||
CreateButton.addActionListener(new ActionListener() {
|
buttonCreateAirbus.setBounds(12, 355, 146, 33);
|
||||||
@Override
|
buttonCreatePlane.setBounds(182, 355, 146, 33);
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
CreateObject("DrawingAirbus");
|
labelCount.setBounds(42, 405, 240, 20);
|
||||||
|
fieldCount.setBounds(240, 407, 48, 20);
|
||||||
|
|
||||||
|
labelStrategy.setBounds(630, 20, 146, 33);
|
||||||
|
comboBoxStrategy.setBounds(630, 50, 146, 20);
|
||||||
|
buttonStrategy.setBounds(630, 80, 146, 33);
|
||||||
|
|
||||||
|
buttonUp.setBounds(679, 313, 48, 44);
|
||||||
|
buttonRight.setBounds(728, 358, 48, 44);
|
||||||
|
buttonLeft.setBounds(630, 358, 48, 44);
|
||||||
|
buttonDown.setBounds(679, 358, 48, 44);
|
||||||
|
labelCount.setBounds(12, 405, 240, 20);
|
||||||
|
fieldCount.setBounds(210, 407, 48, 20);
|
||||||
|
canvas.setBounds(0, 0, 790, 460);
|
||||||
|
|
||||||
|
add(buttonCreateAirbus);
|
||||||
|
add(buttonCreatePlane);
|
||||||
|
add(labelCount);
|
||||||
|
add(fieldCount);
|
||||||
|
add(labelStrategy);
|
||||||
|
add(comboBoxStrategy);
|
||||||
|
add(buttonStrategy);
|
||||||
|
add(buttonUp);
|
||||||
|
add(buttonRight);
|
||||||
|
add(buttonDown);
|
||||||
|
add(buttonLeft);
|
||||||
|
add(labelCount);
|
||||||
|
add(fieldCount);
|
||||||
|
add(canvas);
|
||||||
|
|
||||||
|
// логика формы
|
||||||
|
buttonCreateAirbus.addActionListener(buttonCreateAirbusListener);
|
||||||
|
buttonCreatePlane.addActionListener(buttonCreatePlaneListener);
|
||||||
|
buttonStrategy.addActionListener(buttonStrategyListener);
|
||||||
|
buttonUp.addActionListener(buttonsMoveListener);
|
||||||
|
buttonRight.addActionListener(buttonsMoveListener);
|
||||||
|
buttonDown.addActionListener(buttonsMoveListener);
|
||||||
|
buttonLeft.addActionListener(buttonsMoveListener);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
CreateAirplanButton.addActionListener(new ActionListener() {
|
ActionListener buttonCreateAirbusListener = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
CreateObject("DrawingAirplan");
|
int countPortholes;
|
||||||
|
try {
|
||||||
|
countPortholes = Integer.parseInt(fieldCount.getText());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
countPortholes = 0;
|
||||||
|
}
|
||||||
|
if (countPortholes != 10 && countPortholes != 20 && countPortholes != 30) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Число должно быть равно 10, 20 или 30.\nКол-во иллюминаторов приравнено к 10");
|
||||||
|
countPortholes = 10;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
ButtonStrategy.addActionListener(new ActionListener() {
|
Random rand = new Random();
|
||||||
|
_drawingAirbus = new DrawingAirplan(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
|
||||||
|
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
||||||
|
countPortholes,
|
||||||
|
canvas.getWidth(), canvas.getHeight());
|
||||||
|
|
||||||
|
_drawingAirbus.SetPosition(rand.nextInt(100) + 10, rand.nextInt(100) + 10);
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
canvas.repaint();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ActionListener buttonCreatePlaneListener = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (canvasAirbus._drawingAirplan == null) return;
|
int countPortholes;
|
||||||
if (ComboBoxStrategy.isEnabled())
|
try {
|
||||||
{
|
countPortholes = Integer.parseInt(fieldCount.getText());
|
||||||
int index = ComboBoxStrategy.getSelectedIndex();
|
} catch (Exception ex) {
|
||||||
switch(index)
|
countPortholes = 0;
|
||||||
{
|
}
|
||||||
|
if (countPortholes != 10 && countPortholes != 20 && countPortholes != 30) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Число должно быть равно 10, 20 или 30.\nКол-во иллюминаторов приравнено к 10");
|
||||||
|
countPortholes = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
Random rand = new Random();
|
||||||
|
_drawingAirbus = new DrawingAirbus(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
|
||||||
|
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
||||||
|
countPortholes,
|
||||||
|
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
||||||
|
rand.nextBoolean(), rand.nextBoolean(),
|
||||||
|
canvas.getWidth(), canvas.getHeight());
|
||||||
|
|
||||||
|
_drawingAirbus.SetPosition(rand.nextInt(100) + 10, rand.nextInt(100) + 10);
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
canvas.repaint();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ActionListener buttonStrategyListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_drawingAirbus == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.isEnabled()) {
|
||||||
|
|
||||||
|
switch (comboBoxStrategy.getSelectedIndex()) {
|
||||||
case 0:
|
case 0:
|
||||||
_strategy = new MoveToCenter();
|
_abstractStrategy = new MoveToCenter();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
_strategy = new MoveToBorder();
|
_abstractStrategy = new MoveToBorder();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_strategy = null;
|
_abstractStrategy = null;
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
if (_strategy == null)
|
;
|
||||||
{
|
if (_abstractStrategy == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_strategy.SetData(new MoveableAirplan(canvasAirbus._drawingAirplan), Width, Height);
|
_abstractStrategy.SetData(new MoveableAirplan(_drawingAirbus), canvas.getWidth(), canvas.getHeight());
|
||||||
|
comboBoxStrategy.setEnabled(false);
|
||||||
}
|
}
|
||||||
if (_strategy == null)
|
if (_abstractStrategy == null) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ComboBoxStrategy.setEnabled(false);
|
_abstractStrategy.MakeStep();
|
||||||
_strategy.MakeStep();
|
if (_abstractStrategy.GetStatus() == StrategyStatus.Finish) {
|
||||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
comboBoxStrategy.setEnabled(true);
|
||||||
{
|
_abstractStrategy = null;
|
||||||
ComboBoxStrategy.setEnabled(true);
|
|
||||||
_strategy = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ActionListener actionListener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent event) {
|
|
||||||
if (canvasAirbus._drawingAirplan == null) return;
|
|
||||||
boolean result = false;
|
|
||||||
switch ((((JButton)(event.getSource())).getName())) {
|
|
||||||
case "UP":
|
|
||||||
result = canvasAirbus._drawingAirplan.MoveTransport(DirectionType.Up);
|
|
||||||
break;
|
|
||||||
case "DOWN":
|
|
||||||
result = canvasAirbus._drawingAirplan.MoveTransport(DirectionType.Down);
|
|
||||||
break;
|
|
||||||
case "LEFT":
|
|
||||||
result = canvasAirbus._drawingAirplan.MoveTransport(DirectionType.Left);
|
|
||||||
break;
|
|
||||||
case "RIGHT":
|
|
||||||
result = canvasAirbus._drawingAirplan.MoveTransport(DirectionType.Right);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (result) {
|
|
||||||
canvasAirbus.repaint();
|
|
||||||
}
|
}
|
||||||
|
canvas.repaint();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
UpButton.addActionListener(actionListener);
|
|
||||||
DownButton.addActionListener(actionListener);
|
|
||||||
LeftButton.addActionListener(actionListener);
|
|
||||||
RightButton.addActionListener(actionListener);
|
|
||||||
|
|
||||||
setSize(dimension.width,dimension.height);
|
ActionListener buttonsMoveListener = new ActionListener() {
|
||||||
setLayout(null);
|
// реакция на нажатие
|
||||||
canvasAirbus.setBounds(0,0, getWidth(), getHeight());
|
public void actionPerformed(ActionEvent e) {
|
||||||
CreateButton.setBounds(10, getHeight() - 90, 125, 40);
|
if (_drawingAirbus == null) {
|
||||||
CreateAirplanButton.setBounds(160, getHeight() - 90, 125, 40);
|
return;
|
||||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
}
|
||||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
String command = ((JButton) (e.getSource())).getName();
|
||||||
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
switch (command) {
|
||||||
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
case "up":
|
||||||
ComboBoxStrategy.setBounds(getWidth() - 170, 10, 140, 35);
|
_drawingAirbus.MoveTransport(Direction.Up);
|
||||||
ButtonStrategy.setBounds(getWidth() - 130, 55, 100, 25);
|
break;
|
||||||
add(CreateButton);
|
case "down":
|
||||||
add(CreateAirplanButton);
|
_drawingAirbus.MoveTransport(Direction.Down);
|
||||||
add(UpButton);
|
break;
|
||||||
add(DownButton);
|
case "right":
|
||||||
add(RightButton);
|
_drawingAirbus.MoveTransport(Direction.Right);
|
||||||
add(LeftButton);
|
break;
|
||||||
add(ComboBoxStrategy);
|
case "left":
|
||||||
add(ButtonStrategy);
|
_drawingAirbus.MoveTransport(Direction.Left);
|
||||||
add(canvasAirbus);
|
break;
|
||||||
setVisible(true);
|
}
|
||||||
//обработка события изменения размеров окна
|
canvas.repaint();
|
||||||
addComponentListener(new ComponentAdapter() {
|
}
|
||||||
public void componentResized(ComponentEvent e) {
|
};
|
||||||
Width = getWidth() - 15;
|
|
||||||
Height = getHeight() - 35;
|
class Canvas extends JComponent {
|
||||||
if (canvasAirbus._drawingAirplan != null)
|
public Canvas() {
|
||||||
canvasAirbus._drawingAirplan.SetPictureSize(Width, Height);
|
}
|
||||||
canvasAirbus.setBounds(0,0, getWidth(), getHeight());
|
|
||||||
CreateButton.setBounds(10, getHeight() - 90, 125, 40);
|
public void paintComponent(Graphics g) {
|
||||||
CreateAirplanButton.setBounds(160, getHeight() - 90, 125, 40);
|
if (_drawingAirbus == null) {
|
||||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
return;
|
||||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
}
|
||||||
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
super.paintComponents(g);
|
||||||
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
ComboBoxStrategy.setBounds(getWidth() - 170, 10, 140, 35);
|
_drawingAirbus.DrawTransport(g2d);
|
||||||
ButtonStrategy.setBounds(getWidth() - 130, 55, 100, 25);
|
super.repaint();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,6 @@ import java.awt.*;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
FormAirbus form = new FormAirbus("Самолёт", new Dimension(500, 500));
|
new FormAirbus();
|
||||||
form.Init();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,54 +3,74 @@ package MovementStrategy;
|
|||||||
public abstract class AbstractStrategy {
|
public abstract class AbstractStrategy {
|
||||||
private IMoveableObject _moveableObject;
|
private IMoveableObject _moveableObject;
|
||||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||||
public int FieldWidth;
|
protected int FieldWidth;
|
||||||
public int FieldHeight;
|
protected int FieldHeight;
|
||||||
public StrategyStatus GetStatus() {return _state;}
|
public StrategyStatus GetStatus() { return _state; }
|
||||||
public void SetData(IMoveableObject moveableObjects, int width, int height)
|
|
||||||
|
// Изменить статус, установить поля
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||||
{
|
{
|
||||||
if (moveableObjects == null)
|
if (moveableObject == null)
|
||||||
{
|
{
|
||||||
_state = StrategyStatus.NotInit;
|
_state = StrategyStatus.NotInit;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_state = StrategyStatus.InProgress;
|
_state = StrategyStatus.InProgress;
|
||||||
_moveableObject = moveableObjects;
|
_moveableObject = moveableObject;
|
||||||
FieldWidth = width;
|
FieldWidth = width;
|
||||||
FieldHeight = height;
|
FieldHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// сделать шаг
|
||||||
public void MakeStep()
|
public void MakeStep()
|
||||||
{
|
{
|
||||||
if (_state != StrategyStatus.InProgress) return;
|
if (_state != StrategyStatus.InProgress)
|
||||||
if (IsTargetDestinaion())
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestination())
|
||||||
{
|
{
|
||||||
_state = StrategyStatus.Finish;
|
_state = StrategyStatus.Finish;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MoveToTarget();
|
MoveToTarget();
|
||||||
}
|
}
|
||||||
protected boolean MoveLeft() {return MoveTo(MovementDirection.Left);};
|
|
||||||
protected boolean MoveRight() {return MoveTo(MovementDirection.Right);};
|
// перемещения
|
||||||
protected boolean MoveUp() {return MoveTo(MovementDirection.Up);};
|
protected boolean MoveLeft() { return MoveTo(Direction.Up); }
|
||||||
protected boolean MoveDown() {return MoveTo(MovementDirection.Down);};
|
protected boolean MoveRight() { return MoveTo(Direction.Right); }
|
||||||
protected ObjectParameters GetObjectParameters() {return _moveableObject.GetObjectPosition();};
|
protected boolean MoveUp() { return MoveTo(Direction.Up); }
|
||||||
protected Integer GetStep()
|
protected boolean MoveDown() { return MoveTo(Direction.Down); }
|
||||||
|
|
||||||
|
// параметры
|
||||||
|
protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
|
||||||
|
// шаг
|
||||||
|
protected int GetStep()
|
||||||
{
|
{
|
||||||
if (_state != StrategyStatus.InProgress)
|
if (_state != StrategyStatus.InProgress)
|
||||||
{
|
{
|
||||||
return null;
|
return 0;
|
||||||
}
|
}
|
||||||
return _moveableObject.GetStep();
|
return _moveableObject.GetStep();
|
||||||
}
|
}
|
||||||
|
// перемещение
|
||||||
protected abstract void MoveToTarget();
|
protected abstract void MoveToTarget();
|
||||||
protected abstract boolean IsTargetDestinaion();
|
|
||||||
private boolean MoveTo(MovementDirection movementDirection)
|
// достигнута ли цель
|
||||||
|
protected abstract boolean IsTargetDestination();
|
||||||
|
|
||||||
|
// попытка перемещения по направлению
|
||||||
|
private boolean MoveTo(Direction directionType)
|
||||||
{
|
{
|
||||||
if (_state != StrategyStatus.InProgress)
|
if (_state != StrategyStatus.InProgress)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean stateTryMoveObject = _moveableObject.TryMoveObject(movementDirection);
|
if (_moveableObject.CheckCanMove(directionType))
|
||||||
if (stateTryMoveObject) return stateTryMoveObject;
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package MovementStrategy;
|
package MovementStrategy;
|
||||||
|
|
||||||
public enum MovementDirection {
|
public enum Direction {
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right;
|
||||||
}
|
}
|
@ -3,5 +3,6 @@ package MovementStrategy;
|
|||||||
public interface IMoveableObject {
|
public interface IMoveableObject {
|
||||||
ObjectParameters GetObjectPosition();
|
ObjectParameters GetObjectPosition();
|
||||||
int GetStep();
|
int GetStep();
|
||||||
boolean TryMoveObject(MovementDirection direction);
|
boolean CheckCanMove(Direction direction);
|
||||||
|
void MoveObject(Direction direction);
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,45 @@
|
|||||||
package MovementStrategy;
|
package MovementStrategy;
|
||||||
|
|
||||||
public class MoveToBorder extends AbstractStrategy{
|
public class MoveToBorder extends AbstractStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean IsTargetDestinaion() {
|
protected boolean IsTargetDestination()
|
||||||
ObjectParameters objParams = GetObjectParameters();
|
{
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
if (objParams == null)
|
if (objParams == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return objParams.RightBorder + GetStep() >= FieldWidth-GetStep() &&
|
return objParams.RightBorder() + GetStep() >= FieldWidth && objParams.DownBorder() + GetStep() >= FieldHeight;
|
||||||
objParams.DownBorder + GetStep() >= FieldHeight-GetStep();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// движение к цели
|
||||||
@Override
|
@Override
|
||||||
protected void MoveToTarget() {
|
protected void MoveToTarget()
|
||||||
ObjectParameters objParams = GetObjectParameters();
|
{
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
if (objParams == null)
|
if (objParams == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//реализация в правый нижний угол
|
var diffX = objParams.RightBorder() - FieldWidth;
|
||||||
int x = objParams.RightBorder;
|
var diffY = objParams.DownBorder() - FieldHeight;
|
||||||
if (x + GetStep() < FieldWidth) MoveRight();
|
if (diffX >= 0)
|
||||||
int y = objParams.DownBorder;
|
{
|
||||||
if (y + GetStep() < FieldHeight) MoveDown();
|
MoveDown();
|
||||||
|
}
|
||||||
|
else if (diffY >= 0)
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
else if (Math.abs(diffX) > Math.abs(diffY))
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,30 @@
|
|||||||
package MovementStrategy;
|
package MovementStrategy;
|
||||||
|
|
||||||
public class MoveToCenter extends AbstractStrategy{
|
public class MoveToCenter extends AbstractStrategy {
|
||||||
@Override
|
@Override
|
||||||
protected boolean IsTargetDestinaion() {
|
protected boolean IsTargetDestination()
|
||||||
ObjectParameters objParams = GetObjectParameters();
|
{
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
if (objParams == null)
|
if (objParams == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 &&
|
return objParams.ObjectMiddleHorizontal() <= FieldWidth / 2 &&
|
||||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
||||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 &&
|
objParams.ObjectMiddleVertical() <= FieldHeight / 2 &&
|
||||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight /2;
|
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// движение к цели
|
||||||
@Override
|
@Override
|
||||||
protected void MoveToTarget() {
|
protected void MoveToTarget()
|
||||||
ObjectParameters objParams = GetObjectParameters();
|
{
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
if (objParams == null)
|
if (objParams == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
||||||
if (Math.abs(diffX) > GetStep())
|
if (Math.abs(diffX) > GetStep())
|
||||||
{
|
{
|
||||||
if (diffX > 0)
|
if (diffX > 0)
|
||||||
@ -32,7 +36,8 @@ public class MoveToCenter extends AbstractStrategy{
|
|||||||
MoveRight();
|
MoveRight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
|
||||||
|
var diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
||||||
if (Math.abs(diffY) > GetStep())
|
if (Math.abs(diffY) > GetStep())
|
||||||
{
|
{
|
||||||
if (diffY > 0)
|
if (diffY > 0)
|
||||||
|
@ -1,47 +1,33 @@
|
|||||||
package MovementStrategy;
|
package MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
import Drawings.CanvasAirbus;
|
|
||||||
import Drawings.DirectionType;
|
|
||||||
import Drawings.DrawingAirbus;
|
|
||||||
import Drawings.DrawingAirplan;
|
import Drawings.DrawingAirplan;
|
||||||
|
|
||||||
public class MoveableAirplan implements IMoveableObject{
|
public class MoveableAirplan implements IMoveableObject {
|
||||||
private CanvasAirbus canvas = new CanvasAirbus();
|
private DrawingAirplan _drawingAirplan = null;
|
||||||
public MoveableAirplan(DrawingAirplan drawningairplan)
|
|
||||||
|
public MoveableAirplan(DrawingAirplan drawingAirplan)
|
||||||
{
|
{
|
||||||
canvas._drawingAirplan = drawningairplan;
|
_drawingAirplan = drawingAirplan;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public ObjectParameters GetObjectPosition() {
|
public ObjectParameters GetObjectPosition()
|
||||||
if (canvas._drawingAirplan == null || canvas._drawingAirplan.EntityAirplan == null ||
|
{
|
||||||
canvas._drawingAirplan.GetPosX() == null || canvas._drawingAirplan.GetPosY() == null)
|
if (_drawingAirplan == null || _drawingAirplan.entityAirplan == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new ObjectParameters(canvas._drawingAirplan.GetPosX(), canvas._drawingAirplan.GetPosY(),
|
return new ObjectParameters(_drawingAirplan.GetPosX(), _drawingAirplan.GetPosY(), _drawingAirplan.GetWidth(), _drawingAirplan.GetHeight());
|
||||||
canvas._drawingAirplan.GetWidth(), canvas._drawingAirplan.GetHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetStep() { return (int)_drawingAirplan.entityAirplan.Step; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int GetStep() {
|
public boolean CheckCanMove(Direction direction) {
|
||||||
return (int)(canvas._drawingAirplan.EntityAirplan.Step);
|
return _drawingAirplan.CanMove(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean TryMoveObject(MovementDirection direction) {
|
public void MoveObject(Direction direction) {
|
||||||
if (canvas._drawingAirplan == null || canvas._drawingAirplan.EntityAirplan == null)
|
_drawingAirplan.MoveTransport(direction);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return canvas._drawingAirplan.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;
|
|
||||||
default: return DirectionType.Unknown;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,23 +5,21 @@ public class ObjectParameters {
|
|||||||
private int _y;
|
private int _y;
|
||||||
private int _width;
|
private int _width;
|
||||||
private int _height;
|
private int _height;
|
||||||
public int LeftBorder = _x;
|
|
||||||
public int TopBorder = _y;
|
public int LeftBorder() { return _x; }
|
||||||
public int RightBorder = _x + _width;
|
public int TopBorder() { return _y; }
|
||||||
public int DownBorder = _y + _height;
|
public int RightBorder() { return _x + _width; }
|
||||||
public int ObjectMiddleHorizontal = _x + _width / 2;
|
public int DownBorder() { return _y + _height; }
|
||||||
public int ObjectMiddleVertical = _y + _height / 2;
|
|
||||||
|
|
||||||
|
public int ObjectMiddleHorizontal () { return _x + _width / 2; }
|
||||||
|
public int ObjectMiddleVertical () { return _y + _height / 2; }
|
||||||
|
|
||||||
public ObjectParameters(int x, int y, int width, int height)
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
_x = x;
|
_x = x;
|
||||||
_y = y;
|
_y = y;
|
||||||
_width = width;
|
_width = width;
|
||||||
_height = height;
|
_height = height;
|
||||||
LeftBorder = _x;
|
|
||||||
TopBorder = _y;
|
|
||||||
RightBorder = _x + _width;
|
|
||||||
DownBorder = _y + _height;
|
|
||||||
ObjectMiddleHorizontal = _x + _width / 2;
|
|
||||||
ObjectMiddleVertical = _y + _height / 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user