lab2
This commit is contained in:
parent
a919a51967
commit
845860c3dc
82
src/AbstractStrategy.java
Normal file
82
src/AbstractStrategy.java
Normal file
@ -0,0 +1,82 @@
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject _moveableObject;
|
||||
private Status _state = Status.NotInit;
|
||||
protected int FieldWidth;
|
||||
protected int FieldHeight;
|
||||
public Status GetStatus() { return _state; }
|
||||
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
protected boolean MoveLeft(){
|
||||
return MoveTo(DyrectionType.Left);
|
||||
}
|
||||
|
||||
protected boolean MoveRight(){
|
||||
return MoveTo(DyrectionType.Right);
|
||||
}
|
||||
|
||||
protected boolean MoveUp(){
|
||||
return MoveTo(DyrectionType.Up);
|
||||
}
|
||||
|
||||
protected boolean MoveDown(){
|
||||
return MoveTo(DyrectionType.Down);
|
||||
}
|
||||
|
||||
/// Параметры объекта
|
||||
protected ObjectParameters GetObjectParameters(){
|
||||
if(_moveableObject == null) return null;
|
||||
return _moveableObject.GetObjectPosition();
|
||||
}
|
||||
|
||||
protected int GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(_moveableObject == null) return -1;
|
||||
return _moveableObject.GetStep();
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
protected abstract boolean IsTargetDestinaion();
|
||||
|
||||
private boolean MoveTo(DyrectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.CheckCanMove(directionType) == false) return false;
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
26
src/DrawingEmptyWheels.java
Normal file
26
src/DrawingEmptyWheels.java
Normal file
@ -0,0 +1,26 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingEmptyWheels implements IDrawingWheels{
|
||||
private WheelsCount _wheelsCount;
|
||||
@Override
|
||||
public void SetWheelsCount(int wheelsCount) {
|
||||
for (WheelsCount val : WheelsCount.values()) {
|
||||
if (val.count == wheelsCount) {
|
||||
_wheelsCount = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._wheelsCount = WheelsCount.Five;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WheelsCount GetWheelsCount() {
|
||||
return _wheelsCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(x, y, w, h);
|
||||
}
|
||||
}
|
28
src/DrawingObjectUsta.java
Normal file
28
src/DrawingObjectUsta.java
Normal file
@ -0,0 +1,28 @@
|
||||
public class DrawingObjectUsta implements IMoveableObject {
|
||||
private DrawingUsta _drawningUsta = null;
|
||||
public DrawingObjectUsta(DrawingUsta drawningUsta)
|
||||
{
|
||||
_drawningUsta = drawningUsta;
|
||||
}
|
||||
public ObjectParameters GetObjectPosition()
|
||||
{
|
||||
if (_drawningUsta == null || _drawningUsta.EntityUsta == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningUsta.GetPosX(), _drawningUsta.GetPosY(),
|
||||
_drawningUsta.GetWidth(), _drawningUsta.GetHeight());
|
||||
}
|
||||
public int GetStep(){
|
||||
if(_drawningUsta == null) return -1;
|
||||
return (int)(_drawningUsta.EntityUsta.Step());
|
||||
}
|
||||
public boolean CheckCanMove(DyrectionType direction){
|
||||
if(_drawningUsta == null) return false;
|
||||
return _drawningUsta.CanMove(direction);
|
||||
}
|
||||
public void MoveObject(DyrectionType direction){
|
||||
if(_drawningUsta == null) return;
|
||||
_drawningUsta.MoveTransport(direction);
|
||||
}
|
||||
}
|
@ -1,37 +1,68 @@
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Arc2D;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingUsta {
|
||||
public EntityUsta EntityUsta;
|
||||
private DrawingWheel _drawingWheel;
|
||||
protected IDrawingWheels _drawingWheels;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
private final int _ustaWidth = 170;
|
||||
private final int _ustaHeight = 90;
|
||||
public int _startPosX;
|
||||
public int _startPosY;
|
||||
private int _ustaWidth = 170;
|
||||
private int _ustaHeight = 90;
|
||||
|
||||
public boolean Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean bodyKit, boolean pushka, int width, int height)
|
||||
public int GetPosX(){
|
||||
return _startPosX;
|
||||
}
|
||||
public int GetPosY(){
|
||||
return _startPosY;
|
||||
}
|
||||
public int GetWidth(){
|
||||
return _ustaWidth;
|
||||
}
|
||||
public int GetHeight(){
|
||||
return _ustaHeight;
|
||||
}
|
||||
|
||||
public DrawingUsta(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
|
||||
if (width < _ustaWidth || height < _ustaHeight)
|
||||
{
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityUsta = new EntityUsta();
|
||||
_drawingWheel = new DrawingWheel();
|
||||
EntityUsta.Init(speed, weight, bodyColor, additionalColor, bodyKit, pushka);
|
||||
return true;
|
||||
EntityUsta = new EntityUsta(speed, weight, bodyColor);
|
||||
|
||||
Random rnd = new Random();
|
||||
int WhatWheels = rnd.nextInt(0, 3);
|
||||
|
||||
if(WhatWheels == 0) _drawingWheels = new DrawingWheel();
|
||||
if(WhatWheels == 1) _drawingWheels = new DrawingEmptyWheels();
|
||||
if(WhatWheels == 2) _drawingWheels = new DrawingWheelsBlueCrom();
|
||||
}
|
||||
|
||||
public void SetWheelsCount(int weelsCount) {
|
||||
|
||||
_drawingWheel.SetWheelsCount(weelsCount);
|
||||
public void SetWheelsCount(int wheelsCount){
|
||||
_drawingWheels.SetWheelsCount(wheelsCount);
|
||||
}
|
||||
|
||||
protected DrawingUsta(int speed, double weight, Color bodyColor, int width,
|
||||
int height, int ustaWidth, int ustaHeight)
|
||||
{
|
||||
this(speed,weight, bodyColor, width, height);
|
||||
if (width < _ustaWidth || height < _ustaHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_ustaWidth = ustaWidth;
|
||||
_ustaHeight = ustaHeight;
|
||||
}
|
||||
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x + _ustaWidth > _pictureWidth)
|
||||
@ -72,11 +103,7 @@ public class DrawingUsta {
|
||||
if (EntityUsta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Color bodyColor = EntityUsta.BodyColor;
|
||||
Color additionalColor = EntityUsta.AdditionalColor;
|
||||
|
||||
Color blackBrush = Color.BLACK;
|
||||
|
||||
@ -85,146 +112,56 @@ public class DrawingUsta {
|
||||
|
||||
int cornerRadius1 = 12;
|
||||
|
||||
_drawingWheel.DrawWheels(g, additionalColor, _startPosX, _startPosY);
|
||||
Path2D path = new Path2D.Double();
|
||||
|
||||
g.setColor(color1);
|
||||
path.append(new Arc2D.Double(_startPosX + 5, _startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 180, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(_startPosX + 140, _startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 270, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(_startPosX + 140, _startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 0, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(_startPosX + 5, _startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 90, 90, Arc2D.OPEN), true);
|
||||
path.closePath();
|
||||
g.setColor(bodyColor);
|
||||
g.fill(path);
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(path);
|
||||
|
||||
_drawingWheels.DrawWheels(g, blackBrush, _startPosX, _startPosY, 9,9);
|
||||
|
||||
g.setColor(bodyColor);
|
||||
g.fillRect(_startPosX + 45, _startPosY + 20, 40, 20);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 45, _startPosY + 20, 40, 20);
|
||||
|
||||
|
||||
|
||||
g.setColor(color1);
|
||||
|
||||
g.setColor(bodyColor);
|
||||
g.fillRect(_startPosX + 10, _startPosY + 40, 120, 10);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 10, _startPosY + 40, 120, 10);
|
||||
if(EntityUsta.BodyKit)
|
||||
{
|
||||
Path2D path1 = new Path2D.Double();
|
||||
path1.moveTo(_startPosX + 15, _startPosY + 40);
|
||||
path1.lineTo(_startPosX + 15, _startPosY + 30);
|
||||
path1.lineTo(_startPosX + 15, _startPosY + 35);
|
||||
path1.lineTo(_startPosX + 25, _startPosY + 35);
|
||||
path1.lineTo(_startPosX + 30, _startPosY + 30);
|
||||
path1.lineTo(_startPosX + 35, _startPosY + 40);
|
||||
path1.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path1);
|
||||
|
||||
g.setColor(color2);
|
||||
g.fill(path1);
|
||||
|
||||
Path2D path2 = new Path2D.Double();
|
||||
path2.moveTo(_startPosX + 15, _startPosY + 30);
|
||||
path2.lineTo(_startPosX + 40, _startPosY + 20);
|
||||
path2.lineTo(_startPosX + 40, _startPosY + 25);
|
||||
path2.lineTo(_startPosX + 25, _startPosY + 35);
|
||||
path2.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(path2);
|
||||
|
||||
g.setColor(additionalColor);
|
||||
g.fill(path2);
|
||||
|
||||
Path2D path3 = new Path2D.Double();
|
||||
path3.moveTo(_startPosX + 10, _startPosY + 32);
|
||||
path3.lineTo(_startPosX, _startPosY + 10);
|
||||
path3.lineTo(_startPosX + 40, _startPosY - 7);
|
||||
path3.lineTo(_startPosX + 50, _startPosY + 16);
|
||||
path3.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(path3);
|
||||
|
||||
g.setColor(bodyColor);
|
||||
g.fill(path3);
|
||||
|
||||
Path2D path4 = new Path2D.Double();
|
||||
path4.moveTo(_startPosX, _startPosY + 10);
|
||||
path4.lineTo(_startPosX + 40, _startPosY - 7);
|
||||
path4.lineTo(_startPosX + 43, _startPosY - 5);
|
||||
path4.lineTo(_startPosX + 41, _startPosY - 3);
|
||||
path4.lineTo(_startPosX + 2, _startPosY + 13);
|
||||
path4.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path4);
|
||||
|
||||
g.setColor(additionalColor);
|
||||
g.fill(path4);
|
||||
|
||||
Path2D path5 = new Path2D.Double();
|
||||
path5.moveTo(_startPosX + 3, _startPosY + 15);
|
||||
path5.lineTo(_startPosX + 45, _startPosY - 2);
|
||||
path5.lineTo(_startPosX + 46, _startPosY - 2);
|
||||
path5.lineTo(_startPosX + 49, _startPosY - 1);
|
||||
path5.lineTo(_startPosX + 46, _startPosY + 3);
|
||||
path5.lineTo(_startPosX + 6, _startPosY + 20);
|
||||
path5.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path5);
|
||||
|
||||
g.setColor(bodyColor);
|
||||
g.fill(path5);
|
||||
|
||||
Path2D path6 = new Path2D.Double();
|
||||
path6.moveTo(_startPosX + 5, _startPosY + 22);
|
||||
path6.lineTo(_startPosX + 47, _startPosY + 5);
|
||||
path6.lineTo(_startPosX + 51, _startPosY + 5);
|
||||
path6.lineTo(_startPosX + 53, _startPosY + 7);
|
||||
path6.lineTo(_startPosX + 8, _startPosY + 25);
|
||||
path6.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path6);
|
||||
|
||||
g.setColor(additionalColor);
|
||||
g.fill(path6);
|
||||
|
||||
Path2D path7 = new Path2D.Double();
|
||||
path7.moveTo(_startPosX + 7, _startPosY + 27);
|
||||
path7.lineTo(_startPosX + 46, _startPosY + 11);
|
||||
path7.lineTo(_startPosX + 51, _startPosY + 9);
|
||||
path7.lineTo(_startPosX + 56, _startPosY + 11);
|
||||
path7.lineTo(_startPosX + 10, _startPosY + 31);
|
||||
path7.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path7);
|
||||
|
||||
g.setColor(bodyColor);
|
||||
g.fill(path7);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(EntityUsta.Pushka)
|
||||
{
|
||||
g.fillRect(_startPosX + 80, _startPosY + 25, 10, 10);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 80, _startPosY + 25, 10, 10);
|
||||
g.setColor(color1);
|
||||
g.fillRect(_startPosX + 90, _startPosY + 28, 40, 5);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 90, _startPosY + 28, 40, 5);
|
||||
g.setColor(additionalColor);
|
||||
g.fillRect(_startPosX + 130, _startPosY + 27, 5, 7);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 130, _startPosY + 27, 5, 7);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean CanMove(DyrectionType direction)
|
||||
{
|
||||
if (EntityUsta == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch(direction) {
|
||||
//влево
|
||||
case Left:
|
||||
if (_startPosX - EntityUsta.Step() > 0) return true;
|
||||
break;
|
||||
case Up:
|
||||
if (_startPosY - EntityUsta.Step() > 0) return true;
|
||||
break;
|
||||
case Right:
|
||||
if (_startPosX + EntityUsta.Step() < _pictureWidth) return true;
|
||||
break;
|
||||
case Down:
|
||||
if (_startPosY + EntityUsta.Step() < _pictureHeight) return true;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
157
src/DrawingUstaBat.java
Normal file
157
src/DrawingUstaBat.java
Normal file
@ -0,0 +1,157 @@
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Path2D;
|
||||
|
||||
public class DrawingUstaBat extends DrawingUsta {
|
||||
public DrawingUstaBat(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean pushka, boolean bodyKit, int width, int height)
|
||||
{
|
||||
super(speed, weight, bodyColor, width, height, 170, 90);
|
||||
if (EntityUsta != null)
|
||||
{
|
||||
EntityUsta = new EntityUstaBat(speed, width, bodyColor, additionalColor, pushka, bodyKit);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
if (EntityUsta instanceof EntityUstaBat ustabat) ///////// WARNING INSTANCEOF
|
||||
{
|
||||
Color bodyColor = EntityUsta.BodyColor;
|
||||
Color additionalColor = ustabat.AdditionalColor;
|
||||
|
||||
Color blackBrush = Color.BLACK;
|
||||
|
||||
Color color1 = new Color(65, 72, 51);
|
||||
Color color2 = new Color(47, 69, 56);
|
||||
|
||||
if(ustabat.BodyKit)
|
||||
{
|
||||
Path2D path1 = new Path2D.Double();
|
||||
path1.moveTo(_startPosX + 15, _startPosY + 40);
|
||||
path1.lineTo(_startPosX + 15, _startPosY + 30);
|
||||
path1.lineTo(_startPosX + 15, _startPosY + 35);
|
||||
path1.lineTo(_startPosX + 25, _startPosY + 35);
|
||||
path1.lineTo(_startPosX + 30, _startPosY + 30);
|
||||
path1.lineTo(_startPosX + 35, _startPosY + 40);
|
||||
path1.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path1);
|
||||
|
||||
g.setColor(color2);
|
||||
g.fill(path1);
|
||||
|
||||
Path2D path2 = new Path2D.Double();
|
||||
path2.moveTo(_startPosX + 15, _startPosY + 30);
|
||||
path2.lineTo(_startPosX + 40, _startPosY + 20);
|
||||
path2.lineTo(_startPosX + 40, _startPosY + 25);
|
||||
path2.lineTo(_startPosX + 25, _startPosY + 35);
|
||||
path2.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(path2);
|
||||
|
||||
g.setColor(additionalColor);
|
||||
g.fill(path2);
|
||||
|
||||
Path2D path3 = new Path2D.Double();
|
||||
path3.moveTo(_startPosX + 10, _startPosY + 32);
|
||||
path3.lineTo(_startPosX, _startPosY + 10);
|
||||
path3.lineTo(_startPosX + 40, _startPosY - 7);
|
||||
path3.lineTo(_startPosX + 50, _startPosY + 16);
|
||||
path3.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(path3);
|
||||
|
||||
g.setColor(bodyColor);
|
||||
g.fill(path3);
|
||||
|
||||
Path2D path4 = new Path2D.Double();
|
||||
path4.moveTo(_startPosX, _startPosY + 10);
|
||||
path4.lineTo(_startPosX + 40, _startPosY - 7);
|
||||
path4.lineTo(_startPosX + 43, _startPosY - 5);
|
||||
path4.lineTo(_startPosX + 41, _startPosY - 3);
|
||||
path4.lineTo(_startPosX + 2, _startPosY + 13);
|
||||
path4.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path4);
|
||||
|
||||
g.setColor(additionalColor);
|
||||
g.fill(path4);
|
||||
|
||||
Path2D path5 = new Path2D.Double();
|
||||
path5.moveTo(_startPosX + 3, _startPosY + 15);
|
||||
path5.lineTo(_startPosX + 45, _startPosY - 2);
|
||||
path5.lineTo(_startPosX + 46, _startPosY - 2);
|
||||
path5.lineTo(_startPosX + 49, _startPosY - 1);
|
||||
path5.lineTo(_startPosX + 46, _startPosY + 3);
|
||||
path5.lineTo(_startPosX + 6, _startPosY + 20);
|
||||
path5.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path5);
|
||||
|
||||
g.setColor(bodyColor);
|
||||
g.fill(path5);
|
||||
|
||||
Path2D path6 = new Path2D.Double();
|
||||
path6.moveTo(_startPosX + 5, _startPosY + 22);
|
||||
path6.lineTo(_startPosX + 47, _startPosY + 5);
|
||||
path6.lineTo(_startPosX + 51, _startPosY + 5);
|
||||
path6.lineTo(_startPosX + 53, _startPosY + 7);
|
||||
path6.lineTo(_startPosX + 8, _startPosY + 25);
|
||||
path6.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path6);
|
||||
|
||||
g.setColor(additionalColor);
|
||||
g.fill(path6);
|
||||
|
||||
Path2D path7 = new Path2D.Double();
|
||||
path7.moveTo(_startPosX + 7, _startPosY + 27);
|
||||
path7.lineTo(_startPosX + 46, _startPosY + 11);
|
||||
path7.lineTo(_startPosX + 51, _startPosY + 9);
|
||||
path7.lineTo(_startPosX + 56, _startPosY + 11);
|
||||
path7.lineTo(_startPosX + 10, _startPosY + 31);
|
||||
path7.closePath();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
g.draw(path7);
|
||||
|
||||
g.setColor(bodyColor);
|
||||
g.fill(path7);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(ustabat.Pushka)
|
||||
{
|
||||
g.fillRect(_startPosX + 80, _startPosY + 25, 10, 10);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 80, _startPosY + 25, 10, 10);
|
||||
g.setColor(color1);
|
||||
g.fillRect(_startPosX + 90, _startPosY + 28, 40, 5);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 90, _startPosY + 28, 40, 5);
|
||||
g.setColor(additionalColor);
|
||||
g.fillRect(_startPosX + 130, _startPosY + 27, 5, 7);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_startPosX + 130, _startPosY + 27, 5, 7);
|
||||
}
|
||||
super.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ import java.awt.*;
|
||||
import java.awt.geom.Arc2D;
|
||||
import java.awt.geom.Path2D;
|
||||
|
||||
public class DrawingWheel {
|
||||
public class DrawingWheel implements IDrawingWheels {
|
||||
private WheelsCount _wheelsCount;
|
||||
public void SetWheelsCount(int enginesCount) {
|
||||
for (WheelsCount val : WheelsCount.values()) {
|
||||
@ -11,130 +11,16 @@ public class DrawingWheel {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._wheelsCount = WheelsCount.Five;
|
||||
}
|
||||
|
||||
public void DrawWheels(Graphics2D g, Color color, int startPosX, int startPosY) {
|
||||
if (_wheelsCount == null) {
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public WheelsCount GetWheelsCount() {
|
||||
return _wheelsCount;
|
||||
}
|
||||
|
||||
int cornerRadius1 = 12;
|
||||
Color color1 = new Color(65, 72, 51);
|
||||
|
||||
if (_wheelsCount.count >= _wheelsCount.Four.count) {
|
||||
|
||||
Path2D path = new Path2D.Double();
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 5, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 180, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 110, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 270, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 110, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 0, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 5, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 90, 90, Arc2D.OPEN), true);
|
||||
path.closePath();
|
||||
|
||||
g.setColor(color1);
|
||||
|
||||
g.fill(path);
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(path);
|
||||
|
||||
|
||||
/* наверху гусеницы*/
|
||||
g.fillOval(startPosX + 47, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 62, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 77, startPosY + 44, 13, 13);
|
||||
|
||||
/* по середине гусеницы*/
|
||||
g.drawOval(startPosX + 40, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 55, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 70, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 85, startPosY + 59, 13, 13);
|
||||
|
||||
|
||||
/* два крайних на гусенице*/
|
||||
g.fillOval(startPosX + 10, startPosY + 50, 25, 25);
|
||||
g.fillOval(startPosX + 105, startPosY + 50, 25, 25);
|
||||
|
||||
}
|
||||
|
||||
if (_wheelsCount.count >= _wheelsCount.Five.count) {
|
||||
Path2D path = new Path2D.Double();
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 5, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 180, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 125, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 270, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 125, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 0, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 5, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 90, 90, Arc2D.OPEN), true);
|
||||
path.closePath();
|
||||
|
||||
g.setColor(color1);
|
||||
|
||||
g.fill(path);
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(path);
|
||||
|
||||
|
||||
/* наверху гусеницы*/
|
||||
g.fillOval(startPosX + 47, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 62, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 77, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 92, startPosY + 44, 13, 13);
|
||||
|
||||
/* по середине гусеницы*/
|
||||
g.drawOval(startPosX + 40, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 55, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 70, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 85, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 100, startPosY + 59, 13, 13);
|
||||
|
||||
|
||||
/* два крайних на гусенице*/
|
||||
g.fillOval(startPosX + 10, startPosY + 50, 25, 25);
|
||||
g.fillOval(startPosX + 120, startPosY + 50, 25, 25);
|
||||
}
|
||||
|
||||
if (_wheelsCount.count >= _wheelsCount.Six.count) {
|
||||
Path2D path = new Path2D.Double();
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 5, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 180, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 140, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 270, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 140, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 0, 90, Arc2D.OPEN), true);
|
||||
|
||||
path.append(new Arc2D.Double(startPosX + 5, startPosY + 50, 2 * cornerRadius1, 2 * cornerRadius1, 90, 90, Arc2D.OPEN), true);
|
||||
path.closePath();
|
||||
|
||||
g.setColor(color1);
|
||||
|
||||
g.fill(path);
|
||||
g.setColor(Color.BLACK);
|
||||
g.draw(path);
|
||||
|
||||
|
||||
/* наверху гусеницы*/
|
||||
g.fillOval(startPosX + 47, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 62, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 77, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 92, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 107, startPosY + 44, 13, 13);
|
||||
|
||||
/* по середине гусеницы*/
|
||||
g.drawOval(startPosX + 40, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 55, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 70, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 85, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 100, startPosY + 59, 13, 13);
|
||||
g.drawOval(startPosX + 115, startPosY + 59, 13, 13);
|
||||
|
||||
|
||||
/* два крайних на гусенице*/
|
||||
g.fillOval(startPosX + 10, startPosY + 50, 25, 25);
|
||||
g.fillOval(startPosX + 135, startPosY + 50, 25, 25);
|
||||
}
|
||||
public void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.fillOval(x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
33
src/DrawingWheelsBlueCrom.java
Normal file
33
src/DrawingWheelsBlueCrom.java
Normal file
@ -0,0 +1,33 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingWheelsBlueCrom implements IDrawingWheels{
|
||||
private WheelsCount _wheelsCount;
|
||||
@Override
|
||||
public void SetWheelsCount(int wheelsCount) {
|
||||
for (WheelsCount val : WheelsCount.values()) {
|
||||
if (val.count == wheelsCount) {
|
||||
_wheelsCount = val;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._wheelsCount = WheelsCount.Five;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WheelsCount GetWheelsCount() {
|
||||
return _wheelsCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||
g2d.setColor(Color.GRAY);
|
||||
g2d.drawOval(x, y + 3, w-5, h-5);
|
||||
g2d.setColor(Color.GREEN);
|
||||
g2d.drawOval(x - 2, y - 2, w, h);
|
||||
g2d.setColor(Color.WHITE);
|
||||
g2d.drawOval(x + 3, y, w - 10, h - 10);
|
||||
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawOval(x, y, w, h);
|
||||
}
|
||||
}
|
@ -4,21 +4,18 @@ public class EntityUsta {
|
||||
public int Speed;
|
||||
public double Weight;
|
||||
public Color BodyColor;
|
||||
public Color AdditionalColor;
|
||||
public boolean BodyKit;
|
||||
public boolean Pushka;
|
||||
public EntityUsta(int speed, double weight, Color bodyColor) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
public double Step()
|
||||
{
|
||||
return (double) Speed * 100 / Weight;
|
||||
}
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean bodyKit, boolean pushka)
|
||||
{
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean horns, boolean seifbatteries) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Pushka = pushka;
|
||||
}
|
||||
}
|
||||
|
15
src/EntityUstaBat.java
Normal file
15
src/EntityUstaBat.java
Normal file
@ -0,0 +1,15 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityUstaBat extends EntityUsta {
|
||||
public Color AdditionalColor;
|
||||
public boolean Pushka;
|
||||
public boolean BodyKit;
|
||||
public EntityUstaBat(int speed, double weight, Color bodyColor, Color additionalColor, boolean pushka, boolean bodyKit)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
Pushka = pushka;
|
||||
BodyKit = bodyKit;
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="SelfPropelledArtilleryUnit">
|
||||
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormUstaBat">
|
||||
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="5" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="24" y="37" width="635" height="383"/>
|
||||
<xy x="24" y="37" width="736" height="499"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<properties>
|
||||
<minimumSize width="700" height="400"/>
|
||||
<preferredSize width="700" height="400"/>
|
||||
</properties>
|
||||
<border type="none">
|
||||
<font/>
|
||||
</border>
|
||||
<children>
|
||||
<hspacer id="ce44b">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="17764">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="6cb47" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<component id="6cb47" class="javax.swing.JButton" binding="buttonCreateUstaBat">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать"/>
|
||||
<text value="Создать вооруженную арт. установку"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ca377" class="javax.swing.JButton" binding="buttonCreateUsta">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать арт. установку"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="dac01" class="javax.swing.JComboBox" binding="comboBoxStrategy">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model>
|
||||
<item value="MoveToCenter"/>
|
||||
<item value="MoveToRightCorner"/>
|
||||
</model>
|
||||
<toolTipText value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="42f28" class="javax.swing.JButton" binding="buttonStep">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Шаг"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="cc460" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="4" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="true"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2fa92" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="4" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="true"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bbbb" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
@ -46,30 +100,16 @@
|
||||
<hideActionText class="java.lang.Boolean" value="false"/>
|
||||
</clientProperties>
|
||||
</component>
|
||||
<component id="2fa92" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="true"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="326c5" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="true"/>
|
||||
<hideActionText value="false"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
@ -77,20 +117,6 @@
|
||||
<hideActionText class="java.lang.Boolean" value="false"/>
|
||||
</clientProperties>
|
||||
</component>
|
||||
<component id="cc460" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="50" height="50"/>
|
||||
<preferred-size width="50" height="50"/>
|
||||
<maximum-size width="50" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<hideActionText value="true"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
133
src/FormUstaBat.java
Normal file
133
src/FormUstaBat.java
Normal file
@ -0,0 +1,133 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormUstaBat {
|
||||
public DrawingUsta _drawingUsta;
|
||||
AbstractStrategy _abstractStrategy;
|
||||
private JButton buttonCreateUstaBat;
|
||||
private JPanel pictureBox;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
public JComboBox comboBoxStrategy;
|
||||
private JButton buttonStep;
|
||||
private JButton buttonCreateUsta;
|
||||
public JPanel getPictureBox() {
|
||||
return pictureBox;
|
||||
}
|
||||
public FormUstaBat()
|
||||
{
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
buttonCreateUsta.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
|
||||
_drawingUsta = new DrawingUsta(rnd.nextInt(100, 300),
|
||||
rnd.nextInt(1000, 3000), new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
pictureBox.getWidth(),
|
||||
pictureBox.getHeight());
|
||||
|
||||
_drawingUsta.SetWheelsCount(rnd.nextInt(4, 7));
|
||||
_drawingUsta.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100));
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonCreateUstaBat.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
|
||||
_drawingUsta = new DrawingUstaBat(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
random.nextBoolean(),
|
||||
random.nextBoolean(),
|
||||
pictureBox.getWidth(),
|
||||
pictureBox.getHeight()
|
||||
);
|
||||
|
||||
_drawingUsta.SetWheelsCount(random.nextInt(2, 5));
|
||||
_drawingUsta.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonStep.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawingUsta == null) {
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
switch(comboBoxStrategy.getSelectedIndex())
|
||||
{
|
||||
case 0:
|
||||
_abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_abstractStrategy = new MoveToRigthCorner();
|
||||
break;
|
||||
default:
|
||||
_abstractStrategy = null;
|
||||
break;
|
||||
} ;
|
||||
if (_abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawingObjectUsta(_drawingUsta), pictureBox.getWidth(),
|
||||
pictureBox.getHeight());
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (_abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish) {
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ActionListener buttonMoveClickedListener = e -> {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
|
||||
switch (buttonName) {
|
||||
case ("buttonUp") -> {
|
||||
_drawingUsta.MoveTransport(DyrectionType.Up);
|
||||
}
|
||||
case ("buttonDown") -> {
|
||||
_drawingUsta.MoveTransport(DyrectionType.Down);
|
||||
}
|
||||
case ("buttonLeft") -> {
|
||||
_drawingUsta.MoveTransport(DyrectionType.Left);
|
||||
}
|
||||
case ("buttonRight") -> {
|
||||
_drawingUsta.MoveTransport(DyrectionType.Right);
|
||||
}
|
||||
}
|
||||
Draw();
|
||||
};
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
}
|
||||
public void Draw() {
|
||||
if (_drawingUsta.EntityUsta == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = pictureBox.getGraphics();
|
||||
pictureBox.paint(g);
|
||||
_drawingUsta.DrawTransport((Graphics2D) g);
|
||||
}
|
||||
}
|
16
src/FrameUstaBat.java
Normal file
16
src/FrameUstaBat.java
Normal file
@ -0,0 +1,16 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameUstaBat extends JFrame {
|
||||
public FormUstaBat _formUstaCollection;
|
||||
public FrameUstaBat() {
|
||||
super();
|
||||
setTitle("UstaBat");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
_formUstaCollection = new FormUstaBat();
|
||||
setContentPane(_formUstaCollection.getPictureBox());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(500, 200);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
83
src/IDrawingWheels.java
Normal file
83
src/IDrawingWheels.java
Normal file
@ -0,0 +1,83 @@
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Arc2D;
|
||||
import java.awt.geom.Path2D;
|
||||
|
||||
public interface IDrawingWheels {
|
||||
void SetWheelsCount(int wheelsCount);
|
||||
|
||||
WheelsCount GetWheelsCount();
|
||||
|
||||
void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h);
|
||||
|
||||
default void DrawWheels(Graphics2D g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight){
|
||||
WheelsCount wheelsCount = GetWheelsCount();
|
||||
if(wheelsCount == null) return;
|
||||
|
||||
if (wheelsCount.count <= wheelsCount.Four.count) {
|
||||
|
||||
|
||||
/* наверху гусеницы*/
|
||||
g.fillOval(startPosX + 47, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 62, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 77, startPosY + 44, 13, 13);
|
||||
|
||||
/* по середине гусеницы*/
|
||||
DrawWheel(g, color, startPosX + 40, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 55, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 70, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 85, startPosY + 59, 12, 12);
|
||||
|
||||
|
||||
/* два крайних на гусенице*/
|
||||
g.fillOval(startPosX + 10, startPosY + 50, 25, 24);
|
||||
g.fillOval(startPosX + 105, startPosY + 50, 25, 24);
|
||||
|
||||
}
|
||||
|
||||
if (wheelsCount.count == wheelsCount.Five.count) {
|
||||
|
||||
|
||||
/* наверху гусеницы*/
|
||||
g.fillOval(startPosX + 47, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 62, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 77, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 92, startPosY + 44, 13, 13);
|
||||
|
||||
/* по середине гусеницы*/
|
||||
DrawWheel(g, color, startPosX + 40, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 55, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 70, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 85, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 100, startPosY + 59, 12, 12);
|
||||
|
||||
|
||||
/* два крайних на гусенице*/
|
||||
g.fillOval(startPosX + 10, startPosY + 50, 25, 24);
|
||||
g.fillOval(startPosX + 120, startPosY + 50, 25, 24);
|
||||
}
|
||||
|
||||
if (wheelsCount.count == wheelsCount.Six.count) {
|
||||
|
||||
|
||||
/* наверху гусеницы*/
|
||||
g.fillOval(startPosX + 47, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 62, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 77, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 92, startPosY + 44, 13, 13);
|
||||
g.fillOval(startPosX + 107, startPosY + 44, 13, 13);
|
||||
|
||||
/* по середине гусеницы*/
|
||||
DrawWheel(g, color, startPosX + 40, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 55, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 70, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 85, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 100, startPosY + 59, 12, 12);
|
||||
DrawWheel(g, color, startPosX + 115, startPosY + 59, 12, 12);
|
||||
|
||||
|
||||
/* два крайних на гусенице*/
|
||||
g.fillOval(startPosX + 10, startPosY + 50, 25, 24);
|
||||
g.fillOval(startPosX + 135, startPosY + 50, 25, 24);
|
||||
}
|
||||
}
|
||||
}
|
6
src/IMoveableObject.java
Normal file
6
src/IMoveableObject.java
Normal file
@ -0,0 +1,6 @@
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters GetObjectPosition();
|
||||
int GetStep();
|
||||
boolean CheckCanMove(DyrectionType direction);
|
||||
void MoveObject(DyrectionType direction);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
MainFrameUsta mainFrameUsta = new MainFrameUsta();
|
||||
FrameUstaBat mainFrame = new FrameUstaBat();
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class MainFrameUsta extends JFrame {
|
||||
private SelfPropelledArtilleryUnit _formUsta;
|
||||
|
||||
public MainFrameUsta() {
|
||||
super();
|
||||
setTitle("ArtilleryUnit");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
_formUsta = new SelfPropelledArtilleryUnit();
|
||||
setContentPane(_formUsta.getPictureBox());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(500, 50);
|
||||
setSize(500, 850);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
43
src/MoveToCenter.java
Normal file
43
src/MoveToCenter.java
Normal file
@ -0,0 +1,43 @@
|
||||
public class MoveToCenter extends AbstractStrategy{
|
||||
@Override
|
||||
protected boolean IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) return false;
|
||||
|
||||
return objParams.ObjectMiddleHorizontal() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal() + GetStep()
|
||||
>= FieldWidth / 2 && objParams.ObjectMiddleVertical() <= FieldHeight / 2 && objParams.ObjectMiddleVertical()
|
||||
+ GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) return;
|
||||
var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
||||
if (Math.abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
||||
if (Math.abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
src/MoveToRigthCorner.java
Normal file
19
src/MoveToRigthCorner.java
Normal file
@ -0,0 +1,19 @@
|
||||
public class MoveToRigthCorner extends AbstractStrategy {
|
||||
@Override
|
||||
protected boolean IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) return false;
|
||||
|
||||
return objParams.RightBorder() >= FieldWidth - GetStep() && objParams.DownBorder() >= FieldHeight - GetStep();
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) return;
|
||||
|
||||
if (objParams.RightBorder() < FieldWidth - GetStep()) MoveRight();
|
||||
if (objParams.DownBorder() < FieldHeight - GetStep()) MoveDown();
|
||||
}
|
||||
}
|
50
src/ObjectParameters.java
Normal file
50
src/ObjectParameters.java
Normal file
@ -0,0 +1,50 @@
|
||||
public class ObjectParameters {
|
||||
private final int _x;
|
||||
private final int _y;
|
||||
private final int _width;
|
||||
private final int _height;
|
||||
|
||||
/// Левая граница
|
||||
public int LeftBorder()
|
||||
{
|
||||
return _x;
|
||||
};
|
||||
|
||||
/// Верхняя граница
|
||||
public int TopBorder()
|
||||
{
|
||||
return _y;
|
||||
}
|
||||
|
||||
/// Правая граница
|
||||
public int RightBorder()
|
||||
{
|
||||
return _x + _width;
|
||||
}
|
||||
|
||||
/// Нижняя граница
|
||||
public int DownBorder()
|
||||
{
|
||||
return _y + _height;
|
||||
}
|
||||
|
||||
/// Середина объекта по горизонтали
|
||||
public int ObjectMiddleHorizontal()
|
||||
{
|
||||
return _x + _width / 2;
|
||||
}
|
||||
|
||||
/// Середина объекта по вертикали
|
||||
public int ObjectMiddleVertical()
|
||||
{
|
||||
return _y + _height / 2;
|
||||
}
|
||||
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class SelfPropelledArtilleryUnit {
|
||||
DrawingUsta _drawingUsta = new DrawingUsta();
|
||||
private JButton buttonCreate;
|
||||
private JPanel pictureBox;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
|
||||
public JPanel getPictureBox() {
|
||||
return pictureBox;
|
||||
}
|
||||
public SelfPropelledArtilleryUnit()
|
||||
{
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
buttonCreate.addActionListener(e -> {
|
||||
_drawingUsta = new DrawingUsta();
|
||||
Random random = new Random();
|
||||
|
||||
_drawingUsta.Init(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
random.nextBoolean(),
|
||||
random.nextBoolean(),
|
||||
pictureBox.getWidth(),
|
||||
pictureBox.getHeight()
|
||||
);
|
||||
|
||||
_drawingUsta.SetWheelsCount(random.nextInt(4, 7));
|
||||
_drawingUsta.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
Draw();
|
||||
});
|
||||
|
||||
ActionListener buttonMoveClickedListener = e -> {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
|
||||
switch (buttonName) {
|
||||
case ("buttonUp") -> {
|
||||
_drawingUsta.MoveTransport(DyrectionType.Up);
|
||||
}
|
||||
case ("buttonDown") -> {
|
||||
_drawingUsta.MoveTransport(DyrectionType.Down);
|
||||
}
|
||||
case ("buttonLeft") -> {
|
||||
_drawingUsta.MoveTransport(DyrectionType.Left);
|
||||
}
|
||||
case ("buttonRight") -> {
|
||||
_drawingUsta.MoveTransport(DyrectionType.Right);
|
||||
}
|
||||
}
|
||||
Draw();
|
||||
};
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
}
|
||||
public void Draw() {
|
||||
if (_drawingUsta.EntityUsta == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = pictureBox.getGraphics();
|
||||
pictureBox.paint(g);
|
||||
_drawingUsta.DrawTransport((Graphics2D) g);
|
||||
}
|
||||
|
||||
}
|
5
src/Status.java
Normal file
5
src/Status.java
Normal file
@ -0,0 +1,5 @@
|
||||
public enum Status {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user