From e8a6638e159bd5415367cb43883a375ec8e7d56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Tue, 24 Oct 2023 01:01:37 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/Git.iml | 9 + Tank/.gitignore | 29 --- Tank/.idea/.gitignore | 11 +- Tank/.idea/misc.xml | 9 +- Tank/.idea/modules.xml | 14 +- Tank/.idea/uiDesigner.xml | 124 ++++++++++++ Tank/.idea/vcs.xml | 10 +- Tank/Tank.iml | 20 +- Tank/src/AbstractStrategy.java | 82 ++++++++ Tank/src/CountWheels.java | 1 - Tank/src/Direction.java | 4 +- Tank/src/DrawingArmoVehicle.java | 128 ++++++++++++ Tank/src/DrawingAsteriskOrnament.java | 85 ++++++++ Tank/src/DrawingField.java | 54 ------ Tank/src/DrawingObjectTank.java | 17 ++ Tank/src/DrawingSuspensionOrnament.java | 65 +++++++ Tank/src/DrawingTank.java | 176 +++++------------ Tank/src/DrawingWheels.java | 50 ----- Tank/src/DrawingWheelsCombination.java | 104 ++++++++++ Tank/src/EntityArmoVehicle.java | 20 ++ Tank/src/EntityTank.java | 35 ++-- Tank/src/FormTank.form | 112 +++++++++++ Tank/src/FormTank.java | 248 +++++++++++++----------- Tank/src/FrameTank.java | 17 ++ Tank/src/IMoveableObject.java | 13 ++ Tank/src/IOrnamentForm.java | 7 + Tank/src/Main.java | 6 +- Tank/src/MoveToBorder.java | 36 ++++ Tank/src/MoveToCenter.java | 35 ++++ Tank/src/ObjectParameters.java | 44 +++++ Tank/src/Status.java | 5 + 31 files changed, 1133 insertions(+), 437 deletions(-) create mode 100644 .idea/Git.iml delete mode 100644 Tank/.gitignore create mode 100644 Tank/.idea/uiDesigner.xml create mode 100644 Tank/src/AbstractStrategy.java create mode 100644 Tank/src/DrawingArmoVehicle.java create mode 100644 Tank/src/DrawingAsteriskOrnament.java delete mode 100644 Tank/src/DrawingField.java create mode 100644 Tank/src/DrawingObjectTank.java create mode 100644 Tank/src/DrawingSuspensionOrnament.java delete mode 100644 Tank/src/DrawingWheels.java create mode 100644 Tank/src/DrawingWheelsCombination.java create mode 100644 Tank/src/EntityArmoVehicle.java create mode 100644 Tank/src/FormTank.form create mode 100644 Tank/src/FrameTank.java create mode 100644 Tank/src/IMoveableObject.java create mode 100644 Tank/src/IOrnamentForm.java create mode 100644 Tank/src/MoveToBorder.java create mode 100644 Tank/src/MoveToCenter.java create mode 100644 Tank/src/ObjectParameters.java create mode 100644 Tank/src/Status.java diff --git a/.idea/Git.iml b/.idea/Git.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Git.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Tank/.gitignore b/Tank/.gitignore deleted file mode 100644 index f68d109..0000000 --- a/Tank/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -### IntelliJ IDEA ### -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/Tank/.idea/.gitignore b/Tank/.idea/.gitignore index 1c2fda5..26d3352 100644 --- a/Tank/.idea/.gitignore +++ b/Tank/.idea/.gitignore @@ -1,8 +1,3 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Tank/.idea/misc.xml b/Tank/.idea/misc.xml index 80cafc3..1e4328b 100644 --- a/Tank/.idea/misc.xml +++ b/Tank/.idea/misc.xml @@ -1,6 +1,5 @@ - - - - - + + + + \ No newline at end of file diff --git a/Tank/.idea/modules.xml b/Tank/.idea/modules.xml index 8d39350..a2edae3 100644 --- a/Tank/.idea/modules.xml +++ b/Tank/.idea/modules.xml @@ -1,8 +1,8 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/Tank/.idea/uiDesigner.xml b/Tank/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/Tank/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tank/.idea/vcs.xml b/Tank/.idea/vcs.xml index 2e3f692..6c0b863 100644 --- a/Tank/.idea/vcs.xml +++ b/Tank/.idea/vcs.xml @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/Tank/Tank.iml b/Tank/Tank.iml index 9465dd8..c90834f 100644 --- a/Tank/Tank.iml +++ b/Tank/Tank.iml @@ -1,11 +1,11 @@ - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/Tank/src/AbstractStrategy.java b/Tank/src/AbstractStrategy.java new file mode 100644 index 0000000..c36c2ef --- /dev/null +++ b/Tank/src/AbstractStrategy.java @@ -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(Direction.Left);} + + // Перемещение вправо + protected boolean MoveRight() { return MoveTo(Direction.Right);} + + // Перемещение вверх + protected boolean MoveUp() { return MoveTo(Direction.Up);} + + // Перемещение вниз + protected boolean MoveDown() { return MoveTo(Direction.Down);} + + // Параметры объекта + protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); } + + // Шаг объекта + protected int GetStep() { + if (_state != Status.InProgress) { + return 0; + } + return _moveableObject.GetStep(); + } + + // Перемещение к цели + protected abstract void MoveToTarget(); + + // Достигнута ли цель + protected abstract boolean IsTargetDestinaion(); + + // Попытка перемещения в требуемом направлении + private boolean MoveTo(Direction Direction) { + if (_state != Status.InProgress) { + return false; + } + if (_moveableObject.CheckCanMove(Direction)) { + _moveableObject.MoveObject(Direction); + return true; + } + return false; + } +} diff --git a/Tank/src/CountWheels.java b/Tank/src/CountWheels.java index 5d064d7..2a7408e 100644 --- a/Tank/src/CountWheels.java +++ b/Tank/src/CountWheels.java @@ -10,5 +10,4 @@ public enum CountWheels { public int getCountWheels(){ return Value; } - public int setCountWheels() { return Value; } } diff --git a/Tank/src/Direction.java b/Tank/src/Direction.java index a641b80..8ea7191 100644 --- a/Tank/src/Direction.java +++ b/Tank/src/Direction.java @@ -1,6 +1,6 @@ public enum Direction { Up, - Down, Left, + Down, Right -} +} \ No newline at end of file diff --git a/Tank/src/DrawingArmoVehicle.java b/Tank/src/DrawingArmoVehicle.java new file mode 100644 index 0000000..0beb04b --- /dev/null +++ b/Tank/src/DrawingArmoVehicle.java @@ -0,0 +1,128 @@ +import java.awt.*; +import java.util.Random; + +public class DrawingArmoVehicle { + protected IOrnamentForm OrnamentsForm; + public EntityArmoVehicle ArmoVehicle; + public EntityArmoVehicle getTank() { + return ArmoVehicle; + } + protected int _pictureWidth; + protected int _pictureHeight; + protected int _startPosX; + protected int _startPosY; + protected int _TankWidth = 160; + protected int _TankHeight = 55; + + public DrawingArmoVehicle(int speed, double weight, Color bodyColor, int _numWheel, int width, int height) { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureHeight < _TankHeight || _pictureWidth < _TankWidth) + return; + ArmoVehicle = new EntityArmoVehicle(speed, weight, bodyColor, _numWheel); + + Random random = new Random(); + switch(random.nextInt(0, 3)) { + case 0: + OrnamentsForm = new DrawingWheelsCombination(); + break; + case 1: + OrnamentsForm = new DrawingAsteriskOrnament(); + break; + case 2: + OrnamentsForm = new DrawingSuspensionOrnament(); + break; + default: + OrnamentsForm = new DrawingWheelsCombination(); + break; + } + OrnamentsForm.setDigit(_numWheel); + } + + public void SetPosition(int x, int y) { + _startPosX = Math.min(x, _pictureWidth - _TankWidth); + _startPosY = Math.min(y, _pictureHeight - _TankHeight); + } + + public int GetPosX (){ return _startPosX; } + public int GetPosY (){ return _startPosY; } + public int GetWidth (){ return _TankWidth; } + public int GetHeight (){return _TankHeight;} + + public boolean CanMove(Direction direction) { + if (ArmoVehicle == null) { + return false; + } + switch (direction) { + case Left: + return _startPosX - ArmoVehicle.Step > 0; + case Right: + return _startPosX + _TankWidth + ArmoVehicle.Step < _pictureWidth; + case Up: + return _startPosY - ArmoVehicle.Step > 0; + case Down: + return _startPosY + _TankHeight + ArmoVehicle.Step < _pictureHeight; + default: + return false; + } + } + + public void MoveTransport(Direction direction) { + if (!CanMove(direction) || ArmoVehicle == null) { + return; + } + switch (direction) { + //влево + case Left: + _startPosX -= (int)ArmoVehicle.Step; + break; + //вверх + case Up: + _startPosY -= (int)ArmoVehicle.Step; + break; + // вправо + case Right: + _startPosX += (int)ArmoVehicle.Step; + break; + //вниз + case Down: + _startPosY += (int)ArmoVehicle.Step; + break; + } + } + + public void SetWheels(int number) { + OrnamentsForm.setDigit(number); + } + public void DrawTransport(Graphics2D g) { + if (ArmoVehicle == null) { + return; + } + + g.setColor(Color.BLUE); + int[] xPoints = {_startPosX + 5, _startPosX + 140, _startPosX + 130,_startPosX + 12}; + int[] yPoints = {_startPosY + 30, _startPosY + 30, _startPosY + 42, _startPosY + 42}; + int nPoints = 4; + g.drawPolygon(xPoints,yPoints,nPoints); + g.fillPolygon(xPoints,yPoints,nPoints); + + //wheels + OrnamentsForm.Draw(g, _startPosX, _startPosY); + } + + public void ChangeBorders(int width,int height) { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth<=_TankWidth||_pictureHeight<=_TankHeight) { + _pictureWidth = Integer.parseInt(null); + _pictureHeight = Integer.parseInt(null); + return; + } + if (_startPosX + _TankWidth > _pictureWidth) { + _startPosX = _pictureWidth - _TankWidth; + } + if (_startPosY + _TankHeight > _pictureHeight) { + _startPosY = _pictureHeight - _TankHeight; + } + } +} diff --git a/Tank/src/DrawingAsteriskOrnament.java b/Tank/src/DrawingAsteriskOrnament.java new file mode 100644 index 0000000..cc76eda --- /dev/null +++ b/Tank/src/DrawingAsteriskOrnament.java @@ -0,0 +1,85 @@ +import java.awt.*; + +public class DrawingAsteriskOrnament implements IOrnamentForm { + private CountWheels wheels; + private Color additionalColor; + public CountWheels getNumWheel() { + return wheels; + } + + public void setDigit(int number) { + switch(number){ + case 2: + wheels = CountWheels.Two; + break; + case 3: + wheels = CountWheels.Three; + break; + case 4: + wheels = CountWheels.Four; + break; + default: + wheels = CountWheels.Two; + break; + } + } + + public void CaterpillarStar(Graphics g, int _startPosX, int _startPosY) { + additionalColor = Color.RED; + g.setColor(additionalColor); + int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 12, _startPosX + 11, _startPosX + 15, _startPosX + 16}; + int yPontsStar[] = {_startPosY + 35, _startPosY + 38, _startPosY + 38, _startPosY + 42, _startPosY + 45, _startPosY + 42, _startPosY + 45, _startPosY + 41, _startPosY + 38, _startPosY + 38, _startPosY + 35}; + g.drawPolygon(xPontsStar, yPontsStar, xPontsStar.length); + g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length); + } + + public void DrawWheels(Graphics g, int _startPosX, int _startPosY){ + g.setColor(Color.BLACK); + g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); + } + public void Draw(Graphics g, int _startPosX, int _startPosY) { + if (wheels == CountWheels.Two){ + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + CaterpillarStar(g,_startPosX + 105, _startPosY + 12); + } + + if (wheels == CountWheels.Three) { + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 50, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + CaterpillarStar(g,_startPosX + 55, _startPosY + 12); + CaterpillarStar(g,_startPosX + 105, _startPosY + 12); + } + + if (wheels == CountWheels.Four) { + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 25, _startPosY); + DrawWheels(g,_startPosX + 50, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + CaterpillarStar(g,_startPosX + 30, _startPosY + 12); + CaterpillarStar(g,_startPosX + 55, _startPosY + 12); + CaterpillarStar(g,_startPosX + 105, _startPosY + 12); + } + + if(wheels == CountWheels.Five) { + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 25, _startPosY); + DrawWheels(g,_startPosX + 50, _startPosY); + DrawWheels(g,_startPosX + 75, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + CaterpillarStar(g,_startPosX + 30, _startPosY + 12); + CaterpillarStar(g,_startPosX + 55, _startPosY + 12); + CaterpillarStar(g,_startPosX + 80, _startPosY + 12); + CaterpillarStar(g,_startPosX + 105, _startPosY + 12); + } + } +} \ No newline at end of file diff --git a/Tank/src/DrawingField.java b/Tank/src/DrawingField.java deleted file mode 100644 index 5f782e8..0000000 --- a/Tank/src/DrawingField.java +++ /dev/null @@ -1,54 +0,0 @@ -import javax.swing.*; -import java.awt.*; -import java.util.Random; - -public class DrawingField extends JPanel { - private final FormTank field; - DrawingTank _Tank; - public DrawingField(FormTank field) { - this.field = field; - } - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - Graphics2D g2 =(Graphics2D)g; - if (_Tank!=null) - _Tank.DrawTransport(g2); - else return; - } - public void UpButtonAction(){ - if (_Tank!=null) - _Tank.MoveTransport(Direction.Up); - else - return; - } - public void DownButtonAction(){ - if (_Tank!=null) - _Tank.MoveTransport(Direction.Down); - else - return; - } - public void RightButtonAction(){ - if (_Tank!=null) - _Tank.MoveTransport(Direction.Right); - else - return; - } - public void LeftButtonAction(){ - if (_Tank!=null) - _Tank.MoveTransport(Direction.Left); - else - return; - } - public void CreateButtonAction(){ - Random rnd=new Random(); - _Tank=new DrawingTank(); - _Tank.Init(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256))); - _Tank.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10,getWidth(),getHeight()); - } - public void ResizeField(){ - if (_Tank!=null) - _Tank.ChangeBorders(getWidth(),getHeight()); - else return; - } -} diff --git a/Tank/src/DrawingObjectTank.java b/Tank/src/DrawingObjectTank.java new file mode 100644 index 0000000..ddb9b50 --- /dev/null +++ b/Tank/src/DrawingObjectTank.java @@ -0,0 +1,17 @@ +public class DrawingObjectTank implements IMoveableObject { + private DrawingArmoVehicle _ArmoVehicle = null; + public DrawingObjectTank(DrawingArmoVehicle drawingTrain) + { + _ArmoVehicle = drawingTrain; + } + public ObjectParameters GetObjectPosition() { + if (_ArmoVehicle == null || _ArmoVehicle.ArmoVehicle == null) { + return null; + } + return new ObjectParameters(_ArmoVehicle.GetPosX(),_ArmoVehicle.GetPosY(), + _ArmoVehicle.GetWidth(), _ArmoVehicle.GetHeight()); + } + public int GetStep(){ return (int)_ArmoVehicle.ArmoVehicle.Step; } + public boolean CheckCanMove(Direction direction) { return _ArmoVehicle.CanMove(direction);} + public void MoveObject(Direction direction) { _ArmoVehicle.MoveTransport(direction); } +} diff --git a/Tank/src/DrawingSuspensionOrnament.java b/Tank/src/DrawingSuspensionOrnament.java new file mode 100644 index 0000000..1f5f1e7 --- /dev/null +++ b/Tank/src/DrawingSuspensionOrnament.java @@ -0,0 +1,65 @@ +import java.awt.*; + +public class DrawingSuspensionOrnament implements IOrnamentForm { + private CountWheels wheels; + private Color additionalColor; + public CountWheels getNumWheel() { + return wheels; + } + + public void setDigit(int number) { + switch(number){ + case 2: + wheels = CountWheels.Two; + break; + case 3: + wheels = CountWheels.Three; + break; + case 4: + wheels = CountWheels.Four; + break; + default: + wheels = CountWheels.Two; + break; + } + } + + public void DrawWheels(Graphics g, int _startPosX, int _startPosY) { + g.setColor(Color.BLACK); + g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); + } + + public void Draw(Graphics g, int _startPosX, int _startPosY) { + if (wheels == CountWheels.Two){ + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + additionalColor = Color.RED; + g.setColor(additionalColor); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 100, _startPosY + 50, 10, 3); + } + + if (wheels == CountWheels.Three) { + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 50, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 100, _startPosY + 50, 10, 3); + } + + if (wheels == CountWheels.Four) { + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 25, _startPosY); + DrawWheels(g,_startPosX + 50, _startPosY); + DrawWheels(g,_startPosX + 75, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + } + } +} \ No newline at end of file diff --git a/Tank/src/DrawingTank.java b/Tank/src/DrawingTank.java index 1f363ce..a7cd8db 100644 --- a/Tank/src/DrawingTank.java +++ b/Tank/src/DrawingTank.java @@ -1,143 +1,69 @@ import java.awt.*; -public class DrawingTank { - public EntityTank Tank; - public EntityTank getTank() { - return Tank; - } - public DrawingWheels Wheels; - private int _startPosX; - private int _startPosY; - private Integer _pictureWidth = null; - private Integer _pictureHeight = null; - private final int _TankWidth = 175; - private final int _TankHeight = 100; +public class DrawingTank extends DrawingArmoVehicle { + protected IOrnamentForm OrnamentsForm; + private boolean WheelsOrnament; + private Color AdditionalColor; + private boolean OrnamentAdd; - public void Init(int speed, float weight, Color bodyColor) + public DrawingTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height, boolean wheelsOrnament, boolean ornamentAdd) { - Tank = new EntityTank(); - Tank.Init(speed, weight, bodyColor); - Wheels = new DrawingWheels(); - Wheels.SetCountWheels((int)(2 + Math.random() + Math.random()*2)); + super(speed, weight, bodyColor, _numWheel, width, height); + ArmoVehicle = new EntityTank(speed, weight, bodyColor, _numWheel, additionalColor, bodyKit, caterpillar, tower); + _TankWidth = ((EntityTank)ArmoVehicle).BodyKit ? 169 : 83; + + this.AdditionalColor = additionalColor; + this.OrnamentAdd = ornamentAdd; } - public void SetPosition(int x, int y, int width, int height) - { - if (x >= 0 && x+_TankWidth <= width && y >= 0 && y+_TankHeight <= height) - { - _startPosX = x; - _startPosY = y; - _pictureWidth = width; - _pictureHeight = height; - } + public void SetPosition(int x, int y) { + _startPosX = Math.min(x, _pictureWidth-_TankWidth); + _startPosY = Math.min(y, _pictureHeight-_TankHeight); } - public void MoveTransport(Direction direction) - { - if (_pictureWidth == null || _pictureHeight == null) - { + public boolean isOrnamentAdd() { + return OrnamentAdd; + } + private void setOrnamentAdd(boolean ornamentAdd) { + this.OrnamentAdd = ornamentAdd; + } + + public void DrawTransport(Graphics2D g) { + if (ArmoVehicle == null) { return; } - switch (direction) - { - case Right: - if (_startPosX + _TankWidth + Tank.Step < _pictureWidth) - { - _startPosX += Tank.Step; - } - break; + super.DrawTransport(g); - case Left: - if (_startPosX- Tank.Step >= 0) - { - _startPosX -= Tank.Step; - } - break; + if (((EntityTank) ArmoVehicle).BodyKit) { + g.setColor(Color.DARK_GRAY); + int[] xPointsBody = {_startPosX + 52, _startPosX + 52, _startPosX + 40, _startPosX + 15,_startPosX + 15, _startPosX + 60,_startPosX + 90,_startPosX + 120,_startPosX + 100,_startPosX + 95, _startPosX + 90}; + int[] yPointsBody = {_startPosY + 30, _startPosY + 27, _startPosY + 23, _startPosY + 18,_startPosY + 15, _startPosY + 11,_startPosY + 11,_startPosY + 20,_startPosY + 25,_startPosY + 27,_startPosY + 30}; + int nPointsBody = xPointsBody.length; - case Up: - if (_startPosY - Tank.Step >= 0) - { - _startPosY -= Tank.Step; - } - break; - - case Down: - if (_startPosY + _TankHeight + Tank.Step < _pictureHeight) - { - _startPosY += Tank.Step; - } - break; - } - } - public void DrawTransport(Graphics g) - { - if (_startPosX < 0 || _startPosY < 0 || _pictureHeight== null || _pictureWidth== null) - { - return; + g.drawPolygon(xPointsBody,yPointsBody,nPointsBody); + g.fillPolygon(xPointsBody,yPointsBody,nPointsBody); } - Graphics2D g2 = (Graphics2D) g; - - //Гусеница - Color Gray = new Color(128, 128, 128); - g2.setColor(Gray); - g2.drawOval(_startPosX + 10, _startPosY + 30, 120, 30); - - // Ведущие колёса танка (в размере чуть меньше) - g2.setColor(Color.BLACK); - g2.drawOval(_startPosX + 113, _startPosY + 41, 11, 11); - g2.fillOval(_startPosX + 113, _startPosY + 41, 11, 11); - g2.drawOval(_startPosX + 13, _startPosY + 40, 11, 11); - g2.fillOval(_startPosX + 13, _startPosY + 40, 11, 11); - Wheels.DrawWheels(g2, _startPosX, _startPosY); - - // Корпус танка - g2.setColor(Color.DARK_GRAY); - int[] xPoints = {_startPosX + 5, _startPosX + 140, _startPosX + 130,_startPosX + 12}; - int[] yPoints = {_startPosY + 30, _startPosY + 30, _startPosY + 42, _startPosY + 42}; - int nPoints = 4; - g2.drawPolygon(xPoints,yPoints,nPoints); - g2.fillPolygon(xPoints,yPoints,nPoints); - - // Башня - int[] xPointsBody = {_startPosX + 52, _startPosX + 52, _startPosX + 40, _startPosX + 15,_startPosX + 15, _startPosX + 60,_startPosX + 90,_startPosX + 120,_startPosX + 100,_startPosX + 95, _startPosX + 90}; - int[] yPointsBody = {_startPosY + 30, _startPosY + 27, _startPosY + 23, _startPosY + 18,_startPosY + 15, _startPosY + 11,_startPosY + 11,_startPosY + 20,_startPosY + 25,_startPosY + 27,_startPosY + 30}; - int nPointsBody = 11; - - g2.drawPolygon(xPointsBody,yPointsBody,nPointsBody); - g2.fillPolygon(xPointsBody,yPointsBody,nPointsBody); - - // Орудие - g2.drawRect(_startPosX + 112, _startPosY+17, 50, 5); - g2.fillRect(_startPosX + 112, _startPosY+17, 50, 5); - - // Зенитное орудие - int[] xPointsGun = {_startPosX + 45, _startPosX + 45, _startPosX + 41, _startPosX + 41, _startPosX + 42, _startPosX + 41, _startPosX + 44,_startPosX + 50 ,_startPosX + 52,_startPosX + 53, _startPosX + 58}; - int[] yPointsGun = {_startPosY + 12, _startPosY + 10, _startPosY + 8, _startPosY + 7, _startPosY + 5, _startPosY + 4,_startPosY + 3,_startPosY + 3,_startPosY + 5,_startPosY + 7,_startPosY + 10}; - int nPointsGun = 11; - - g2.fillRect(_startPosX + 50, _startPosY+5, 20, 2); - g2.drawPolygon(xPointsGun,yPointsGun,nPointsGun); - g2.fillPolygon(xPointsGun,yPointsGun,nPointsGun); - } - - public void ChangeBorders(int width,int height) - { - _pictureWidth = width; - _pictureHeight = height; - if (_pictureWidth<=_TankWidth||_pictureHeight<=_TankHeight) - { - _pictureWidth = null; - _pictureHeight = null; - return; + if (((EntityTank) ArmoVehicle).Caterpillar) { + Color Gray = new Color(128, 128, 128); + g.setColor(Gray); + g.drawOval(_startPosX + 10, _startPosY + 30, 120, 30); } - if (_startPosX + _TankWidth > _pictureWidth) - { - _startPosX = _pictureWidth - _TankWidth; - } - if (_startPosY + _TankHeight > _pictureHeight) - { - _startPosY = _pictureHeight - _TankHeight; + + if (((EntityTank) ArmoVehicle).Tower) { + g.setColor(AdditionalColor); + // Орудие + g.drawRect(_startPosX + 112, _startPosY + 17, 60, 4); + g.fillRect(_startPosX + 112, _startPosY + 17, 60, 4); + + // Зенитное орудие + int[] xPointsGun = {_startPosX + 45, _startPosX + 45, _startPosX + 41, _startPosX + 41, _startPosX + 42, _startPosX + 41, _startPosX + 44,_startPosX + 50 ,_startPosX + 52,_startPosX + 53, _startPosX + 58}; + int[] yPointsGun = {_startPosY + 12, _startPosY + 10, _startPosY + 8, _startPosY + 7, _startPosY + 5, _startPosY + 4,_startPosY + 3,_startPosY + 3,_startPosY + 5,_startPosY + 7,_startPosY + 10}; + int nPointsGun = xPointsGun.length; + + g.fillRect(_startPosX + 50, _startPosY + 5, 20, 2); + g.drawPolygon(xPointsGun,yPointsGun,nPointsGun); + g.fillPolygon(xPointsGun,yPointsGun,nPointsGun); } } } diff --git a/Tank/src/DrawingWheels.java b/Tank/src/DrawingWheels.java deleted file mode 100644 index 397c052..0000000 --- a/Tank/src/DrawingWheels.java +++ /dev/null @@ -1,50 +0,0 @@ -import java.awt.*; - -public class DrawingWheels { - - private CountWheels _wheels; - - public void SetCountWheels(int Count){ - for (CountWheels temp: CountWheels.values()) - if (temp.getCountWheels() == Count){ - _wheels=temp; - return; - } - } - - public void DrawWheels(Graphics2D g,int _startPosX, int _startPosY) { - switch (_wheels.getCountWheels()) - { - case 2: - // Отрисовка 2 катков - g.setColor(Color.BLACK); - g.drawOval(_startPosX + 30, _startPosY + 42, 15, 15); - g.fillOval(_startPosX + 30, _startPosY + 42, 15, 15); - g.drawOval(_startPosX + 50, _startPosY + 45, 15, 15); - g.fillOval(_startPosX + 50, _startPosY + 45, 15, 15); - break; - case 3: - // Отрисовка 3 катков - g.setColor(Color.BLACK); - g.drawOval(_startPosX + 30, _startPosY + 42, 15, 15); - g.fillOval(_startPosX + 30, _startPosY + 42, 15, 15); - g.drawOval(_startPosX + 50, _startPosY + 45, 15, 15); - g.fillOval(_startPosX + 50, _startPosY + 45, 15, 15); - g.drawOval(_startPosX + 75, _startPosY + 45, 15, 15); - g.fillOval(_startPosX + 75, _startPosY + 45, 15, 15); - break; - case 4: - // Отрисовка 4 катков - g.setColor(Color.BLACK); - g.drawOval(_startPosX + 30, _startPosY + 42, 15, 15); - g.fillOval(_startPosX + 30, _startPosY + 42, 15, 15); - g.drawOval(_startPosX + 50, _startPosY + 45, 15, 15); - g.fillOval(_startPosX + 50, _startPosY + 45, 15, 15); - g.drawOval(_startPosX + 75, _startPosY + 45, 15, 15); - g.fillOval(_startPosX + 75, _startPosY + 45, 15, 15); - g.drawOval(_startPosX + 95, _startPosY + 42, 15, 15); - g.fillOval(_startPosX + 95, _startPosY + 42, 15, 15); - break; - } - } -} diff --git a/Tank/src/DrawingWheelsCombination.java b/Tank/src/DrawingWheelsCombination.java new file mode 100644 index 0000000..640fa21 --- /dev/null +++ b/Tank/src/DrawingWheelsCombination.java @@ -0,0 +1,104 @@ +import java.awt.*; + +public class DrawingWheelsCombination implements IOrnamentForm { + private CountWheels _wheels; + private CountWheels wheels; + private Color additionalColor; + public CountWheels getNumWheel() { + return wheels; + } + + public void setDigit(int number) { + switch(number) { + case 2: + wheels = CountWheels.Two; + break; + case 3: + wheels = CountWheels.Three; + break; + case 4: + wheels = CountWheels.Four; + break; + default: + wheels = CountWheels.Two; + break; + } + } + + public void CaterpillarStar(Graphics g, int _startPosX, int _startPosY) { + additionalColor = Color.RED; + g.setColor(additionalColor); + int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 13, _startPosX + 12, _startPosX + 15, _startPosX + 16}; + int yPontsStar[] = {_startPosY + 35, _startPosY + 38, _startPosY + 38, _startPosY + 42, _startPosY + 45, _startPosY + 42, _startPosY + 45, _startPosY + 41, _startPosY + 38, _startPosY + 38, _startPosY + 35}; + g.drawPolygon(xPontsStar, yPontsStar, xPontsStar.length); + g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length); + } + + public void DrawWheels(Graphics g, int _startPosX, int _startPosY){ + g.setColor(Color.BLACK); + g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); + } + + public void Draw(Graphics g, int _startPosX, int _startPosY) { + if (wheels == CountWheels.Two){ + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + CaterpillarStar(g,_startPosX + 105, _startPosY + 12); + + } + if (wheels == CountWheels.Three) { + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 50, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 100, _startPosY + 50, 10, 3); + + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + CaterpillarStar(g,_startPosX + 55, _startPosY + 12); + CaterpillarStar(g,_startPosX + 105, _startPosY + 12); + } + + if (wheels == CountWheels.Four) { + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 25, _startPosY); + DrawWheels(g,_startPosX + 50, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + CaterpillarStar(g,_startPosX + 30, _startPosY + 12); + CaterpillarStar(g,_startPosX + 55, _startPosY + 12); + CaterpillarStar(g,_startPosX + 105, _startPosY + 12); + + } + if(wheels == CountWheels.Five) { + DrawWheels(g,_startPosX, _startPosY); + DrawWheels(g,_startPosX + 25, _startPosY); + DrawWheels(g,_startPosX + 50, _startPosY); + DrawWheels(g,_startPosX + 75, _startPosY); + DrawWheels(g,_startPosX + 100, _startPosY); + + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); + g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + + CaterpillarStar(g,_startPosX + 5, _startPosY + 12); + CaterpillarStar(g,_startPosX + 30, _startPosY + 12); + CaterpillarStar(g,_startPosX + 55, _startPosY + 12); + CaterpillarStar(g,_startPosX + 80, _startPosY + 12); + CaterpillarStar(g,_startPosX + 105, _startPosY + 12); + } + } +} diff --git a/Tank/src/EntityArmoVehicle.java b/Tank/src/EntityArmoVehicle.java new file mode 100644 index 0000000..772099b --- /dev/null +++ b/Tank/src/EntityArmoVehicle.java @@ -0,0 +1,20 @@ +import java.awt.*; + +public class EntityArmoVehicle { + public int Speed; + public double Weight; + public double getWeight() { + return Weight; + } + public Color BodyColor; + public double Step; + public int numWheel; + + public EntityArmoVehicle(int speed, double weight, Color bodyColor, int _numWheel) { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + numWheel = _numWheel; + Step = (double) Speed * 300 / Weight; + } +} diff --git a/Tank/src/EntityTank.java b/Tank/src/EntityTank.java index 37840a1..bca2e31 100644 --- a/Tank/src/EntityTank.java +++ b/Tank/src/EntityTank.java @@ -1,27 +1,20 @@ import java.awt.*; -import java.util.Random; -public class EntityTank { - private int Speed; - public int getSpeed() { - return Speed; - } - private float Weight; - public float getWeight() { - return Weight; - } - private Color BodyColor; - public Color getBodyColor() { - return BodyColor; - } - public float Step; +public class EntityTank extends EntityArmoVehicle { + public Color AdditionalColor; + public boolean BodyKit; + public boolean Caterpillar; + public boolean Tower; - public void Init(int speed, float weight, Color bodyColor){ - Random rnd = new Random(); - Speed = speed <= 0 ? rnd.nextInt(50)+10 : speed; - Weight = weight <= 0 ? rnd.nextInt(100)+500 : weight; - BodyColor = bodyColor; - Step = Speed * 600 / (int)Weight; + public EntityTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower) + { + super(speed, weight, bodyColor, _numWheel); + AdditionalColor = additionalColor; + BodyKit = bodyKit; + Caterpillar = caterpillar; + Tower = tower; } } + + diff --git a/Tank/src/FormTank.form b/Tank/src/FormTank.form new file mode 100644 index 0000000..b5e14d1 --- /dev/null +++ b/Tank/src/FormTank.form @@ -0,0 +1,112 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Tank/src/FormTank.java b/Tank/src/FormTank.java index f094dbe..be2a7cf 100644 --- a/Tank/src/FormTank.java +++ b/Tank/src/FormTank.java @@ -1,135 +1,149 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -public class FormTank extends JFrame{ - private int Width; - private int Height; +import java.awt.event.ActionListener; +import java.util.Random; - JPanel BottomPanel = new JPanel(); - JPanel CreatePanel = new JPanel(); - JPanel BottomAndCreatePanel = new JPanel(); - JPanel DimentionPanel = new JPanel(); - JPanel UpPanel = new JPanel(); - JPanel DownPanel = new JPanel(); - JPanel LRPanel = new JPanel(); +public class FormTank { + DrawingArmoVehicle _drawingTank; + AbstractStrategy _abstractStrategy; + private JButton buttonCreateTank; + private JPanel pictureBox; + private JButton buttonDown; + private JButton buttonUp; + private JButton buttonLeft; + private JButton buttonRight; + private JButton buttonCreateVehicle; + private JComboBox comboBoxStrategy; + private JButton buttonStep; - DrawingField field = new DrawingField(this); - - JButton ButtonCreate=new JButton("Создать"); - Icon iconUp = new ImageIcon("Resources/KeyUp.png"); - JButton ButtonUp=new JButton(iconUp); - - Icon iconDown = new ImageIcon("Resources/KeyDown.png"); - JButton ButtonDown=new JButton(iconDown); - - Icon iconRight = new ImageIcon("Resources/KeyRight.png"); - JButton ButtonRight=new JButton(iconRight); - - Icon iconLeft = new ImageIcon("Resources/KeyLeft.png"); - JButton ButtonLeft=new JButton(iconLeft); - public FormTank(){ - super("Tank"); - setSize(800,600); - Width=getWidth(); - Height=getHeight(); - ShowWindow(); - RefreshWindow(); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setVisible(true); + public JPanel getPictureBox() { + return pictureBox; } - public void ShowWindow(){ + public FormTank() { + buttonUp.setName("buttonUp"); + buttonDown.setName("buttonDown"); + buttonLeft.setName("buttonLeft"); + buttonRight.setName("buttonRight"); - Dimension dimen=new Dimension(30,30); + ImageIcon iconUp = new ImageIcon("Resources/KeyUp.png"); + buttonUp.setIcon(iconUp); + ImageIcon iconDown = new ImageIcon("Resources/KeyDown.png"); + buttonDown.setIcon(iconDown); + ImageIcon iconRight = new ImageIcon("Resources/KeyRight.png"); + buttonRight.setIcon(iconRight); + ImageIcon iconLeft = new ImageIcon("Resources/KeyLeft.png"); + buttonLeft.setIcon(iconLeft); - // Обработка нажатия кнопки - ButtonUp.setPreferredSize(dimen); - ButtonUp.addActionListener(e->{ - field.UpButtonAction(); - repaint(); + buttonCreateTank.addActionListener(e -> { + Random random = new Random(); + _drawingTank = new DrawingTank( + random.nextInt(100, 300), + random.nextInt(1000, 3000), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + random.nextInt(2, 6), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + true, + true, + true, + pictureBox.getWidth(), + pictureBox.getHeight(), + true, + true + ); + + _drawingTank.SetWheels(random.nextInt(2, 6)); + _drawingTank.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); + + Draw(); }); - // Обработка нажатия кнопки - ButtonDown.setPreferredSize(dimen); - ButtonDown.addActionListener(e->{ - field.DownButtonAction(); - repaint(); + buttonCreateVehicle.addActionListener(e -> { + Random random = new Random(); + _drawingTank = new DrawingArmoVehicle( + random.nextInt(100, 300), + random.nextInt(1000, 3000), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + random.nextInt(2, 6), + pictureBox.getWidth(), + pictureBox.getHeight() + ); + + _drawingTank.SetWheels(random.nextInt(2, 6)); + _drawingTank.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); + + Draw(); }); - // Обработка нажатия кнопки - ButtonRight.setPreferredSize(dimen); - ButtonRight.addActionListener(e->{ - field.RightButtonAction(); - repaint(); - }); + buttonStep.addActionListener(e -> { + if (_drawingTank == null) + return; + if (comboBoxStrategy.isEnabled()) { + _abstractStrategy = null; + int comboBoxStrategySelectedIndex = comboBoxStrategy.getSelectedIndex(); + if (comboBoxStrategySelectedIndex == 0) { + _abstractStrategy = new MoveToCenter(); + } else if (comboBoxStrategySelectedIndex == 1) { + _abstractStrategy = new MoveToBorder(); + } + if (_abstractStrategy == null) + return; + _abstractStrategy.SetData(new DrawingObjectTank(_drawingTank), pictureBox.getWidth(), pictureBox.getHeight()); + comboBoxStrategy.setEnabled(false); + } - // Обработка нажатия кнопки - ButtonLeft.setPreferredSize(dimen); - ButtonLeft.addActionListener(e->{ - field.LeftButtonAction(); - repaint(); - }); - - // Добавление кнопок на панель (Левая и правая стрелки) - LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0)); - LRPanel.setBackground(new Color(0,0,0,0)); - LRPanel.add(ButtonLeft); - LRPanel.add(ButtonRight); - - // Добавление кнопки (Стрелка вверх) - UpPanel.setLayout(new FlowLayout()); - UpPanel.setBackground(new Color(0,0,0,0)); - UpPanel.add(ButtonUp); - - // Добавление кнопки (Стрелка вниз) - DownPanel.setLayout(new FlowLayout()); - DownPanel.setBackground(new Color(0,0,0,0)); - DownPanel.add(ButtonDown); - - DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS)); - DimentionPanel.setBackground(new Color(0,0,0,0)); - DimentionPanel.add(UpPanel); - DimentionPanel.add(LRPanel); - DimentionPanel.add(DownPanel); - add(DimentionPanel); - - // нажатие кнопки - CreatePanel.setLayout(new FlowLayout()); - CreatePanel.setBackground(new Color(0,0,0,0)); - CreatePanel.add(ButtonCreate); - ButtonCreate.addActionListener(e->{ - field.CreateButtonAction(); - repaint(); - }); - - BottomPanel.setLayout(new FlowLayout()); - BottomPanel.setBackground(new Color(0,0,0,0)); - - BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS)); - BottomAndCreatePanel.setBackground(new Color(0,0,0,0)); - BottomAndCreatePanel.add(CreatePanel); - BottomAndCreatePanel.add(BottomPanel); - - add(BottomAndCreatePanel); - add(field); - - addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - super.componentResized(e); - Width=getWidth(); - Height=getHeight(); - - field.ResizeField(); - repaint(); - RefreshWindow(); + 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") -> { + _drawingTank.MoveTransport(Direction.Up); + } + case ("buttonDown") -> { + _drawingTank.MoveTransport(Direction.Down); + } + case ("buttonLeft") -> { + _drawingTank.MoveTransport(Direction.Left); + } + case ("buttonRight") -> { + _drawingTank.MoveTransport(Direction.Right); + } + } + + Draw(); + }; + + buttonUp.addActionListener(buttonMoveClickedListener); + buttonDown.addActionListener(buttonMoveClickedListener); + buttonLeft.addActionListener(buttonMoveClickedListener); + buttonRight.addActionListener(buttonMoveClickedListener); } - public void RefreshWindow(){ - field.setBounds(0,0,Width,Height); - BottomAndCreatePanel.setBounds(-320,Height-110,Width,80); - DimentionPanel.setBounds(Width-170,Height-170,190,140); + + public void Draw() { + if (_drawingTank == null) { + return; + } + + Graphics g = pictureBox.getGraphics(); + pictureBox.paint(g); + _drawingTank.DrawTransport((Graphics2D)g); + } + + private void createUIComponents() { + String[] strategiesList = { + "Движение к центру", + "Движение к краю формы" + }; + comboBoxStrategy = new JComboBox(strategiesList); } } diff --git a/Tank/src/FrameTank.java b/Tank/src/FrameTank.java new file mode 100644 index 0000000..aa06d8e --- /dev/null +++ b/Tank/src/FrameTank.java @@ -0,0 +1,17 @@ +import javax.swing.*; + +public class FrameTank extends JFrame { + private FormTank _formTank; + + public FrameTank() { + super(); + setTitle("Танк"); + setDefaultCloseOperation(EXIT_ON_CLOSE); + _formTank = new FormTank(); + setContentPane(_formTank.getPictureBox()); + setDefaultLookAndFeelDecorated(false); + setLocation(300, 100); + pack(); + setVisible(true); + } +} diff --git a/Tank/src/IMoveableObject.java b/Tank/src/IMoveableObject.java new file mode 100644 index 0000000..d8f4c08 --- /dev/null +++ b/Tank/src/IMoveableObject.java @@ -0,0 +1,13 @@ +public interface IMoveableObject { + // Получение координаты X объекта + ObjectParameters GetObjectPosition(); + + // Шаг объекта + int GetStep(); + + // Проверка, можно ли переместиться по нужному направлению + boolean CheckCanMove(Direction direction); + + /// Изменение направления пермещения объекта + void MoveObject(Direction direction); +} diff --git a/Tank/src/IOrnamentForm.java b/Tank/src/IOrnamentForm.java new file mode 100644 index 0000000..e89364b --- /dev/null +++ b/Tank/src/IOrnamentForm.java @@ -0,0 +1,7 @@ +import java.awt.*; + +public interface IOrnamentForm { + public CountWheels getNumWheel(); + void setDigit(int number); + void Draw(Graphics g, int _startPosX, int _startPosY); +} \ No newline at end of file diff --git a/Tank/src/Main.java b/Tank/src/Main.java index 7c7e57b..984e71f 100644 --- a/Tank/src/Main.java +++ b/Tank/src/Main.java @@ -1,5 +1,5 @@ public class Main { - public static void main(String[] args){ - new FormTank(); + public static void main(String[] args) { + new FrameTank(); } -} +} \ No newline at end of file diff --git a/Tank/src/MoveToBorder.java b/Tank/src/MoveToBorder.java new file mode 100644 index 0000000..079f792 --- /dev/null +++ b/Tank/src/MoveToBorder.java @@ -0,0 +1,36 @@ +public class MoveToBorder extends AbstractStrategy{ + protected boolean IsTargetDestinaion() { + var objParams = GetObjectParameters(); + if (objParams == null) { + return false; + } + return objParams.RightBorder() <= FieldWidth && + objParams.RightBorder() + GetStep() >= FieldWidth && + objParams.DownBorder() <= FieldHeight && + objParams.DownBorder() + GetStep() >= FieldHeight; + } + protected void MoveToTarget() { + var objParams = GetObjectParameters(); + if (objParams == null) { + return; + } + var diffX = objParams.RightBorder() - FieldWidth; + if (Math.abs(diffX) > GetStep()) { + if (diffX > 0) { + MoveLeft(); + } + else { + MoveRight(); + } + } + var diffY = objParams.DownBorder() - FieldHeight; + if (Math.abs(diffY) > GetStep()) { + if (diffY > 0) { + MoveUp(); + } + else { + MoveDown(); + } + } + } +} diff --git a/Tank/src/MoveToCenter.java b/Tank/src/MoveToCenter.java new file mode 100644 index 0000000..9b80709 --- /dev/null +++ b/Tank/src/MoveToCenter.java @@ -0,0 +1,35 @@ +public class MoveToCenter extends AbstractStrategy { + protected boolean IsTargetDestinaion() { + var objParams = GetObjectParameters(); + if (objParams == null) { + return false; + } + return + Math.abs(objParams.ObjectMiddleHorizontal() - FieldWidth / 2) <= GetStep() + && + Math.abs(objParams.ObjectMiddleVertical() - FieldHeight / 2) <= GetStep(); + } + + 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(); + } + } + } +} diff --git a/Tank/src/ObjectParameters.java b/Tank/src/ObjectParameters.java new file mode 100644 index 0000000..1039f53 --- /dev/null +++ b/Tank/src/ObjectParameters.java @@ -0,0 +1,44 @@ +public class ObjectParameters { + private int _x; + private int _y; + private int _width; + private 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; + } +} diff --git a/Tank/src/Status.java b/Tank/src/Status.java new file mode 100644 index 0000000..6467ed7 --- /dev/null +++ b/Tank/src/Status.java @@ -0,0 +1,5 @@ +public enum Status { + NotInit, + InProgress, + Finish +} -- 2.25.1 From 9bb10333ef1e9667ebb75727abcb7d24a41fce7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Tue, 24 Oct 2023 01:03:27 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=BD=D0=B0=D1=8F=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/Git.iml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .idea/Git.iml diff --git a/.idea/Git.iml b/.idea/Git.iml deleted file mode 100644 index d6ebd48..0000000 --- a/.idea/Git.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file -- 2.25.1 From 41dc8a43254f6ae7af7a40cab3effffb9657d840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Sun, 29 Oct 2023 18:57:32 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/.gitignore | 29 ++ Tank/.idea/.gitignore | 5 + Tank/.idea/misc.xml | 1 + Tank/.idea/vcs.xml | 6 - Tank/Tank.iml | 11 - Tank/src/AbstractStrategy.java | 145 +++++---- Tank/src/DrawingArmoVehicle.java | 33 +- Tank/src/DrawingObjectTank.java | 20 +- ...Ornament.java => DrawingStarOrnament.java} | 8 +- Tank/src/DrawingSuspensionOrnament.java | 31 +- Tank/src/DrawingTank.java | 25 +- Tank/src/DrawingWheelsCombination.java | 39 ++- Tank/src/EntityArmoVehicle.java | 5 +- Tank/src/FormTank.form | 112 ------- Tank/src/FormTank.java | 293 ++++++++++-------- Tank/src/FrameTank.java | 17 - Tank/src/Main.java | 2 +- Tank/src/MoveToBorder.java | 4 +- Tank/src/MoveToCenter.java | 8 +- Tank/src/ObjectParameters.java | 2 +- 20 files changed, 362 insertions(+), 434 deletions(-) create mode 100644 Tank/.gitignore delete mode 100644 Tank/.idea/vcs.xml delete mode 100644 Tank/Tank.iml rename Tank/src/{DrawingAsteriskOrnament.java => DrawingStarOrnament.java} (95%) delete mode 100644 Tank/src/FormTank.form delete mode 100644 Tank/src/FrameTank.java diff --git a/Tank/.gitignore b/Tank/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/Tank/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Tank/.idea/.gitignore b/Tank/.idea/.gitignore index 26d3352..13566b8 100644 --- a/Tank/.idea/.gitignore +++ b/Tank/.idea/.gitignore @@ -1,3 +1,8 @@ # Default ignored files /shelf/ /workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Tank/.idea/misc.xml b/Tank/.idea/misc.xml index 1e4328b..5d30da4 100644 --- a/Tank/.idea/misc.xml +++ b/Tank/.idea/misc.xml @@ -1,3 +1,4 @@ + diff --git a/Tank/.idea/vcs.xml b/Tank/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/Tank/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Tank/Tank.iml b/Tank/Tank.iml deleted file mode 100644 index c90834f..0000000 --- a/Tank/Tank.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/Tank/src/AbstractStrategy.java b/Tank/src/AbstractStrategy.java index c36c2ef..e3c1812 100644 --- a/Tank/src/AbstractStrategy.java +++ b/Tank/src/AbstractStrategy.java @@ -1,82 +1,93 @@ public abstract class AbstractStrategy { + // Перемещаемый объект + private IMoveableObject _moveableObject; - // Перемещаемый объект - private IMoveableObject _moveableObject; + // Статус перемещения + private Status _state = Status.NotInit; - // Статус перемещения - private Status _state = Status.NotInit; + // Ширина поля + protected int FieldWidth; - // Ширина поля - protected int FieldWidth; + // Высота поля + protected int FieldHeight; - // Высота поля - protected int FieldHeight; + // Статус перемещения + public Status GetStatus() { + return _state; + } - // Статус перемещения - 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 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(); + // Шаг перемещения + public void MakeStep() { + if (_state != Status.InProgress) { + return; } - - // Перемещение влево - protected boolean MoveLeft() { return MoveTo(Direction.Left);} - - // Перемещение вправо - protected boolean MoveRight() { return MoveTo(Direction.Right);} - - // Перемещение вверх - protected boolean MoveUp() { return MoveTo(Direction.Up);} - - // Перемещение вниз - protected boolean MoveDown() { return MoveTo(Direction.Down);} - - // Параметры объекта - protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); } - - // Шаг объекта - protected int GetStep() { - if (_state != Status.InProgress) { - return 0; - } - return _moveableObject.GetStep(); + if (IsTargetDestination()) { + _state = Status.Finish; + return; } + MoveToTarget(); + } - // Перемещение к цели - protected abstract void MoveToTarget(); + // Перемещение влево + protected boolean MoveLeft() { + return MoveTo(Direction.Left); + } - // Достигнута ли цель - protected abstract boolean IsTargetDestinaion(); + // Перемещение вправо + protected boolean MoveRight() { + return MoveTo(Direction.Right); + } - // Попытка перемещения в требуемом направлении - private boolean MoveTo(Direction Direction) { - if (_state != Status.InProgress) { - return false; - } - if (_moveableObject.CheckCanMove(Direction)) { - _moveableObject.MoveObject(Direction); - return true; - } + // Перемещение вверх + protected boolean MoveUp() { + return MoveTo(Direction.Up); + } + + // Перемещение вниз + protected boolean MoveDown() { + return MoveTo(Direction.Down); + } + + // Параметры объекта + protected ObjectParameters GetObjectParameters() { + return _moveableObject.GetObjectPosition(); + } + + // Шаг объекта + protected int GetStep() { + if (_state != Status.InProgress) { + return 0; + } + return _moveableObject.GetStep(); + } + + // Перемещение к цели + protected abstract void MoveToTarget(); + + // Достигнута ли цель + protected abstract boolean IsTargetDestination(); + + // Попытка перемещения в требуемом направлении + private boolean MoveTo(Direction Direction) { + if (_state != Status.InProgress) { return false; } -} + if (_moveableObject.CheckCanMove(Direction)) { + _moveableObject.MoveObject(Direction); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/Tank/src/DrawingArmoVehicle.java b/Tank/src/DrawingArmoVehicle.java index 0beb04b..f3f195d 100644 --- a/Tank/src/DrawingArmoVehicle.java +++ b/Tank/src/DrawingArmoVehicle.java @@ -4,9 +4,6 @@ import java.util.Random; public class DrawingArmoVehicle { protected IOrnamentForm OrnamentsForm; public EntityArmoVehicle ArmoVehicle; - public EntityArmoVehicle getTank() { - return ArmoVehicle; - } protected int _pictureWidth; protected int _pictureHeight; protected int _startPosX; @@ -27,7 +24,7 @@ public class DrawingArmoVehicle { OrnamentsForm = new DrawingWheelsCombination(); break; case 1: - OrnamentsForm = new DrawingAsteriskOrnament(); + OrnamentsForm = new DrawingStarOrnament(); break; case 2: OrnamentsForm = new DrawingSuspensionOrnament(); @@ -47,7 +44,7 @@ public class DrawingArmoVehicle { public int GetPosX (){ return _startPosX; } public int GetPosY (){ return _startPosY; } public int GetWidth (){ return _TankWidth; } - public int GetHeight (){return _TankHeight;} + public int GetHeight (){ return _TankHeight; } public boolean CanMove(Direction direction) { if (ArmoVehicle == null) { @@ -91,38 +88,20 @@ public class DrawingArmoVehicle { } } - public void SetWheels(int number) { - OrnamentsForm.setDigit(number); - } public void DrawTransport(Graphics2D g) { if (ArmoVehicle == null) { return; } - g.setColor(Color.BLUE); + // body + g.setColor(ArmoVehicle.BodyColor); int[] xPoints = {_startPosX + 5, _startPosX + 140, _startPosX + 130,_startPosX + 12}; int[] yPoints = {_startPosY + 30, _startPosY + 30, _startPosY + 42, _startPosY + 42}; - int nPoints = 4; + int nPoints = xPoints.length; g.drawPolygon(xPoints,yPoints,nPoints); g.fillPolygon(xPoints,yPoints,nPoints); //wheels OrnamentsForm.Draw(g, _startPosX, _startPosY); } - - public void ChangeBorders(int width,int height) { - _pictureWidth = width; - _pictureHeight = height; - if (_pictureWidth<=_TankWidth||_pictureHeight<=_TankHeight) { - _pictureWidth = Integer.parseInt(null); - _pictureHeight = Integer.parseInt(null); - return; - } - if (_startPosX + _TankWidth > _pictureWidth) { - _startPosX = _pictureWidth - _TankWidth; - } - if (_startPosY + _TankHeight > _pictureHeight) { - _startPosY = _pictureHeight - _TankHeight; - } - } -} +} \ No newline at end of file diff --git a/Tank/src/DrawingObjectTank.java b/Tank/src/DrawingObjectTank.java index ddb9b50..bfa1347 100644 --- a/Tank/src/DrawingObjectTank.java +++ b/Tank/src/DrawingObjectTank.java @@ -1,17 +1,17 @@ public class DrawingObjectTank implements IMoveableObject { - private DrawingArmoVehicle _ArmoVehicle = null; - public DrawingObjectTank(DrawingArmoVehicle drawingTrain) + private DrawingArmoVehicle _drawingArmoVehicle = null; + public DrawingObjectTank(DrawingArmoVehicle drawingTank) { - _ArmoVehicle = drawingTrain; + _drawingArmoVehicle = drawingTank; } public ObjectParameters GetObjectPosition() { - if (_ArmoVehicle == null || _ArmoVehicle.ArmoVehicle == null) { + if (_drawingArmoVehicle == null || _drawingArmoVehicle.ArmoVehicle == null) { return null; } - return new ObjectParameters(_ArmoVehicle.GetPosX(),_ArmoVehicle.GetPosY(), - _ArmoVehicle.GetWidth(), _ArmoVehicle.GetHeight()); + return new ObjectParameters(_drawingArmoVehicle.GetPosX(),_drawingArmoVehicle.GetPosY(), + _drawingArmoVehicle.GetWidth(), _drawingArmoVehicle.GetHeight()); } - public int GetStep(){ return (int)_ArmoVehicle.ArmoVehicle.Step; } - public boolean CheckCanMove(Direction direction) { return _ArmoVehicle.CanMove(direction);} - public void MoveObject(Direction direction) { _ArmoVehicle.MoveTransport(direction); } -} + public int GetStep(){ return (int)_drawingArmoVehicle.ArmoVehicle.Step; } + public boolean CheckCanMove(Direction direction) { return _drawingArmoVehicle.CanMove(direction);} + public void MoveObject(Direction direction) { _drawingArmoVehicle.MoveTransport(direction); } +} \ No newline at end of file diff --git a/Tank/src/DrawingAsteriskOrnament.java b/Tank/src/DrawingStarOrnament.java similarity index 95% rename from Tank/src/DrawingAsteriskOrnament.java rename to Tank/src/DrawingStarOrnament.java index cc76eda..53cb792 100644 --- a/Tank/src/DrawingAsteriskOrnament.java +++ b/Tank/src/DrawingStarOrnament.java @@ -1,8 +1,8 @@ import java.awt.*; -public class DrawingAsteriskOrnament implements IOrnamentForm { +public class DrawingStarOrnament implements IOrnamentForm { private CountWheels wheels; - private Color additionalColor; + private Color StarColor; public CountWheels getNumWheel() { return wheels; } @@ -25,8 +25,8 @@ public class DrawingAsteriskOrnament implements IOrnamentForm { } public void CaterpillarStar(Graphics g, int _startPosX, int _startPosY) { - additionalColor = Color.RED; - g.setColor(additionalColor); + StarColor = Color.RED; + g.setColor(StarColor); int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 12, _startPosX + 11, _startPosX + 15, _startPosX + 16}; int yPontsStar[] = {_startPosY + 35, _startPosY + 38, _startPosY + 38, _startPosY + 42, _startPosY + 45, _startPosY + 42, _startPosY + 45, _startPosY + 41, _startPosY + 38, _startPosY + 38, _startPosY + 35}; g.drawPolygon(xPontsStar, yPontsStar, xPontsStar.length); diff --git a/Tank/src/DrawingSuspensionOrnament.java b/Tank/src/DrawingSuspensionOrnament.java index 1f5f1e7..32f1953 100644 --- a/Tank/src/DrawingSuspensionOrnament.java +++ b/Tank/src/DrawingSuspensionOrnament.java @@ -2,7 +2,7 @@ import java.awt.*; public class DrawingSuspensionOrnament implements IOrnamentForm { private CountWheels wheels; - private Color additionalColor; + private Color SuspensionColor; public CountWheels getNumWheel() { return wheels; } @@ -29,14 +29,19 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); } + public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) { + SuspensionColor = Color.BLUE; + g.setColor(SuspensionColor); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + } + public void Draw(Graphics g, int _startPosX, int _startPosY) { - if (wheels == CountWheels.Two){ + if (wheels == CountWheels.Two) { DrawWheels(g,_startPosX, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - additionalColor = Color.RED; - g.setColor(additionalColor); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 100, _startPosY + 50, 10, 3); + + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); } if (wheels == CountWheels.Three) { @@ -44,9 +49,9 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 100, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); } if (wheels == CountWheels.Four) { @@ -56,10 +61,10 @@ public class DrawingSuspensionOrnament implements IOrnamentForm { DrawWheels(g,_startPosX + 75, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 53, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); } } } \ No newline at end of file diff --git a/Tank/src/DrawingTank.java b/Tank/src/DrawingTank.java index a7cd8db..046d4aa 100644 --- a/Tank/src/DrawingTank.java +++ b/Tank/src/DrawingTank.java @@ -2,32 +2,25 @@ import java.awt.*; public class DrawingTank extends DrawingArmoVehicle { protected IOrnamentForm OrnamentsForm; - private boolean WheelsOrnament; - private Color AdditionalColor; private boolean OrnamentAdd; - public DrawingTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height, boolean wheelsOrnament, boolean ornamentAdd) - { + public DrawingTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height, boolean ornamentAdd) { super(speed, weight, bodyColor, _numWheel, width, height); ArmoVehicle = new EntityTank(speed, weight, bodyColor, _numWheel, additionalColor, bodyKit, caterpillar, tower); _TankWidth = ((EntityTank)ArmoVehicle).BodyKit ? 169 : 83; - this.AdditionalColor = additionalColor; this.OrnamentAdd = ornamentAdd; } + // Установка позиции public void SetPosition(int x, int y) { _startPosX = Math.min(x, _pictureWidth-_TankWidth); _startPosY = Math.min(y, _pictureHeight-_TankHeight); } - public boolean isOrnamentAdd() { - return OrnamentAdd; - } - private void setOrnamentAdd(boolean ornamentAdd) { - this.OrnamentAdd = ornamentAdd; - } + private boolean setOrnamentAdd() { return OrnamentAdd; } + // Прорисовка объекта public void DrawTransport(Graphics2D g) { if (ArmoVehicle == null) { return; @@ -35,7 +28,7 @@ public class DrawingTank extends DrawingArmoVehicle { super.DrawTransport(g); if (((EntityTank) ArmoVehicle).BodyKit) { - g.setColor(Color.DARK_GRAY); + g.setColor(((EntityTank) ArmoVehicle).AdditionalColor); int[] xPointsBody = {_startPosX + 52, _startPosX + 52, _startPosX + 40, _startPosX + 15,_startPosX + 15, _startPosX + 60,_startPosX + 90,_startPosX + 120,_startPosX + 100,_startPosX + 95, _startPosX + 90}; int[] yPointsBody = {_startPosY + 30, _startPosY + 27, _startPosY + 23, _startPosY + 18,_startPosY + 15, _startPosY + 11,_startPosY + 11,_startPosY + 20,_startPosY + 25,_startPosY + 27,_startPosY + 30}; int nPointsBody = xPointsBody.length; @@ -51,10 +44,10 @@ public class DrawingTank extends DrawingArmoVehicle { } if (((EntityTank) ArmoVehicle).Tower) { - g.setColor(AdditionalColor); + g.setColor(Color.DARK_GRAY); // Орудие - g.drawRect(_startPosX + 112, _startPosY + 17, 60, 4); - g.fillRect(_startPosX + 112, _startPosY + 17, 60, 4); + g.drawRect(_startPosX + 112, _startPosY + 17, 60, 5); + g.fillRect(_startPosX + 112, _startPosY + 17, 60, 5); // Зенитное орудие int[] xPointsGun = {_startPosX + 45, _startPosX + 45, _startPosX + 41, _startPosX + 41, _startPosX + 42, _startPosX + 41, _startPosX + 44,_startPosX + 50 ,_startPosX + 52,_startPosX + 53, _startPosX + 58}; @@ -66,4 +59,4 @@ public class DrawingTank extends DrawingArmoVehicle { g.fillPolygon(xPointsGun,yPointsGun,nPointsGun); } } -} +} \ No newline at end of file diff --git a/Tank/src/DrawingWheelsCombination.java b/Tank/src/DrawingWheelsCombination.java index 640fa21..000dea2 100644 --- a/Tank/src/DrawingWheelsCombination.java +++ b/Tank/src/DrawingWheelsCombination.java @@ -1,9 +1,8 @@ import java.awt.*; public class DrawingWheelsCombination implements IOrnamentForm { - private CountWheels _wheels; private CountWheels wheels; - private Color additionalColor; + private Color CombinationColor; public CountWheels getNumWheel() { return wheels; } @@ -26,14 +25,20 @@ public class DrawingWheelsCombination implements IOrnamentForm { } public void CaterpillarStar(Graphics g, int _startPosX, int _startPosY) { - additionalColor = Color.RED; - g.setColor(additionalColor); + CombinationColor = Color.RED; + g.setColor(CombinationColor); int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 13, _startPosX + 12, _startPosX + 15, _startPosX + 16}; int yPontsStar[] = {_startPosY + 35, _startPosY + 38, _startPosY + 38, _startPosY + 42, _startPosY + 45, _startPosY + 42, _startPosY + 45, _startPosY + 41, _startPosY + 38, _startPosY + 38, _startPosY + 35}; g.drawPolygon(xPontsStar, yPontsStar, xPontsStar.length); g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length); } + public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) { + CombinationColor = Color.BLUE; + g.setColor(CombinationColor); + g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); + } + public void DrawWheels(Graphics g, int _startPosX, int _startPosY){ g.setColor(Color.BLACK); g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20); @@ -44,8 +49,8 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 105, _startPosY + 12); @@ -56,9 +61,9 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 100, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 55, _startPosY + 12); @@ -71,10 +76,10 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX + 50, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 53, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 30, _startPosY + 12); @@ -89,10 +94,10 @@ public class DrawingWheelsCombination implements IOrnamentForm { DrawWheels(g,_startPosX + 75, _startPosY); DrawWheels(g,_startPosX + 100, _startPosY); - g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 51, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 80, _startPosY + 50, 10, 3); - g.fillRect(_startPosX + 101, _startPosY + 50, 10, 3); + DrawSuspension(g, _startPosX, _startPosY); + DrawSuspension(g,_startPosX + 24, _startPosY); + DrawSuspension(g,_startPosX + 53, _startPosY); + DrawSuspension(g,_startPosX + 73, _startPosY); CaterpillarStar(g,_startPosX + 5, _startPosY + 12); CaterpillarStar(g,_startPosX + 30, _startPosY + 12); diff --git a/Tank/src/EntityArmoVehicle.java b/Tank/src/EntityArmoVehicle.java index 772099b..bc35d94 100644 --- a/Tank/src/EntityArmoVehicle.java +++ b/Tank/src/EntityArmoVehicle.java @@ -3,9 +3,6 @@ import java.awt.*; public class EntityArmoVehicle { public int Speed; public double Weight; - public double getWeight() { - return Weight; - } public Color BodyColor; public double Step; public int numWheel; @@ -15,6 +12,6 @@ public class EntityArmoVehicle { Weight = weight; BodyColor = bodyColor; numWheel = _numWheel; - Step = (double) Speed * 300 / Weight; + Step = (double) Speed * 200 / Weight; } } diff --git a/Tank/src/FormTank.form b/Tank/src/FormTank.form deleted file mode 100644 index b5e14d1..0000000 --- a/Tank/src/FormTank.form +++ /dev/null @@ -1,112 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/Tank/src/FormTank.java b/Tank/src/FormTank.java index be2a7cf..0e3ff97 100644 --- a/Tank/src/FormTank.java +++ b/Tank/src/FormTank.java @@ -1,149 +1,198 @@ import javax.swing.*; import java.awt.*; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; public class FormTank { - DrawingArmoVehicle _drawingTank; - AbstractStrategy _abstractStrategy; - private JButton buttonCreateTank; - private JPanel pictureBox; - private JButton buttonDown; - private JButton buttonUp; - private JButton buttonLeft; - private JButton buttonRight; - private JButton buttonCreateVehicle; - private JComboBox comboBoxStrategy; - private JButton buttonStep; + private DrawingArmoVehicle _drawingArmoVehicle; + private AbstractStrategy abstractStrategy; + Canvas canv; + static int pictureBoxWidth = 980; + static int pictureBoxHeight = 560; - public JPanel getPictureBox() { - return pictureBox; + public void Draw() { + canv.repaint(); } public FormTank() { - buttonUp.setName("buttonUp"); - buttonDown.setName("buttonDown"); - buttonLeft.setName("buttonLeft"); - buttonRight.setName("buttonRight"); + JFrame Frame = new JFrame("Tank"); + JButton buttonCreateArmoVehicle = new JButton("Создать Бронемашину"); + JButton buttonCreateTank = new JButton("Создать Танк"); + JButton buttonStrategysStep = new JButton("Шаг"); + JComboBox ComboBoxStrategy = new JComboBox(new String[]{"к центру", "к краю формочки"}); - ImageIcon iconUp = new ImageIcon("Resources/KeyUp.png"); - buttonUp.setIcon(iconUp); - ImageIcon iconDown = new ImageIcon("Resources/KeyDown.png"); - buttonDown.setIcon(iconDown); - ImageIcon iconRight = new ImageIcon("Resources/KeyRight.png"); - buttonRight.setIcon(iconRight); - ImageIcon iconLeft = new ImageIcon("Resources/KeyLeft.png"); - buttonLeft.setIcon(iconLeft); + Icon iconUp = new ImageIcon("Resources/KeyUp.png"); + JButton up = new JButton(iconUp); + up.setName("up"); - buttonCreateTank.addActionListener(e -> { - Random random = new Random(); - _drawingTank = new DrawingTank( - random.nextInt(100, 300), - random.nextInt(1000, 3000), - new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), - random.nextInt(2, 6), - new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), - true, - true, - true, - pictureBox.getWidth(), - pictureBox.getHeight(), - true, - true - ); + Icon iconDown = new ImageIcon("Resources/KeyDown.png"); + JButton down = new JButton(iconDown); + down.setName("down"); - _drawingTank.SetWheels(random.nextInt(2, 6)); - _drawingTank.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); + Icon iconRight = new ImageIcon("Resources/KeyRight.png"); + JButton right = new JButton(iconRight); + right.setName("right"); - Draw(); - }); + Icon iconLeft = new ImageIcon("Resources/KeyLeft.png"); + JButton left = new JButton(iconLeft); + left.setName("left"); - buttonCreateVehicle.addActionListener(e -> { - Random random = new Random(); - _drawingTank = new DrawingArmoVehicle( - random.nextInt(100, 300), - random.nextInt(1000, 3000), - new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), - random.nextInt(2, 6), - pictureBox.getWidth(), - pictureBox.getHeight() - ); + buttonStrategysStep.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (_drawingArmoVehicle == null) { + return; + } + if (ComboBoxStrategy.isEnabled()) { + switch (ComboBoxStrategy.getSelectedIndex()) { + case 0: + abstractStrategy = new MoveToCenter(); + break; + case 1: + abstractStrategy = new MoveToBorder(); + break; + default: + abstractStrategy = null; + break; + } - _drawingTank.SetWheels(random.nextInt(2, 6)); - _drawingTank.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); + if (abstractStrategy == null) { + return; + } - Draw(); - }); - - buttonStep.addActionListener(e -> { - if (_drawingTank == null) - return; - if (comboBoxStrategy.isEnabled()) { - _abstractStrategy = null; - int comboBoxStrategySelectedIndex = comboBoxStrategy.getSelectedIndex(); - if (comboBoxStrategySelectedIndex == 0) { - _abstractStrategy = new MoveToCenter(); - } else if (comboBoxStrategySelectedIndex == 1) { - _abstractStrategy = new MoveToBorder(); + abstractStrategy.SetData(new + DrawingObjectTank(_drawingArmoVehicle), pictureBoxWidth, pictureBoxHeight); + ComboBoxStrategy.setEnabled(false); + } + if (abstractStrategy == null) { + return; + } + abstractStrategy.MakeStep(); + Draw(); + if (abstractStrategy.GetStatus() == Status.Finish) { + ComboBoxStrategy.setEnabled(true); + abstractStrategy = null; + } + } } - if (_abstractStrategy == null) + ); + + buttonCreateTank.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Random random = new Random(); + _drawingArmoVehicle = new DrawingTank( + random.nextInt(100, 300), + random.nextInt(1000, 3000), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), + random.nextInt(2, 6), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), + true, + true, + true, + pictureBoxWidth, + pictureBoxHeight, + true + ); + _drawingArmoVehicle.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); + canv._drawingArmoVehicle = _drawingArmoVehicle; + Draw(); + } + } + ); + + buttonCreateArmoVehicle.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Random random = new Random(); + _drawingArmoVehicle = new DrawingArmoVehicle( + random.nextInt(100, 300), + random.nextInt(1000, 3000), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), + random.nextInt(2, 5), + 1000, + 560); + _drawingArmoVehicle.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); + canv._drawingArmoVehicle = _drawingArmoVehicle; + Draw(); + } + } + ); + + ActionListener actioListener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (_drawingArmoVehicle == null) { return; - _abstractStrategy.SetData(new DrawingObjectTank(_drawingTank), pictureBox.getWidth(), pictureBox.getHeight()); - comboBoxStrategy.setEnabled(false); + } + switch (((JButton) (e.getSource())).getName()) { + case "up": + _drawingArmoVehicle.MoveTransport(Direction.Up); + break; + case "down": + _drawingArmoVehicle.MoveTransport(Direction.Down); + break; + case "left": + _drawingArmoVehicle.MoveTransport(Direction.Left); + break; + case "right": + _drawingArmoVehicle.MoveTransport(Direction.Right); + break; + } + Draw(); } - - 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") -> { - _drawingTank.MoveTransport(Direction.Up); - } - case ("buttonDown") -> { - _drawingTank.MoveTransport(Direction.Down); - } - case ("buttonLeft") -> { - _drawingTank.MoveTransport(Direction.Left); - } - case ("buttonRight") -> { - _drawingTank.MoveTransport(Direction.Right); - } - } - - Draw(); }; - buttonUp.addActionListener(buttonMoveClickedListener); - buttonDown.addActionListener(buttonMoveClickedListener); - buttonLeft.addActionListener(buttonMoveClickedListener); - buttonRight.addActionListener(buttonMoveClickedListener); - } + up.addActionListener(actioListener); + down.addActionListener(actioListener); + left.addActionListener(actioListener); + right.addActionListener(actioListener); - public void Draw() { - if (_drawingTank == null) { - return; - } + Frame.setSize(1000, 600); + Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + Frame.setLayout(null); + canv = new Canvas(); + canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight); - Graphics g = pictureBox.getGraphics(); - pictureBox.paint(g); - _drawingTank.DrawTransport((Graphics2D)g); - } + buttonCreateArmoVehicle.setBounds(5, 500, 170, 40); + buttonCreateTank.setBounds(185, 500, 170, 40); - private void createUIComponents() { - String[] strategiesList = { - "Движение к центру", - "Движение к краю формы" - }; - comboBoxStrategy = new JComboBox(strategiesList); + up.setBounds(900, 480, 40, 40); + down.setBounds(900, 520, 40, 40); + left.setBounds(860, 520, 40, 40); + right.setBounds(940, 520, 40, 40); + + ComboBoxStrategy.setBounds(pictureBoxWidth - 150, 20, 150, 20); + buttonStrategysStep.setBounds(pictureBoxWidth - 150, 45, 150, 20); + + Frame.add(canv); + Frame.add(buttonCreateArmoVehicle); + Frame.add(buttonCreateTank); + Frame.add(up); + Frame.add(down); + Frame.add(left); + Frame.add(right); + + Frame.add(ComboBoxStrategy); + Frame.add(buttonStrategysStep); + + Frame.setVisible(true); } } + +class Canvas extends JComponent { + public DrawingArmoVehicle _drawingArmoVehicle; + + public Canvas() { + } + + public void paintComponent(Graphics g) { + if (_drawingArmoVehicle == null) { + return; + } + super.paintComponents(g); + Graphics2D g2d = (Graphics2D) g; + _drawingArmoVehicle.DrawTransport(g2d); + super.repaint(); + } +} \ No newline at end of file diff --git a/Tank/src/FrameTank.java b/Tank/src/FrameTank.java deleted file mode 100644 index aa06d8e..0000000 --- a/Tank/src/FrameTank.java +++ /dev/null @@ -1,17 +0,0 @@ -import javax.swing.*; - -public class FrameTank extends JFrame { - private FormTank _formTank; - - public FrameTank() { - super(); - setTitle("Танк"); - setDefaultCloseOperation(EXIT_ON_CLOSE); - _formTank = new FormTank(); - setContentPane(_formTank.getPictureBox()); - setDefaultLookAndFeelDecorated(false); - setLocation(300, 100); - pack(); - setVisible(true); - } -} diff --git a/Tank/src/Main.java b/Tank/src/Main.java index 984e71f..02a9eab 100644 --- a/Tank/src/Main.java +++ b/Tank/src/Main.java @@ -1,5 +1,5 @@ public class Main { public static void main(String[] args) { - new FrameTank(); + new FormTank(); } } \ No newline at end of file diff --git a/Tank/src/MoveToBorder.java b/Tank/src/MoveToBorder.java index 079f792..b5daa77 100644 --- a/Tank/src/MoveToBorder.java +++ b/Tank/src/MoveToBorder.java @@ -1,5 +1,5 @@ public class MoveToBorder extends AbstractStrategy{ - protected boolean IsTargetDestinaion() { + protected boolean IsTargetDestination() { var objParams = GetObjectParameters(); if (objParams == null) { return false; @@ -33,4 +33,4 @@ public class MoveToBorder extends AbstractStrategy{ } } } -} +} \ No newline at end of file diff --git a/Tank/src/MoveToCenter.java b/Tank/src/MoveToCenter.java index 9b80709..3a78338 100644 --- a/Tank/src/MoveToCenter.java +++ b/Tank/src/MoveToCenter.java @@ -1,13 +1,13 @@ public class MoveToCenter extends AbstractStrategy { - protected boolean IsTargetDestinaion() { + protected boolean IsTargetDestination() { var objParams = GetObjectParameters(); if (objParams == null) { return false; } return Math.abs(objParams.ObjectMiddleHorizontal() - FieldWidth / 2) <= GetStep() - && - Math.abs(objParams.ObjectMiddleVertical() - FieldHeight / 2) <= GetStep(); + && + Math.abs(objParams.ObjectMiddleVertical() - FieldHeight / 2) <= GetStep(); } protected void MoveToTarget() { @@ -32,4 +32,4 @@ public class MoveToCenter extends AbstractStrategy { } } } -} +} \ No newline at end of file diff --git a/Tank/src/ObjectParameters.java b/Tank/src/ObjectParameters.java index 1039f53..8df4f07 100644 --- a/Tank/src/ObjectParameters.java +++ b/Tank/src/ObjectParameters.java @@ -41,4 +41,4 @@ public class ObjectParameters { _width = width; _height = height; } -} +} \ No newline at end of file -- 2.25.1 From a3c081c02a5007fa0d09f736c0885df7f3aa44b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Sun, 29 Oct 2023 19:16:33 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/FormTank.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tank/src/FormTank.java b/Tank/src/FormTank.java index 0e3ff97..793d872 100644 --- a/Tank/src/FormTank.java +++ b/Tank/src/FormTank.java @@ -22,19 +22,19 @@ public class FormTank { JButton buttonStrategysStep = new JButton("Шаг"); JComboBox ComboBoxStrategy = new JComboBox(new String[]{"к центру", "к краю формочки"}); - Icon iconUp = new ImageIcon("Resources/KeyUp.png"); + Icon iconUp = new ImageIcon("Tank//Resources//KeyUp.png"); JButton up = new JButton(iconUp); up.setName("up"); - Icon iconDown = new ImageIcon("Resources/KeyDown.png"); + Icon iconDown = new ImageIcon("Tank//Resources//KeyDown.png"); JButton down = new JButton(iconDown); down.setName("down"); - Icon iconRight = new ImageIcon("Resources/KeyRight.png"); + Icon iconRight = new ImageIcon("Tank//Resources//KeyRight.png"); JButton right = new JButton(iconRight); right.setName("right"); - Icon iconLeft = new ImageIcon("Resources/KeyLeft.png"); + Icon iconLeft = new ImageIcon("Tank//Resources//KeyLeft.png"); JButton left = new JButton(iconLeft); left.setName("left"); -- 2.25.1 From bac51aa40cf82e6698a6f7a615ccf330bedd753d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Sun, 29 Oct 2023 19:21:52 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/src/CountWheels.java | 4 ++-- Tank/src/DrawingWheelsCombination.java | 2 +- Tank/src/EntityArmoVehicle.java | 2 +- Tank/src/EntityTank.java | 3 +-- Tank/src/IMoveableObject.java | 2 +- Tank/src/Status.java | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Tank/src/CountWheels.java b/Tank/src/CountWheels.java index 2a7408e..dfe3b65 100644 --- a/Tank/src/CountWheels.java +++ b/Tank/src/CountWheels.java @@ -5,9 +5,9 @@ public enum CountWheels { Five(5); private final int Value; CountWheels(int Count){ - Value=Count; + Value = Count; } public int getCountWheels(){ return Value; } -} +} \ No newline at end of file diff --git a/Tank/src/DrawingWheelsCombination.java b/Tank/src/DrawingWheelsCombination.java index 000dea2..80f46a1 100644 --- a/Tank/src/DrawingWheelsCombination.java +++ b/Tank/src/DrawingWheelsCombination.java @@ -106,4 +106,4 @@ public class DrawingWheelsCombination implements IOrnamentForm { CaterpillarStar(g,_startPosX + 105, _startPosY + 12); } } -} +} \ No newline at end of file diff --git a/Tank/src/EntityArmoVehicle.java b/Tank/src/EntityArmoVehicle.java index bc35d94..f8e09c8 100644 --- a/Tank/src/EntityArmoVehicle.java +++ b/Tank/src/EntityArmoVehicle.java @@ -14,4 +14,4 @@ public class EntityArmoVehicle { numWheel = _numWheel; Step = (double) Speed * 200 / Weight; } -} +} \ No newline at end of file diff --git a/Tank/src/EntityTank.java b/Tank/src/EntityTank.java index bca2e31..ee6a1c3 100644 --- a/Tank/src/EntityTank.java +++ b/Tank/src/EntityTank.java @@ -6,8 +6,7 @@ public class EntityTank extends EntityArmoVehicle { public boolean Caterpillar; public boolean Tower; - public EntityTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower) - { + public EntityTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower) { super(speed, weight, bodyColor, _numWheel); AdditionalColor = additionalColor; BodyKit = bodyKit; diff --git a/Tank/src/IMoveableObject.java b/Tank/src/IMoveableObject.java index d8f4c08..934005c 100644 --- a/Tank/src/IMoveableObject.java +++ b/Tank/src/IMoveableObject.java @@ -10,4 +10,4 @@ public interface IMoveableObject { /// Изменение направления пермещения объекта void MoveObject(Direction direction); -} +} \ No newline at end of file diff --git a/Tank/src/Status.java b/Tank/src/Status.java index 6467ed7..388d5b4 100644 --- a/Tank/src/Status.java +++ b/Tank/src/Status.java @@ -2,4 +2,4 @@ public enum Status { NotInit, InProgress, Finish -} +} \ No newline at end of file -- 2.25.1 From 785a3bbfc0fab2db4065ae4a61abc9bf3b3c8ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Sun, 29 Oct 2023 19:30:06 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tank/Tank.iml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Tank/Tank.iml diff --git a/Tank/Tank.iml b/Tank/Tank.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Tank/Tank.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file -- 2.25.1