From d50c303c9fff783041fd287337351451efb22949 Mon Sep 17 00:00:00 2001 From: ZakenChannel Date: Wed, 10 Apr 2024 14:10:09 +0400 Subject: [PATCH] refactored code --- .../com/projectairfighter/FormAirFighter.java | 12 +++---- .../FormWarPlaneCollection.java | 4 +-- .../AbstractCompany.java | 32 +++++++++---------- .../collectiongenericobjects/Hangar.java | 24 +++++++------- .../com/projectairfighter/FormAirFighter.fxml | 2 +- .../FormWarPlaneCollection.fxml | 32 ++++++------------- 6 files changed, 47 insertions(+), 59 deletions(-) diff --git a/ProjectAirFighter/src/main/java/com/projectairfighter/FormAirFighter.java b/ProjectAirFighter/src/main/java/com/projectairfighter/FormAirFighter.java index 2b80082..f38b42c 100644 --- a/ProjectAirFighter/src/main/java/com/projectairfighter/FormAirFighter.java +++ b/ProjectAirFighter/src/main/java/com/projectairfighter/FormAirFighter.java @@ -30,7 +30,7 @@ public class FormAirFighter extends Application { private ComboBox comboBoxStrategy; @FXML - private void ButtonStrategy(){ + private void buttonStrategy(){ if (drawningWarPlane == null) return; if (!comboBoxStrategy.isDisabled()) { @@ -54,7 +54,7 @@ public class FormAirFighter extends Application { return; comboBoxStrategy.setDisable(true); strategy.makeStep(); - Draw(); + draw(); if (strategy.getStatus() == StrategyStatus.Finish){ comboBoxStrategy.setDisable(false); strategy = null; @@ -68,7 +68,7 @@ public class FormAirFighter extends Application { Button btn = (Button) event.getSource(); DirectionType direction = DirectionType.valueOf(btn.getId().toUpperCase()); boolean result = drawningWarPlane.moveTransport(direction); - if (result) Draw(); + if (result) draw(); } // Нажатие кнопок двжиения клавиатурой @@ -78,11 +78,11 @@ public class FormAirFighter extends Application { Button btn = (Button) event.getSource(); DirectionType direction = DirectionType.valueOf(btn.getId().toUpperCase()); boolean result = drawningWarPlane.moveTransport(direction); - if (result) Draw(); + if (result) draw(); } // Функция отрисовки объекта - private void Draw() { + private void draw() { if (drawningWarPlane == null) return; GraphicsContext gc = canvasAirFighter.getGraphicsContext2D(); gc.clearRect(0, 0, canvasAirFighter.getWidth(), canvasAirFighter.getHeight()); @@ -94,7 +94,7 @@ public class FormAirFighter extends Application { this.drawningWarPlane.setPictureSize((int) canvasAirFighter.getWidth(), (int) canvasAirFighter.getHeight()); comboBoxStrategy.setDisable(false); strategy = null; - Draw(); + draw(); } @FXML diff --git a/ProjectAirFighter/src/main/java/com/projectairfighter/FormWarPlaneCollection.java b/ProjectAirFighter/src/main/java/com/projectairfighter/FormWarPlaneCollection.java index 83bd9bf..22e47bc 100644 --- a/ProjectAirFighter/src/main/java/com/projectairfighter/FormWarPlaneCollection.java +++ b/ProjectAirFighter/src/main/java/com/projectairfighter/FormWarPlaneCollection.java @@ -96,7 +96,7 @@ public class FormWarPlaneCollection extends Application { } @FXML - private void ButtonRefresh(ActionEvent event){ + private void buttonRefresh(ActionEvent event){ if (company == null) return; company.show(canvasWarPlane); @@ -126,7 +126,7 @@ public class FormWarPlaneCollection extends Application { } @FXML - private void ButtonGoToCheck(ActionEvent event){ + private void buttonGoToCheck(ActionEvent event){ if (company == null) return; DrawningWarPlane warPlane = null; diff --git a/ProjectAirFighter/src/main/java/com/projectairfighter/collectiongenericobjects/AbstractCompany.java b/ProjectAirFighter/src/main/java/com/projectairfighter/collectiongenericobjects/AbstractCompany.java index 03e79b1..032d85e 100644 --- a/ProjectAirFighter/src/main/java/com/projectairfighter/collectiongenericobjects/AbstractCompany.java +++ b/ProjectAirFighter/src/main/java/com/projectairfighter/collectiongenericobjects/AbstractCompany.java @@ -7,39 +7,39 @@ import javafx.scene.canvas.GraphicsContext; import java.util.Random; public abstract class AbstractCompany { - protected final int _placeSizeWidth = 210; - protected final int _placeSizeHeight = 150; + protected final int placeSizeWidth = 210; + protected final int placeSizeHeight = 150; - protected final int _pictureWidth; - protected final int _pictureHeight; + protected final int pictureWidth; + protected final int pictureHeight; - protected ICollectionGenericObjects _collection = null; + protected ICollectionGenericObjects collection = null; private int getMaxCount() { - return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + return pictureWidth * pictureHeight / (placeSizeWidth * placeSizeHeight); } public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) { - _pictureWidth = picWidth; - _pictureHeight = picHeight; - _collection = collection; - _collection.setMaxCount(getMaxCount()); + pictureWidth = picWidth; + pictureHeight = picHeight; + this.collection = collection; + this.collection.setMaxCount(getMaxCount()); } public int addPlane(DrawningWarPlane plane) { - if (_collection == null) { + if (collection == null) { return -1; } - return _collection.insert(plane); + return collection.insert(plane); } public DrawningWarPlane removePlane(int position) { - return _collection != null ? _collection.remove(position) : null; + return collection != null ? collection.remove(position) : null; } public DrawningWarPlane getRandomPlane() { Random rnd = new Random(); - return _collection != null ? _collection.get(rnd.nextInt(getMaxCount())) : null; + return collection != null ? collection.get(rnd.nextInt(getMaxCount())) : null; } public void show(Canvas canvas) { @@ -48,8 +48,8 @@ public abstract class AbstractCompany { drawBackground(graphicsContext); setObjectsPosition(); - for (int i = 0; i < (_collection != null ? _collection.getCount() : 0); i++) { - DrawningWarPlane obj = _collection.get(i); + for (int i = 0; i < (collection != null ? collection.getCount() : 0); i++) { + DrawningWarPlane obj = collection.get(i); if (obj != null) obj.drawTransport(graphicsContext); } } diff --git a/ProjectAirFighter/src/main/java/com/projectairfighter/collectiongenericobjects/Hangar.java b/ProjectAirFighter/src/main/java/com/projectairfighter/collectiongenericobjects/Hangar.java index c4c5249..40520f2 100644 --- a/ProjectAirFighter/src/main/java/com/projectairfighter/collectiongenericobjects/Hangar.java +++ b/ProjectAirFighter/src/main/java/com/projectairfighter/collectiongenericobjects/Hangar.java @@ -15,27 +15,27 @@ public class Hangar extends AbstractCompany { gc.setLineWidth(3); int posX = 0; - for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { + for (int i = 0; i < pictureWidth / placeSizeWidth; i++) { int posY = 0; - gc.strokeLine(posX, posY, posX, posY + _placeSizeHeight * (_pictureHeight / _placeSizeHeight)); - for (int j = 0; j <= _pictureHeight / _placeSizeHeight; j++) { - gc.strokeLine(posX, posY, posX + _placeSizeWidth - 30, posY); - posY += _placeSizeHeight; + gc.strokeLine(posX, posY, posX, posY + placeSizeHeight * (pictureHeight / placeSizeHeight)); + for (int j = 0; j <= pictureHeight / placeSizeHeight; j++) { + gc.strokeLine(posX, posY, posX + placeSizeWidth - 30, posY); + posY += placeSizeHeight; } - posX += _placeSizeWidth; + posX += placeSizeWidth; } } @Override protected void setObjectsPosition() { int counter = 0; - int valPlaceY = _pictureHeight / _placeSizeHeight; - int valPlaceX = _pictureWidth / _placeSizeWidth; - for (int y = ((valPlaceY - 1) * _placeSizeHeight) + 8; y >= 0; y -= _placeSizeHeight) { - for (int x = ((valPlaceX - 1) * _placeSizeWidth) + 10; x >= 0; x -= _placeSizeWidth) { - DrawningWarPlane plane = _collection != null ? _collection.get(counter) : null; + int valPlaceY = pictureHeight / placeSizeHeight; + int valPlaceX = pictureWidth / placeSizeWidth; + for (int y = ((valPlaceY - 1) * placeSizeHeight) + 8; y >= 0; y -= placeSizeHeight) { + for (int x = ((valPlaceX - 1) * placeSizeWidth) + 10; x >= 0; x -= placeSizeWidth) { + DrawningWarPlane plane = collection != null ? collection.get(counter) : null; if (plane != null) { - plane.setPictureSize(_pictureWidth, _pictureHeight); + plane.setPictureSize(pictureWidth, pictureHeight); plane.setPosition(x, y); } counter++; diff --git a/ProjectAirFighter/src/main/resources/com/projectairfighter/FormAirFighter.fxml b/ProjectAirFighter/src/main/resources/com/projectairfighter/FormAirFighter.fxml index d72a1a5..6272b6e 100644 --- a/ProjectAirFighter/src/main/resources/com/projectairfighter/FormAirFighter.fxml +++ b/ProjectAirFighter/src/main/resources/com/projectairfighter/FormAirFighter.fxml @@ -28,5 +28,5 @@ -