Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b162d292f2 | ||
|
fae4bc9884 | ||
|
5a616bf909 | ||
|
9a79ed80e2 | ||
|
bbf868ac7d | ||
|
1949aadf52 | ||
|
7e0d0d42b1 | ||
|
ecb63e6e2c | ||
|
67ad38f49a | ||
|
3d6983c22a | ||
|
002d5890d9 |
BIN
SelfPropelledArtilleryUnit/Arrows/down-arrow.png
Normal file
BIN
SelfPropelledArtilleryUnit/Arrows/down-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 281 B |
BIN
SelfPropelledArtilleryUnit/Arrows/left-arrow.png
Normal file
BIN
SelfPropelledArtilleryUnit/Arrows/left-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 265 B |
BIN
SelfPropelledArtilleryUnit/Arrows/right-arrow.png
Normal file
BIN
SelfPropelledArtilleryUnit/Arrows/right-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 224 B |
BIN
SelfPropelledArtilleryUnit/Arrows/upper-arrow.png
Normal file
BIN
SelfPropelledArtilleryUnit/Arrows/upper-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 264 B |
14
SelfPropelledArtilleryUnit/DirectionType.java
Normal file
14
SelfPropelledArtilleryUnit/DirectionType.java
Normal file
@ -0,0 +1,14 @@
|
||||
package SelfPropelledArtilleryUnit;
|
||||
public enum DirectionType
|
||||
{
|
||||
Up(1),
|
||||
Down(2),
|
||||
Left(3),
|
||||
Right(4);
|
||||
|
||||
private final int DirectionTypeCode;
|
||||
private DirectionType(int DirectionTypeCode){
|
||||
this.DirectionTypeCode = DirectionTypeCode;
|
||||
}
|
||||
|
||||
}
|
101
SelfPropelledArtilleryUnit/DrawningObjects/DrawningClamps.java
Normal file
101
SelfPropelledArtilleryUnit/DrawningObjects/DrawningClamps.java
Normal file
@ -0,0 +1,101 @@
|
||||
package SelfPropelledArtilleryUnit.DrawningObjects;
|
||||
import SelfPropelledArtilleryUnit.NumbeRollers;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
public class DrawningClamps implements IDrawable {
|
||||
|
||||
Graphics2D g2d;
|
||||
int startPosX;
|
||||
int startPosY;
|
||||
Color color;
|
||||
private NumbeRollers _numbeRollers;
|
||||
|
||||
@Override
|
||||
public void setNum(int numRollers) {
|
||||
if (numRollers < 4 || numRollers > 6 ){
|
||||
|
||||
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
|
||||
return;
|
||||
}
|
||||
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
|
||||
}
|
||||
|
||||
public DrawningClamps(Graphics2D g2d, int startPosX, int startPosY, Color color, int numRollers){
|
||||
this.color = color;
|
||||
this.g2d = g2d;
|
||||
this.startPosX = startPosX;
|
||||
this.startPosY = startPosY;
|
||||
setNum(numRollers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(){
|
||||
g2d.setPaint(Color.BLACK);
|
||||
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
|
||||
|
||||
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
|
||||
g2d.draw(ellipse7);
|
||||
switch (_numbeRollers) {
|
||||
case Min:
|
||||
g2d.fill(ellipse1);
|
||||
g2d.fill(ellipse2);
|
||||
g2d.fill(ellipse3);
|
||||
g2d.fill(ellipse4);
|
||||
break;
|
||||
case Mid:
|
||||
g2d.fill(ellipse1);
|
||||
g2d.fill(ellipse2);
|
||||
g2d.fill(ellipse3);
|
||||
g2d.fill(ellipse4);
|
||||
g2d.fill(ellipse5);
|
||||
break;
|
||||
case Max:
|
||||
g2d.fill(ellipse1);
|
||||
g2d.fill(ellipse2);
|
||||
g2d.fill(ellipse3);
|
||||
g2d.fill(ellipse4);
|
||||
g2d.fill(ellipse5);
|
||||
g2d.fill(ellipse6);
|
||||
break;
|
||||
}
|
||||
|
||||
Ellipse2D ellipse11 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 10, 10);
|
||||
Ellipse2D ellipse12 = new Ellipse2D.Double(startPosX + 35, startPosY + 55, 10, 10);
|
||||
Ellipse2D ellipse13 = new Ellipse2D.Double(startPosX + 60, startPosY + 55, 10, 10);
|
||||
Ellipse2D ellipse14 = new Ellipse2D.Double(startPosX + 85, startPosY + 55, 10, 10);
|
||||
Ellipse2D ellipse15 = new Ellipse2D.Double(startPosX + 110, startPosY + 55, 10, 10);
|
||||
Ellipse2D ellipse16 = new Ellipse2D.Double(startPosX + 127, startPosY + 60, 5, 5);
|
||||
g2d.setPaint(color);
|
||||
switch (_numbeRollers) {
|
||||
case Min:
|
||||
g2d.fill(ellipse11);
|
||||
g2d.fill(ellipse12);
|
||||
g2d.fill(ellipse13);
|
||||
g2d.fill(ellipse14);
|
||||
break;
|
||||
case Mid:
|
||||
g2d.fill(ellipse11);
|
||||
g2d.fill(ellipse12);
|
||||
g2d.fill(ellipse13);
|
||||
g2d.fill(ellipse14);
|
||||
g2d.fill(ellipse15);
|
||||
break;
|
||||
case Max:
|
||||
g2d.fill(ellipse11);
|
||||
g2d.fill(ellipse12);
|
||||
g2d.fill(ellipse13);
|
||||
g2d.fill(ellipse14);
|
||||
g2d.fill(ellipse15);
|
||||
g2d.fill(ellipse16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
102
SelfPropelledArtilleryUnit/DrawningObjects/DrawningNails.java
Normal file
102
SelfPropelledArtilleryUnit/DrawningObjects/DrawningNails.java
Normal file
@ -0,0 +1,102 @@
|
||||
package SelfPropelledArtilleryUnit.DrawningObjects;
|
||||
import SelfPropelledArtilleryUnit.NumbeRollers;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
public class DrawningNails implements IDrawable {
|
||||
|
||||
Graphics2D g2d;
|
||||
int startPosX;
|
||||
int startPosY;
|
||||
Color color;
|
||||
private NumbeRollers _numbeRollers;
|
||||
|
||||
@Override
|
||||
public void setNum(int numRollers) {
|
||||
if (numRollers < 4 || numRollers > 6 ){
|
||||
|
||||
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
|
||||
return;
|
||||
}
|
||||
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
|
||||
}
|
||||
|
||||
public DrawningNails(Graphics2D g2d, int startPosX, int startPosY, Color color, int numRollers){
|
||||
this.color = color;
|
||||
this.g2d = g2d;
|
||||
this.startPosX = startPosX;
|
||||
this.startPosY = startPosY;
|
||||
setNum(numRollers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(){
|
||||
|
||||
g2d.setPaint(Color.BLACK);
|
||||
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
|
||||
|
||||
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
|
||||
g2d.draw(ellipse7);
|
||||
switch (_numbeRollers) {
|
||||
case Min:
|
||||
g2d.fill(ellipse1);
|
||||
g2d.fill(ellipse2);
|
||||
g2d.fill(ellipse3);
|
||||
g2d.fill(ellipse4);
|
||||
break;
|
||||
case Mid:
|
||||
g2d.fill(ellipse1);
|
||||
g2d.fill(ellipse2);
|
||||
g2d.fill(ellipse3);
|
||||
g2d.fill(ellipse4);
|
||||
g2d.fill(ellipse5);
|
||||
break;
|
||||
case Max:
|
||||
g2d.fill(ellipse1);
|
||||
g2d.fill(ellipse2);
|
||||
g2d.fill(ellipse3);
|
||||
g2d.fill(ellipse4);
|
||||
g2d.fill(ellipse5);
|
||||
g2d.fill(ellipse6);
|
||||
break;
|
||||
}
|
||||
|
||||
Ellipse2D ellipse11 = new Ellipse2D.Double(startPosX + 15, startPosY + 62, 2, 2);
|
||||
Ellipse2D ellipse12 = new Ellipse2D.Double(startPosX + 40, startPosY + 62, 2, 2);
|
||||
Ellipse2D ellipse13 = new Ellipse2D.Double(startPosX + 65, startPosY + 62, 2, 2);
|
||||
Ellipse2D ellipse14 = new Ellipse2D.Double(startPosX + 90, startPosY + 62, 2, 2);
|
||||
Ellipse2D ellipse15 = new Ellipse2D.Double(startPosX + 115, startPosY + 62, 2, 2);
|
||||
Ellipse2D ellipse16 = new Ellipse2D.Double(startPosX + 130, startPosY + 65, 1, 1);
|
||||
g2d.setPaint(color);
|
||||
switch (_numbeRollers) {
|
||||
case Min:
|
||||
g2d.fill(ellipse11);
|
||||
g2d.fill(ellipse12);
|
||||
g2d.fill(ellipse13);
|
||||
g2d.fill(ellipse14);
|
||||
break;
|
||||
case Mid:
|
||||
g2d.fill(ellipse11);
|
||||
g2d.fill(ellipse12);
|
||||
g2d.fill(ellipse13);
|
||||
g2d.fill(ellipse14);
|
||||
g2d.fill(ellipse15);
|
||||
break;
|
||||
case Max:
|
||||
g2d.fill(ellipse11);
|
||||
g2d.fill(ellipse12);
|
||||
g2d.fill(ellipse13);
|
||||
g2d.fill(ellipse14);
|
||||
g2d.fill(ellipse15);
|
||||
g2d.fill(ellipse16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package SelfPropelledArtilleryUnit.DrawningObjects;
|
||||
import SelfPropelledArtilleryUnit.NumbeRollers;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
public class DrawningRollers implements IDrawable{
|
||||
Graphics2D g2d;
|
||||
int startPosX;
|
||||
int startPosY;
|
||||
Color color;
|
||||
private NumbeRollers _numbeRollers;
|
||||
|
||||
@Override
|
||||
public void setNum(int numRollers) {
|
||||
if (numRollers < 4 || numRollers > 6 ){
|
||||
|
||||
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
|
||||
return;
|
||||
}
|
||||
_numbeRollers = NumbeRollers.fromNumberToEnum(numRollers);
|
||||
}
|
||||
|
||||
public DrawningRollers(Graphics2D g2d, int startPosX, int startPosY, Color color, int numRollers){
|
||||
this.color = color;
|
||||
this.g2d = g2d;
|
||||
this.startPosX = startPosX;
|
||||
this.startPosY = startPosY;
|
||||
setNum(numRollers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(){
|
||||
g2d.setPaint(Color.BLACK);
|
||||
Ellipse2D ellipse7 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 120, 20);
|
||||
|
||||
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
|
||||
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 125, startPosY + 60, 10, 10);
|
||||
g2d.draw(ellipse7);
|
||||
switch (_numbeRollers) {
|
||||
case Min:
|
||||
g2d.fill(ellipse1);
|
||||
g2d.fill(ellipse2);
|
||||
g2d.fill(ellipse3);
|
||||
g2d.fill(ellipse4);
|
||||
break;
|
||||
case Mid:
|
||||
g2d.fill(ellipse1);
|
||||
g2d.fill(ellipse2);
|
||||
g2d.fill(ellipse3);
|
||||
g2d.fill(ellipse4);
|
||||
g2d.fill(ellipse5);
|
||||
break;
|
||||
case Max:
|
||||
g2d.fill(ellipse1);
|
||||
g2d.fill(ellipse2);
|
||||
g2d.fill(ellipse3);
|
||||
g2d.fill(ellipse4);
|
||||
g2d.fill(ellipse5);
|
||||
g2d.fill(ellipse6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
223
SelfPropelledArtilleryUnit/DrawningObjects/DrawningSPAU.java
Normal file
223
SelfPropelledArtilleryUnit/DrawningObjects/DrawningSPAU.java
Normal file
@ -0,0 +1,223 @@
|
||||
package SelfPropelledArtilleryUnit.DrawningObjects;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Path2D;
|
||||
|
||||
import SelfPropelledArtilleryUnit.DirectionType;
|
||||
import SelfPropelledArtilleryUnit.Entities.EntitySPAU;
|
||||
|
||||
|
||||
public class DrawningSPAU {
|
||||
private EntitySPAU EntitySPAU;
|
||||
private int pictureWidth;
|
||||
private int pictureHeight;
|
||||
protected int startPosX;
|
||||
protected int startPosY;
|
||||
private int _numbeRollers;
|
||||
private int rollVar;
|
||||
private int carWidth = 135;
|
||||
private int carHeight = 75;
|
||||
|
||||
protected void setEntitySPAU(EntitySPAU entitySPAU) {
|
||||
this.EntitySPAU = entitySPAU;
|
||||
}
|
||||
|
||||
public EntitySPAU getEntitySPAU() {
|
||||
return EntitySPAU;
|
||||
}
|
||||
|
||||
public DrawningSPAU(int _numbeRollers, int rollVar, int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
this._numbeRollers = _numbeRollers;
|
||||
this.rollVar = rollVar;
|
||||
this.pictureWidth = width;
|
||||
this.pictureHeight = height;
|
||||
if (this.carHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (this.carWidth >= width)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntitySPAU = new EntitySPAU(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
public DrawningSPAU(int _numbeRollers, int rollVar, int speed, double weight, Color bodyColor, int width, int height, int carWidth, int carHeight)
|
||||
{
|
||||
this._numbeRollers = _numbeRollers;
|
||||
this.rollVar = rollVar;
|
||||
this.pictureWidth = width;
|
||||
this.pictureHeight = height;
|
||||
this.carWidth = carWidth;
|
||||
this.carHeight = carHeight;
|
||||
if (this.carHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (this.carWidth >= width)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntitySPAU = new EntitySPAU(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x > this.pictureWidth - this.carWidth)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0 || y > this.pictureHeight - this.carHeight)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
this.startPosX = x;
|
||||
this.startPosY = y;
|
||||
}
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntitySPAU == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case Left:
|
||||
this.startPosX -= (int)EntitySPAU.getStep();
|
||||
break;
|
||||
//вверх
|
||||
case Up:
|
||||
this.startPosY -= (int)EntitySPAU.getStep();
|
||||
break;
|
||||
// вправо
|
||||
case Right:
|
||||
this.startPosX += (int)EntitySPAU.getStep();
|
||||
break;
|
||||
//вниз
|
||||
case Down:
|
||||
this.startPosY += (int)EntitySPAU.getStep();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g) {
|
||||
if (EntitySPAU == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
Color bodyColor = EntitySPAU.BodyColor;
|
||||
Path2D.Double path = new Path2D.Double();
|
||||
|
||||
//гусеницы
|
||||
IDrawable Rollers = new DrawningRollers(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
|
||||
switch (rollVar) {
|
||||
case 2:
|
||||
Rollers = new DrawningClamps(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
|
||||
break;
|
||||
case 3:
|
||||
Rollers = new DrawningNails(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Rollers.Draw();
|
||||
|
||||
// пушка
|
||||
path.moveTo(startPosX + 35, startPosY + 40);
|
||||
path.lineTo(startPosX + 40, startPosY + 45);
|
||||
path.lineTo(startPosX + 135, startPosY + 5);
|
||||
path.lineTo(startPosX + 130, startPosY + 0);
|
||||
path.closePath();
|
||||
|
||||
g2d.setPaint(bodyColor);
|
||||
g2d.fill(path);
|
||||
g2d.draw(path);
|
||||
path.reset();
|
||||
|
||||
// корпус
|
||||
path.moveTo(startPosX, startPosY + 60);
|
||||
path.lineTo(startPosX + 10, startPosY + 30);
|
||||
path.lineTo(startPosX + 130, startPosY + 30);
|
||||
path.lineTo(startPosX + 135, startPosY + 60);
|
||||
path.closePath();
|
||||
|
||||
g2d.setPaint(bodyColor);
|
||||
g2d.fill(path);
|
||||
g2d.draw(path);
|
||||
path.reset();
|
||||
|
||||
// башня
|
||||
path.moveTo(startPosX + 40, startPosY + 30);
|
||||
path.lineTo(startPosX + 45, startPosY + 15);
|
||||
path.lineTo(startPosX + 70, startPosY + 15);
|
||||
path.lineTo(startPosX + 75, startPosY + 30);
|
||||
path.closePath();
|
||||
|
||||
g2d.setPaint(bodyColor);
|
||||
g2d.fill(path);
|
||||
g2d.draw(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Координата X объекта
|
||||
*
|
||||
* @return значение координаты X
|
||||
*/
|
||||
public int getPosX() {
|
||||
return this.startPosX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Координата Y объекта
|
||||
*
|
||||
* @return значение координаты Y
|
||||
*/
|
||||
public int getPosY() {
|
||||
return this.startPosY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ширина объекта
|
||||
*
|
||||
* @return значение ширины
|
||||
*/
|
||||
public int getWidth() {
|
||||
return this.carWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Высота объекта
|
||||
*
|
||||
* @return значение высоты
|
||||
*/
|
||||
public int getHeight() {
|
||||
return this.carHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка, что объект может переместиться в указанном направлении
|
||||
*
|
||||
* @param direction Направление
|
||||
* @return true - можно переместиться в указанном направлении
|
||||
*/
|
||||
public boolean CanMove(DirectionType direction) {
|
||||
if (EntitySPAU == null) {
|
||||
return false;
|
||||
}
|
||||
switch (direction) {
|
||||
case Left: // влево
|
||||
return startPosX - EntitySPAU.getStep() > 0;
|
||||
case Up: // вверх
|
||||
return startPosY - EntitySPAU.getStep() > 0;
|
||||
case Right: // вправо
|
||||
return startPosX + EntitySPAU.getStep() < pictureWidth - carWidth;
|
||||
case Down: // вниз
|
||||
return startPosY + EntitySPAU.getStep() < pictureHeight - carHeight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package SelfPropelledArtilleryUnit.DrawningObjects;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import SelfPropelledArtilleryUnit.Entities.EntitySPAUchild;
|
||||
|
||||
public class DrawningSPAUchild extends DrawningSPAU {
|
||||
private EntitySPAUchild EntitySPAU;
|
||||
|
||||
protected void setEntitySPAU(EntitySPAUchild entitySPAU) {
|
||||
this.EntitySPAU = entitySPAU;
|
||||
}
|
||||
|
||||
public DrawningSPAUchild(int _numbeRollers, int rollVar, int speed, double weight, Color bodyColor, Color additionalColor, boolean bodyKit, boolean ballone, int width, int height) {
|
||||
super(_numbeRollers, rollVar, speed, weight, bodyColor, width, height);
|
||||
|
||||
EntitySPAU = new EntitySPAUchild(speed, weight, bodyColor, additionalColor, bodyKit, ballone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
BasicStroke penBlack = new BasicStroke(1);
|
||||
Color additionalColor = EntitySPAU.AdditionalColor;
|
||||
boolean hasBodyKit = EntitySPAU.BodyKit;
|
||||
|
||||
Path2D.Double path = new Path2D.Double();
|
||||
|
||||
// Обвесы
|
||||
if (hasBodyKit) {
|
||||
path.moveTo(startPosX + 15, startPosY + 20);
|
||||
path.lineTo(startPosX + 35, startPosY + 20);
|
||||
path.lineTo(startPosX + 35, startPosY + 60);
|
||||
path.lineTo(startPosX + 15, startPosY + 60);
|
||||
path.closePath();
|
||||
|
||||
g2d.setPaint(additionalColor);
|
||||
g2d.fill(path);
|
||||
|
||||
g2d.setPaint(Color.BLACK);
|
||||
g2d.setStroke(penBlack);
|
||||
g2d.draw(path);
|
||||
path.reset();
|
||||
|
||||
Line2D line = new Line2D.Double(startPosX + 5, startPosY + 20, startPosX + 15, startPosY + 25);
|
||||
g2d.draw(line);
|
||||
|
||||
super.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package SelfPropelledArtilleryUnit.DrawningObjects;
|
||||
|
||||
public interface IDrawable {
|
||||
public void setNum(int num);
|
||||
public void Draw();
|
||||
}
|
19
SelfPropelledArtilleryUnit/Entities/EntitySPAU.java
Normal file
19
SelfPropelledArtilleryUnit/Entities/EntitySPAU.java
Normal file
@ -0,0 +1,19 @@
|
||||
package SelfPropelledArtilleryUnit.Entities;
|
||||
import java.awt.Color;
|
||||
|
||||
public class EntitySPAU {
|
||||
|
||||
public int Speed;
|
||||
public double Weight;
|
||||
public Color BodyColor;
|
||||
|
||||
public EntitySPAU(int speed, double weight, Color bodyColor) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
|
||||
public double getStep() {
|
||||
return (double) Speed * 100 / Weight;
|
||||
}
|
||||
}
|
16
SelfPropelledArtilleryUnit/Entities/EntitySPAUchild.java
Normal file
16
SelfPropelledArtilleryUnit/Entities/EntitySPAUchild.java
Normal file
@ -0,0 +1,16 @@
|
||||
package SelfPropelledArtilleryUnit.Entities;
|
||||
import java.awt.Color;
|
||||
|
||||
public class EntitySPAUchild extends EntitySPAU{
|
||||
|
||||
public Color AdditionalColor;
|
||||
public boolean BodyKit;
|
||||
public boolean Ballone;
|
||||
|
||||
public EntitySPAUchild(int speed, double weight, Color bodyColor, Color additionalColor, boolean bodyKit, boolean ballone) {
|
||||
super(speed, weight, bodyColor); // Вызов конструктора суперкласса
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Ballone = ballone;
|
||||
}
|
||||
}
|
263
SelfPropelledArtilleryUnit/Form.java
Normal file
263
SelfPropelledArtilleryUnit/Form.java
Normal file
@ -0,0 +1,263 @@
|
||||
package SelfPropelledArtilleryUnit;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
|
||||
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAUchild;
|
||||
import SelfPropelledArtilleryUnit.MovementStrategy.AbstractStrategy;
|
||||
import SelfPropelledArtilleryUnit.MovementStrategy.DrawningObjectSPAU;
|
||||
import SelfPropelledArtilleryUnit.MovementStrategy.MoveToBorder;
|
||||
import SelfPropelledArtilleryUnit.MovementStrategy.MoveToCenter;
|
||||
import SelfPropelledArtilleryUnit.MovementStrategy.Status;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.ImageIcon;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
public class Form extends JFrame {
|
||||
|
||||
private JPanel mainPanel;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonCreateParent;
|
||||
private JButton buttonStep;
|
||||
private JComboBox<String> comboBoxStrategy;
|
||||
private JComboBox<String> comboBoxRoll;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
private JLabel pictureBoxSPAU;
|
||||
private DrawningSPAU drawningSPAU;
|
||||
private AbstractStrategy abstractStrategy;
|
||||
private JTextField wheelsTextField;
|
||||
private JLabel wheelsLabel;
|
||||
|
||||
public Form() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void Draw() {
|
||||
if (drawningSPAU == null) {
|
||||
return;
|
||||
}
|
||||
BufferedImage bmp = new BufferedImage(pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gr = bmp.createGraphics();
|
||||
drawningSPAU.DrawTransport(gr);
|
||||
ImageIcon imageIcon = new ImageIcon(bmp);
|
||||
pictureBoxSPAU.setIcon(imageIcon);
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
mainPanel = new JPanel();
|
||||
buttonCreate = new JButton("Создать c залповой установкой");
|
||||
buttonCreateParent = new JButton("Создать базовый");
|
||||
|
||||
buttonUp = new JButton(new ImageIcon("resources/upper_arrow.png"));
|
||||
buttonDown = new JButton(new ImageIcon("resources/down_arrow.png"));
|
||||
buttonLeft = new JButton(new ImageIcon("resources/left_arrow.png"));
|
||||
buttonRight = new JButton(new ImageIcon("resources/right_arrow.png"));
|
||||
pictureBoxSPAU = new JLabel();
|
||||
wheelsLabel = new JLabel("Количество колёс:");
|
||||
wheelsTextField = new JTextField();
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(mainPanel, BorderLayout.CENTER);
|
||||
mainPanel.setLayout(null);
|
||||
|
||||
pictureBoxSPAU.setBounds(0, 0, 882, 453);
|
||||
mainPanel.add(pictureBoxSPAU);
|
||||
|
||||
wheelsLabel.setBounds(22, 410, 150, 29);
|
||||
mainPanel.add(wheelsLabel);
|
||||
|
||||
wheelsTextField.setBounds(150, 410, 80, 29);
|
||||
mainPanel.add(wheelsTextField);
|
||||
|
||||
// buttonCreate
|
||||
buttonCreate.setBounds(250, 410, 250, 29);
|
||||
mainPanel.add(buttonCreate);
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
buttonCreateActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
// buttonCreateParent
|
||||
buttonCreateParent.setBounds(500, 409, 150, 30);
|
||||
mainPanel.add(buttonCreateParent);
|
||||
buttonCreateParent.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
buttonCreateParent_Click(e);
|
||||
}
|
||||
});
|
||||
|
||||
// buttonStep
|
||||
buttonStep = new JButton("Шаг");
|
||||
mainPanel.add(buttonStep);
|
||||
buttonStep.setBounds(794, 55, 76, 30);
|
||||
buttonStep.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
buttonStep_Click(e);
|
||||
}
|
||||
});
|
||||
|
||||
// comboBoxRoll
|
||||
|
||||
comboBoxRoll = new JComboBox<>();
|
||||
mainPanel.add(comboBoxRoll);
|
||||
comboBoxRoll.setModel(new DefaultComboBoxModel<>(new String[] { "1", "2", "3" }));
|
||||
comboBoxRoll.setBounds(767, 232, 103, 28);
|
||||
|
||||
// comboBoxStrategy
|
||||
comboBoxStrategy = new JComboBox<>();
|
||||
mainPanel.add(comboBoxStrategy);
|
||||
comboBoxStrategy.setModel(new DefaultComboBoxModel<>(new String[] { "0", "1" }));
|
||||
comboBoxStrategy.setBounds(767, 12, 103, 28);
|
||||
|
||||
buttonUp.setBounds(804, 336, 30, 30);
|
||||
mainPanel.add(buttonUp);
|
||||
ImageIcon iconUp = new ImageIcon("Arrows/upper-arrow.png");
|
||||
buttonUp.setIcon(iconUp);
|
||||
buttonUp.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
buttonMoveActionPerformed(buttonUp, e);
|
||||
}
|
||||
});
|
||||
|
||||
buttonDown.setBounds(804, 409, 30, 30);
|
||||
mainPanel.add(buttonDown);
|
||||
ImageIcon iconDown = new ImageIcon("Arrows/down-arrow.png");
|
||||
buttonDown.setIcon(iconDown);
|
||||
buttonDown.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
buttonMoveActionPerformed(buttonDown, e);
|
||||
}
|
||||
});
|
||||
|
||||
buttonLeft.setBounds(768, 372, 30, 30);
|
||||
mainPanel.add(buttonLeft);
|
||||
ImageIcon iconLeft = new ImageIcon("Arrows/left-arrow.png");
|
||||
buttonLeft.setIcon(iconLeft);
|
||||
buttonLeft.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
buttonMoveActionPerformed(buttonLeft, e);
|
||||
}
|
||||
});
|
||||
|
||||
buttonRight.setBounds(840, 372, 30, 30);
|
||||
mainPanel.add(buttonRight);
|
||||
ImageIcon iconRight = new ImageIcon("Arrows/right-arrow.png");
|
||||
buttonRight.setIcon(iconRight);
|
||||
buttonRight.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
buttonMoveActionPerformed(buttonRight, e);
|
||||
}
|
||||
});
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
setPreferredSize(new Dimension(882, 453));
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
pack();
|
||||
}
|
||||
|
||||
protected void buttonCreateActionPerformed(ActionEvent e) {
|
||||
int wheelCount;
|
||||
try {
|
||||
wheelCount = Integer.parseInt(wheelsTextField.getText());
|
||||
} catch (NumberFormatException ex) {
|
||||
wheelCount = 0;
|
||||
}
|
||||
|
||||
if (wheelCount > 0) {
|
||||
Random random = new Random();
|
||||
drawningSPAU = new DrawningSPAUchild(wheelCount, Integer.parseInt((String) comboBoxRoll.getSelectedItem()), random.nextInt(200) + 100,
|
||||
(double) 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)),
|
||||
true, true,
|
||||
pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
|
||||
drawningSPAU.SetPosition(random.nextInt(90) + 20, random.nextInt(90) + 20);
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
protected void buttonCreateParent_Click(ActionEvent e) {
|
||||
int wheelCount;
|
||||
try {
|
||||
wheelCount = Integer.parseInt(wheelsTextField.getText());
|
||||
} catch (NumberFormatException ex) {
|
||||
wheelCount = 0;
|
||||
}
|
||||
|
||||
if (wheelCount > 0) {
|
||||
Random random = new Random();
|
||||
drawningSPAU = new DrawningSPAU(wheelCount, Integer.parseInt((String) comboBoxRoll.getSelectedItem()), random.nextInt(200) + 100,
|
||||
(double) random.nextInt(2000) + 1000,
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
|
||||
drawningSPAU.SetPosition(random.nextInt(90) + 20, random.nextInt(90) + 20);
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
protected void buttonStep_Click (ActionEvent e) {
|
||||
if (drawningSPAU == null) {
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
int selectedIndex = comboBoxStrategy.getSelectedIndex();
|
||||
switch (selectedIndex) {
|
||||
case 0:
|
||||
abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
abstractStrategy = null;
|
||||
break;
|
||||
}
|
||||
if (abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
abstractStrategy.setData(new DrawningObjectSPAU(drawningSPAU), pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
abstractStrategy.makeStep();
|
||||
Draw();
|
||||
if (abstractStrategy.getStatus() == Status.Finish) {
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void buttonMoveActionPerformed(Object sender, ActionEvent e) {
|
||||
if (drawningSPAU == null) {
|
||||
return;
|
||||
}
|
||||
String name = (sender instanceof JButton) ? ((JButton) sender).getName() : "";
|
||||
switch (name) {
|
||||
case "buttonUp":
|
||||
drawningSPAU.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
drawningSPAU.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
drawningSPAU.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
drawningSPAU.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package SelfPropelledArtilleryUnit.MovementStrategy;
|
||||
|
||||
import SelfPropelledArtilleryUnit.DirectionType;
|
||||
|
||||
/**
|
||||
* Класс-стратегия перемещения объекта
|
||||
*/
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/**
|
||||
* Перемещаемый объект
|
||||
*/
|
||||
private IMoveableObject moveableObject;
|
||||
|
||||
/**
|
||||
* Статус перемещения
|
||||
*/
|
||||
private Status state = Status.NotInit;
|
||||
|
||||
/**
|
||||
* Ширина поля
|
||||
*/
|
||||
private int fieldWidth;
|
||||
|
||||
/**
|
||||
* Высота поля
|
||||
*/
|
||||
private int fieldHeight;
|
||||
|
||||
/**
|
||||
* Статус перемещения
|
||||
*/
|
||||
public Status getStatus() { return state; }
|
||||
|
||||
/**
|
||||
* Получить ширину поля
|
||||
*/
|
||||
protected int getFieldWidth() { return fieldWidth; }
|
||||
|
||||
/**
|
||||
* Получить высоту поля
|
||||
*/
|
||||
protected int getFieldHeight() { return fieldHeight; }
|
||||
|
||||
/**
|
||||
* Установка данных
|
||||
* @param moveableObject Перемещаемый объект
|
||||
* @param width Ширина поля
|
||||
* @param height Высота поля
|
||||
*/
|
||||
public void setData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
state = Status.InProgress;
|
||||
this.moveableObject = moveableObject;
|
||||
this.fieldWidth = width;
|
||||
this.fieldHeight = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Шаг перемещения
|
||||
*/
|
||||
public void makeStep()
|
||||
{
|
||||
if (state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (isTargetDestination())
|
||||
{
|
||||
state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
moveToTarget();
|
||||
}
|
||||
|
||||
/**
|
||||
* Перемещение влево
|
||||
* @return Результат перемещения (true - удалось переместиться, false - неудача)
|
||||
*/
|
||||
protected boolean moveLeft() { return moveTo(DirectionType.Left); }
|
||||
|
||||
/**
|
||||
* Перемещение вправо
|
||||
* @return Результат перемещения (true - удалось переместиться, false - неудача)
|
||||
*/
|
||||
protected boolean moveRight() { return moveTo(DirectionType.Right); }
|
||||
|
||||
/**
|
||||
* Перемещение вверх
|
||||
* @return Результат перемещения (true - удалось переместиться, false - неудача)
|
||||
*/
|
||||
protected boolean moveUp() { return moveTo(DirectionType.Up); }
|
||||
|
||||
/**
|
||||
* Перемещение вниз
|
||||
* @return Результат перемещения (true - удалось переместиться, false - неудача)
|
||||
*/
|
||||
protected boolean moveDown() { return moveTo(DirectionType.Down); }
|
||||
|
||||
/**
|
||||
* Параметры объекта
|
||||
* @return Объект ObjectParameters
|
||||
*/
|
||||
protected ObjectParameters getObjectParameters() { return moveableObject != null ? moveableObject.getObjectPosition() : null; }
|
||||
|
||||
/**
|
||||
* Шаг объекта
|
||||
* @return Шаг объекта
|
||||
*/
|
||||
protected Integer getStep()
|
||||
{
|
||||
if (state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return moveableObject != null ? moveableObject.getStep() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Перемещение к цели
|
||||
*/
|
||||
protected abstract void moveToTarget();
|
||||
|
||||
/**
|
||||
* Достигнута ли цель
|
||||
* @return true если цель достигнута
|
||||
*/
|
||||
protected abstract boolean isTargetDestination();
|
||||
|
||||
/**
|
||||
* Попытка перемещения в требуемом направлении
|
||||
* @param directionType Направление
|
||||
* @return Результат попытки (true - удалось переместиться, false - неудача)
|
||||
*/
|
||||
private boolean moveTo(DirectionType directionType)
|
||||
{
|
||||
if (state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (moveableObject != null && moveableObject.checkCanMove(directionType))
|
||||
{
|
||||
moveableObject.moveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package SelfPropelledArtilleryUnit.MovementStrategy;
|
||||
|
||||
import SelfPropelledArtilleryUnit.DirectionType;
|
||||
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
|
||||
|
||||
/**
|
||||
* Класс-стратегия перемещения объекта, реализация интерфейса IMoveableObject
|
||||
* для работы с объектом DrawningCar (паттерн Adapter)
|
||||
*/
|
||||
public class DrawningObjectSPAU implements IMoveableObject {
|
||||
|
||||
private final DrawningSPAU drawningCar;
|
||||
|
||||
public DrawningObjectSPAU(DrawningSPAU drawningCar) {
|
||||
this.drawningCar = drawningCar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectParameters getObjectPosition() {
|
||||
if (drawningCar == null || drawningCar.getEntitySPAU() == null) {
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(drawningCar.getPosX(),
|
||||
drawningCar.getPosY(),
|
||||
drawningCar.getWidth(),
|
||||
drawningCar.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStep() {
|
||||
return drawningCar != null && drawningCar.getEntitySPAU() != null
|
||||
? (int) drawningCar.getEntitySPAU().getStep()
|
||||
: 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkCanMove(DirectionType direction) {
|
||||
return drawningCar != null && drawningCar.CanMove(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveObject(DirectionType direction) {
|
||||
if (drawningCar != null) {
|
||||
drawningCar.MoveTransport(direction);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package SelfPropelledArtilleryUnit.MovementStrategy;
|
||||
|
||||
import SelfPropelledArtilleryUnit.DirectionType;
|
||||
|
||||
public interface IMoveableObject {
|
||||
/**
|
||||
* Получение координаты X объекта
|
||||
* @return координаты объекта
|
||||
*/
|
||||
ObjectParameters getObjectPosition();
|
||||
|
||||
/**
|
||||
* Получение шага объекта
|
||||
* @return шаг объекта
|
||||
*/
|
||||
int getStep();
|
||||
|
||||
/**
|
||||
* Проверка, можно ли переместиться по нужному направлению
|
||||
* @param direction направление
|
||||
* @return true, если можно переместиться, иначе false
|
||||
*/
|
||||
boolean checkCanMove(DirectionType direction);
|
||||
|
||||
/**
|
||||
* Изменение направления перемещения объекта
|
||||
* @param direction направление
|
||||
*/
|
||||
void moveObject(DirectionType direction);
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package SelfPropelledArtilleryUnit.MovementStrategy;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy {
|
||||
|
||||
@Override
|
||||
protected boolean isTargetDestination() {
|
||||
ObjectParameters objParams = getObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return objParams.getRightBorder() <= getFieldWidth() &&
|
||||
objParams.getRightBorder() + getStep() >= getFieldWidth() &&
|
||||
objParams.getDownBorder() <= getFieldHeight() &&
|
||||
objParams.getDownBorder() + getStep() >= getFieldHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveToTarget() {
|
||||
ObjectParameters objParams = getObjectParameters();
|
||||
if (objParams == null) {
|
||||
return;
|
||||
}
|
||||
double diffX = objParams.getRightBorder() - getFieldWidth();
|
||||
if (Math.abs(diffX) > getStep()) {
|
||||
if (diffX > 0) {
|
||||
moveLeft();
|
||||
} else {
|
||||
moveRight();
|
||||
}
|
||||
}
|
||||
double diffY = objParams.getDownBorder() - getFieldHeight();
|
||||
if (Math.abs(diffY) > getStep()) {
|
||||
if (diffY > 0) {
|
||||
moveUp();
|
||||
} else {
|
||||
moveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package SelfPropelledArtilleryUnit.MovementStrategy;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy {
|
||||
|
||||
@Override
|
||||
protected boolean isTargetDestination() {
|
||||
ObjectParameters objParams = getObjectParameters();
|
||||
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() {
|
||||
ObjectParameters objParams = getObjectParameters();
|
||||
if (objParams == null) {
|
||||
return;
|
||||
}
|
||||
double diffX = objParams.getObjectMiddleHorizontal() - getFieldWidth() / 2;
|
||||
if (Math.abs(diffX) > getStep()) {
|
||||
if (diffX > 0) {
|
||||
moveLeft();
|
||||
} else {
|
||||
moveRight();
|
||||
}
|
||||
}
|
||||
double diffY = objParams.getObjectMiddleVertical() - getFieldHeight() / 2;
|
||||
if (Math.abs(diffY) > getStep()) {
|
||||
if (diffY > 0) {
|
||||
moveUp();
|
||||
} else {
|
||||
moveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package SelfPropelledArtilleryUnit.MovementStrategy;
|
||||
|
||||
public class ObjectParameters {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
/**
|
||||
* Левая граница
|
||||
* @return координата X
|
||||
*/
|
||||
public int getLeftBorder() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Верхняя граница
|
||||
* @return координата Y
|
||||
*/
|
||||
public int getTopBorder() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Правая граница
|
||||
* @return координата X + ширина
|
||||
*/
|
||||
public int getRightBorder() {
|
||||
return x + width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Нижняя граница
|
||||
* @return координата Y + высота
|
||||
*/
|
||||
public int getDownBorder() {
|
||||
return y + height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Середина объекта
|
||||
* @return координата X + ширина / 2
|
||||
*/
|
||||
public int getObjectMiddleHorizontal() {
|
||||
return x + width / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Середина объекта
|
||||
* @return координата Y + высота / 2
|
||||
*/
|
||||
public int getObjectMiddleVertical() {
|
||||
return y + height / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
* @param x координата X
|
||||
* @param y координата Y
|
||||
* @param width ширина
|
||||
* @param height высота
|
||||
*/
|
||||
public ObjectParameters(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
7
SelfPropelledArtilleryUnit/MovementStrategy/Status.java
Normal file
7
SelfPropelledArtilleryUnit/MovementStrategy/Status.java
Normal file
@ -0,0 +1,7 @@
|
||||
package SelfPropelledArtilleryUnit.MovementStrategy;
|
||||
|
||||
public enum Status {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
28
SelfPropelledArtilleryUnit/NumbeRollers.java
Normal file
28
SelfPropelledArtilleryUnit/NumbeRollers.java
Normal file
@ -0,0 +1,28 @@
|
||||
package SelfPropelledArtilleryUnit;
|
||||
public enum NumbeRollers {
|
||||
Min(4),
|
||||
Mid(5),
|
||||
Max(6);
|
||||
|
||||
private final int NumbeRollersCode;
|
||||
|
||||
private NumbeRollers(int NumbeRollersCode) {
|
||||
this.NumbeRollersCode = NumbeRollersCode;
|
||||
}
|
||||
|
||||
public int getNumbeRollersCode() {
|
||||
return this.NumbeRollersCode;
|
||||
}
|
||||
|
||||
public static NumbeRollers fromNumberToEnum(int number) {
|
||||
try{
|
||||
for (NumbeRollers numbeRoller : NumbeRollers.values()) {
|
||||
if (numbeRoller.getNumbeRollersCode() == number) {
|
||||
return numbeRoller;
|
||||
}
|
||||
}
|
||||
}catch(NumberFormatException e){
|
||||
}
|
||||
return Min;
|
||||
}
|
||||
}
|
12
SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.java
Normal file
12
SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.java
Normal file
@ -0,0 +1,12 @@
|
||||
package SelfPropelledArtilleryUnit;
|
||||
import javax.swing.*;
|
||||
|
||||
public class SelfPropelledArtilleryUnit {
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
Form form = new Form();
|
||||
form.setSize(900, 500);
|
||||
form.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user