From da3355686d9c6dfc95e26b6f6144c88a676b5da0 Mon Sep 17 00:00:00 2001
From: ksenianeva <95441235+ksenianeva@users.noreply.github.com>
Date: Wed, 21 Dec 2022 21:54:47 +0400
Subject: [PATCH] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D1=83?=
=?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20?=
=?UTF-8?q?=D0=BB=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=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/containership/AbstractMap.java | 123 +++++++
.../src/containership/DecksType.java | 15 +
.../src/containership/Direction.java | 3 +-
.../containership/DrawingContainerShip.java | 55 ++++
.../src/containership/DrawingDecks.java | 29 +-
.../containership/DrawingDecksReversedTr.java | 123 +++++++
.../src/containership/DrawingDecksTropec.java | 125 +++++++
.../src/containership/DrawingObjectShip.java | 58 ++++
.../src/containership/DrawingShip.java | 56 +++-
.../containership/EntityContainerShip.java | 36 ++
.../src/containership/EntityShip.java | 4 +-
.../src/containership/IDrawingObject.java | 40 +++
.../src/containership/IDrawingObjectAdd.java | 18 +
.../src/containership/JFrame_Map.form | 228 +++++++++++++
.../src/containership/JFrame_Map.java | 308 ++++++++++++++++++
.../src/containership/JFrame_Ship.form | 46 ++-
.../src/containership/JFrame_Ship.java | 84 ++++-
.../src/containership/ModifyMap.java | 61 ++++
.../src/containership/SimpleMap.java | 60 ++++
19 files changed, 1426 insertions(+), 46 deletions(-)
create mode 100644 ContainerShip/src/containership/AbstractMap.java
create mode 100644 ContainerShip/src/containership/DecksType.java
create mode 100644 ContainerShip/src/containership/DrawingContainerShip.java
create mode 100644 ContainerShip/src/containership/DrawingDecksReversedTr.java
create mode 100644 ContainerShip/src/containership/DrawingDecksTropec.java
create mode 100644 ContainerShip/src/containership/DrawingObjectShip.java
create mode 100644 ContainerShip/src/containership/EntityContainerShip.java
create mode 100644 ContainerShip/src/containership/IDrawingObject.java
create mode 100644 ContainerShip/src/containership/IDrawingObjectAdd.java
create mode 100644 ContainerShip/src/containership/JFrame_Map.form
create mode 100644 ContainerShip/src/containership/JFrame_Map.java
create mode 100644 ContainerShip/src/containership/ModifyMap.java
create mode 100644 ContainerShip/src/containership/SimpleMap.java
diff --git a/ContainerShip/src/containership/AbstractMap.java b/ContainerShip/src/containership/AbstractMap.java
new file mode 100644
index 0000000..28ce517
--- /dev/null
+++ b/ContainerShip/src/containership/AbstractMap.java
@@ -0,0 +1,123 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package containership;
+
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.util.Random;
+
+/**
+ *
+ * @author ateks
+ */
+public abstract class AbstractMap {
+ private IDrawingObject _drawningObject = null;
+ protected int[][] _map = null;
+ protected int _width;
+ protected int _height;
+ protected int _size_x;
+ protected int _size_y;
+ protected final Random _random = new Random();
+ protected final int _freeRoad = 0;
+ protected final int _barrier = 1;
+
+ public BufferedImage CreateMap(int width, int height, IDrawingObject drawningObject)
+ {
+ _width = width;
+ _height = height;
+ _drawningObject = drawningObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+ public BufferedImage MoveObject(Direction direction)
+ {
+ if (_drawningObject == null) return DrawMapWithObject();
+ boolean canMove = true;
+ switch (direction)
+ {
+ case LEFT:
+ if (!checkForBarriers(0, -1 * _drawningObject.getStep(), -1 * _drawningObject.getStep(), 0)) canMove = false;
+ break;
+ case RIGHT:
+ if (!checkForBarriers(0, _drawningObject.getStep(), _drawningObject.getStep(), 0)) canMove = false;
+ break;
+ case UP:
+ if (!checkForBarriers(-1 * _drawningObject.getStep(), 0, 0, -1 * _drawningObject.getStep())) canMove = false;
+ break;
+ case DOWN:
+ if (!checkForBarriers(_drawningObject.getStep(), 0, 0, _drawningObject.getStep())) canMove = false;
+ break;
+ }
+ if (canMove)
+ {
+ _drawningObject.MoveObject(direction);
+ }
+ return DrawMapWithObject();
+ }
+ private boolean SetObjectOnMap()
+ {
+ if (_drawningObject == null || _map == null)
+ {
+ return false;
+ }
+ int x = _random.nextInt(0, 10);
+ int y = _random.nextInt(0, 10);
+ _drawningObject.SetObject(x, y, _width, _height);
+ if (!checkForBarriers(0,0,0,0)) return false;
+ return true;
+ }
+ private BufferedImage DrawMapWithObject()
+ {
+ BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB);
+ if (_drawningObject == null || _map == null)
+ {
+ return bmp;
+ }
+ Graphics2D gr = bmp.createGraphics();
+ for (int i = 0; i < _map.length; ++i)
+ {
+ for (int j = 0; j < _map[i].length; ++j)
+ {
+ if (_map[i][j] == _freeRoad)
+ {
+ DrawRoadPart(gr, i, j);
+ }
+ else if (_map[i][j] == _barrier)
+ {
+ DrawBarrierPart(gr, i, j);
+ }
+ }
+ }
+ _drawningObject.DrawingObject(gr);
+ return bmp;
+ }
+
+ private boolean checkForBarriers(float topOffset, float rightOffset, float leftOffset, float bottomOffset)
+ {
+ float[] position = _drawningObject.GetCurrentPosition();
+ int top = (int)((position[1] + topOffset) / _size_y);
+ int right = (int)((position[2] + rightOffset) / _size_x);
+ int left = (int)((position[0] + leftOffset) / _size_x);
+ int bottom = (int)((position[3] + bottomOffset) / _size_y);
+ if (top < 0 || left < 0 || right >= _map[0].length || bottom >= _map.length) return false;
+ for (int i = top; i <= bottom; i++)
+ {
+ for (int j = left; j <= right; j++)
+ {
+ if (_map[j][i] == 1) return false;
+ }
+ }
+ return true;
+ }
+
+ protected abstract void GenerateMap();
+ protected abstract void DrawRoadPart(Graphics g, int i, int j);
+ protected abstract void DrawBarrierPart(Graphics g, int i, int j);
+}
diff --git a/ContainerShip/src/containership/DecksType.java b/ContainerShip/src/containership/DecksType.java
new file mode 100644
index 0000000..e393f3b
--- /dev/null
+++ b/ContainerShip/src/containership/DecksType.java
@@ -0,0 +1,15 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package containership;
+
+/**
+ *
+ * @author ateks
+ */
+public enum DecksType {
+ RECTANGLE,
+ TROPEC,
+ REVERSEDTR
+}
diff --git a/ContainerShip/src/containership/Direction.java b/ContainerShip/src/containership/Direction.java
index 31e1a60..af5cd6d 100644
--- a/ContainerShip/src/containership/Direction.java
+++ b/ContainerShip/src/containership/Direction.java
@@ -12,5 +12,6 @@ public enum Direction {
UP,
DOWN,
LEFT,
- RIGHT
+ RIGHT,
+ NONE
}
\ No newline at end of file
diff --git a/ContainerShip/src/containership/DrawingContainerShip.java b/ContainerShip/src/containership/DrawingContainerShip.java
new file mode 100644
index 0000000..0f2774b
--- /dev/null
+++ b/ContainerShip/src/containership/DrawingContainerShip.java
@@ -0,0 +1,55 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package containership;
+import java.awt.*;
+/**
+ *
+ * @author ateks
+ */
+public class DrawingContainerShip extends DrawingShip {
+ public DrawingContainerShip(int speed, float weight, Color bodyColor, DecksType decksType, int numberOfDecks, Color dopColor, boolean containers, boolean crane)
+ {
+ super(speed, weight, bodyColor, decksType, numberOfDecks, 135, 55);
+ Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, containers, crane);
+ this.dopColor = dopColor;
+ }
+ Color dopColor;
+
+ @Override
+ public void DrawTransport(Graphics2D g)
+ {
+ if (!(Ship instanceof EntityContainerShip containerShip))
+ {
+ return;
+ }
+ if (containerShip.getCrane())
+ {
+ g.setColor(dopColor);
+ g.drawLine((int)(_startPosX), (int)(_startPosY+10), (int)(_startPosX+25), (int)(_startPosY+20));
+ g.drawLine((int)(_startPosX), (int)(_startPosY+10), (int)(_startPosX), (int)(_startPosY+22));
+ g.drawLine((int)(_startPosX), (int)(_startPosY+10), (int)(_startPosX), (int)(_startPosY+22));
+ g.drawLine((int)(_startPosX), (int)(_startPosY+10), (int)(_startPosX+25), (int)(_startPosY+10));
+ g.drawLine((int)(_startPosX+25), (int)(_startPosY+10), (int)(_startPosX+25), (int)(_startPosY+30));
+ g.setColor(Color.BLACK);
+ }
+
+ super.DrawTransport(g);
+
+ if (containerShip.getContainers())
+ {
+ g.setColor(dopColor);
+ g.fillRect((int)(_startPosX+35), (int)(_startPosY+20), 10, 10);
+ g.fillRect((int)(_startPosX+55), (int)(_startPosY+20), 20, 10);
+ g.fillRect((int)(_startPosX+75), (int)(_startPosY+15), 25, 15);
+ g.fillRect((int)(_startPosX+100), (int)(_startPosY+20), 25, 10);
+ g.setColor(Color.BLACK);
+ g.drawRect((int)(_startPosX+35), (int)(_startPosY+20), 10, 10);
+ g.drawRect((int)(_startPosX+55), (int)(_startPosY+20), 20, 10);
+ g.drawRect((int)(_startPosX+75), (int)(_startPosY+15), 25, 15);
+ g.drawRect((int)(_startPosX+100), (int)(_startPosY+20), 25, 10);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ContainerShip/src/containership/DrawingDecks.java b/ContainerShip/src/containership/DrawingDecks.java
index 65086b6..17c0ea0 100644
--- a/ContainerShip/src/containership/DrawingDecks.java
+++ b/ContainerShip/src/containership/DrawingDecks.java
@@ -11,15 +11,17 @@ import java.awt.Color;
*
* @author ateks
*/
-public class DrawingDecks {
+public class DrawingDecks implements IDrawingObjectAdd {
private Decks decks = null;
private int numberOfDecks;
+ @Override
public int getNumberOfDecks() {
return numberOfDecks;
}
+ @Override
public void setNumberOfDecks(int numberOfDecks) {
if (numberOfDecks != 1 && numberOfDecks != 2 && numberOfDecks != 3) {
return;
@@ -38,27 +40,15 @@ public class DrawingDecks {
}
}
+ @Override
public void drawBottomDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
- int[] curcuitY
- = {
- _startPosY + 30,
- _startPosY + 30,
- _startPosY + 55,
- _startPosY + 55,
- _startPosY + 30,};
- int[] curcuitX
- = {
- _startPosX + 100,
- _startPosX + 135,
- _startPosX + 115,
- _startPosX + 20,
- _startPosX,};
g.setColor(bodyColor);
- g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
+ g.fillRect(_startPosX, _startPosY + 30, 135, 25);
g.setColor(Color.BLACK);
- g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
+ g.drawRect(_startPosX, _startPosY + 30, 135, 25);
}
+ @Override
public void drawMiddleDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
g.setColor(bodyColor);
g.fillRect(_startPosX+30, _startPosY+15, 70, 15);
@@ -66,6 +56,7 @@ public class DrawingDecks {
g.drawRect(_startPosX+30, _startPosY+15, 70, 15 );
}
+ @Override
public void drawUpperDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
g.setColor(bodyColor);
g.fillRect(_startPosX+50, _startPosY, 45, 15 );
@@ -75,6 +66,7 @@ public class DrawingDecks {
}
+ @Override
public void drawDecks(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
if (decks == null) {
return;
@@ -88,6 +80,5 @@ public class DrawingDecks {
drawBottomDeck(g, _startPosX, _startPosY, bodyColor);
break;
}
-
}
-}
+}
\ No newline at end of file
diff --git a/ContainerShip/src/containership/DrawingDecksReversedTr.java b/ContainerShip/src/containership/DrawingDecksReversedTr.java
new file mode 100644
index 0000000..f7bc08a
--- /dev/null
+++ b/ContainerShip/src/containership/DrawingDecksReversedTr.java
@@ -0,0 +1,123 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package containership;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+
+/**
+ *
+ * @author ateks
+ */
+public class DrawingDecksReversedTr implements IDrawingObjectAdd {
+
+ private Decks decks = null;
+ private int numberOfDecks;
+
+ @Override
+ public int getNumberOfDecks() {
+ return numberOfDecks;
+ }
+
+ @Override
+ public void setNumberOfDecks(int numberOfDecks) {
+ if (numberOfDecks != 1 && numberOfDecks != 2 && numberOfDecks != 3){
+ return;
+ }
+ this.numberOfDecks = numberOfDecks;
+ switch (this.numberOfDecks) {
+ case 1:
+ decks = Decks.ONE;
+ break;
+ case 2:
+ decks = Decks.TWO;
+ break;
+ case 3:
+ decks = Decks.THREE;
+ break;
+ }
+ }
+
+ @Override
+ public void drawDecks(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
+ if (decks == null) {
+ return;
+ }
+ switch (decks) {
+ case THREE:
+ drawUpperDeck(g, _startPosX, _startPosY, bodyColor);
+ case TWO:
+ drawMiddleDeck(g, _startPosX, _startPosY, bodyColor);
+ case ONE:
+ drawBottomDeck(g, _startPosX, _startPosY, bodyColor);
+ break;
+ }
+ }
+
+ @Override
+ public void drawBottomDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
+ int[] curcuitY
+ = {
+ _startPosY + 30,
+ _startPosY + 30,
+ _startPosY + 55,
+ _startPosY + 55,};
+ int[] curcuitX
+ = {
+ _startPosX + 5,
+ _startPosX + 130,
+ _startPosX + 135,
+ _startPosX,};
+ g.setColor(bodyColor);
+ g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
+ g.setColor(Color.BLACK);
+ g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
+ }
+
+ @Override
+ public void drawMiddleDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
+ g.setColor(bodyColor);
+ int[] curcuitY
+ = {
+ _startPosY + 30,
+ _startPosY + 15,
+ _startPosY + 15,
+ _startPosY + 30,
+ } ;
+ int[] curcuitX
+ = {
+ _startPosX + 30,
+ _startPosX + 40,
+ _startPosX + 90,
+ _startPosX + 100,
+ } ;
+ g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
+ g.setColor(Color.BLACK);
+ g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
+ }
+
+ @Override
+ public void drawUpperDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
+ g.setColor(bodyColor);
+ int[] curcuitY
+ = {
+ _startPosY + 15,
+ _startPosY,
+ _startPosY,
+ _startPosY + 15,
+ } ;
+ int[] curcuitX
+ = {
+ _startPosX + 50,
+ _startPosX + 55,
+ _startPosX + 80,
+ _startPosX + 85,
+ } ;
+ g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
+ g.setColor(Color.BLACK);
+ g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
+ }
+
+}
\ No newline at end of file
diff --git a/ContainerShip/src/containership/DrawingDecksTropec.java b/ContainerShip/src/containership/DrawingDecksTropec.java
new file mode 100644
index 0000000..78b46d6
--- /dev/null
+++ b/ContainerShip/src/containership/DrawingDecksTropec.java
@@ -0,0 +1,125 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package containership;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+
+/**
+ *
+ * @author ateks
+ */
+public class DrawingDecksTropec implements IDrawingObjectAdd {
+
+ private Decks decks = null;
+ private int numberOfDecks;
+
+ @Override
+ public int getNumberOfDecks() {
+ return numberOfDecks;
+ }
+
+ @Override
+ public void setNumberOfDecks(int numberOfDecks) {
+ if (numberOfDecks != 1 && numberOfDecks != 2 && numberOfDecks != 3){
+ return;
+ }
+ this.numberOfDecks = numberOfDecks;
+ switch (this.numberOfDecks) {
+ case 1:
+ decks = Decks.ONE;
+ break;
+ case 2:
+ decks = Decks.TWO;
+ break;
+ case 3:
+ decks = Decks.THREE;
+ break;
+ }
+ }
+
+ @Override
+ public void drawDecks(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
+ if (decks == null) {
+ return;
+ }
+ switch (decks) {
+ case THREE:
+ drawUpperDeck(g, _startPosX, _startPosY, bodyColor);
+ case TWO:
+ drawMiddleDeck(g, _startPosX, _startPosY, bodyColor);
+ case ONE:
+ drawBottomDeck(g, _startPosX, _startPosY, bodyColor);
+ break;
+ }
+ }
+
+ @Override
+ public void drawBottomDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
+ int[] curcuitY
+ = {
+ _startPosY + 30,
+ _startPosY + 30,
+ _startPosY + 55,
+ _startPosY + 55,
+ _startPosY + 30,};
+ int[] curcuitX
+ = {
+ _startPosX + 100,
+ _startPosX + 135,
+ _startPosX + 115,
+ _startPosX + 20,
+ _startPosX,};
+ g.setColor(bodyColor);
+ g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
+ g.setColor(Color.BLACK);
+ g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
+ }
+
+ @Override
+ public void drawMiddleDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
+ g.setColor(bodyColor);
+ int[] curcuitY
+ = {
+ _startPosY + 15,
+ _startPosY + 30,
+ _startPosY + 30,
+ _startPosY + 15,
+ } ;
+ int[] curcuitX
+ = {
+ _startPosX + 30,
+ _startPosX + 40,
+ _startPosX + 90,
+ _startPosX + 100,
+ } ;
+ g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
+ g.setColor(Color.BLACK);
+ g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
+ }
+
+ @Override
+ public void drawUpperDeck(Graphics2D g, int _startPosX, int _startPosY, Color bodyColor) {
+ g.setColor(bodyColor);
+ int[] curcuitY
+ = {
+ _startPosY,
+ _startPosY + 15,
+ _startPosY + 15,
+ _startPosY,
+ } ;
+ int[] curcuitX
+ = {
+ _startPosX + 50,
+ _startPosX + 55,
+ _startPosX + 90,
+ _startPosX + 95,
+ } ;
+ g.fillPolygon(curcuitX, curcuitY, curcuitX.length);
+ g.setColor(Color.BLACK);
+ g.drawPolygon(curcuitX, curcuitY, curcuitX.length);
+ }
+
+}
diff --git a/ContainerShip/src/containership/DrawingObjectShip.java b/ContainerShip/src/containership/DrawingObjectShip.java
new file mode 100644
index 0000000..b03280b
--- /dev/null
+++ b/ContainerShip/src/containership/DrawingObjectShip.java
@@ -0,0 +1,58 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package containership;
+import java.awt.*;
+
+/**
+ *
+ * @author ateks
+ */
+public class DrawingObjectShip implements IDrawingObject {
+ private DrawingShip _ship = null;
+
+ public DrawingObjectShip(DrawingShip ship)
+ {
+ _ship = ship;
+ Step = _ship.Ship.Step;
+ }
+
+ public float Step;
+ @Override
+ public float getStep(){
+ return Step;
+ }
+
+ @Override
+ public float[] GetCurrentPosition()
+ {
+ if (_ship == null) return null;
+ return _ship.GetCurrentPosition();
+ }
+ @Override
+ public void MoveObject(Direction direction)
+ {
+ _ship.MoveTransport(direction);
+ }
+ @Override
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _ship.SetPosition(x, y, width, height);
+ }
+
+ @Override
+ public void DrawingObject(Graphics2D g)
+ {
+ if (_ship == null) return;
+ if (_ship instanceof DrawingContainerShip containerShip)
+ {
+ containerShip.DrawTransport(g);
+ }
+ else
+ {
+ _ship.DrawTransport(g);
+ }
+ }
+}
+
diff --git a/ContainerShip/src/containership/DrawingShip.java b/ContainerShip/src/containership/DrawingShip.java
index d5057ec..033052b 100644
--- a/ContainerShip/src/containership/DrawingShip.java
+++ b/ContainerShip/src/containership/DrawingShip.java
@@ -10,22 +10,47 @@ import java.util.Random;
* @author ateks
*/
public class DrawingShip {
- private EntityShip Ship;
+ public EntityShip Ship;
//отрисовка палуб
- public DrawingDecks drawingDecks;
+ public IDrawingObjectAdd drawingDecks;
public float _startPosX;
public float _startPosY;
private Integer _pictureWidth = null;
private Integer _pictureHeight = null;
- private static final int _shipWidth = 135;
- private static final int _shipHeight = 40;
+ private static int _shipWidth = 135;
+ private static int _shipHeight = 55;
- public void Init(int speed, float weight, Color bodyColor, int numberOfDecks){
- Ship = new EntityShip();
- // мметод прорисовки палуб
- drawingDecks = new DrawingDecks();
- Ship.Init(speed, weight, bodyColor);
- drawingDecks.setNumberOfDecks(numberOfDecks);/////// палубы
+ public DrawingShip(int speed, float weight, Color bodyColor, DecksType decksType, int numberOfDecks){
+ Ship = new EntityShip(speed, weight, bodyColor);
+ switch(decksType){
+ case RECTANGLE:
+ drawingDecks = new DrawingDecks();
+ break;
+ case TROPEC:
+ drawingDecks = new DrawingDecksTropec();
+ break;
+ case REVERSEDTR:
+ drawingDecks = new DrawingDecksReversedTr();
+ break;
+ }
+ drawingDecks.setNumberOfDecks(numberOfDecks);//палубы
+ }
+ public DrawingShip(int speed, float weight, Color bodyColor, DecksType decksType, int numberOfDecks, int width, int height){
+ Ship = new EntityShip(speed, weight, bodyColor);
+ _shipWidth = width;
+ _shipHeight = height;
+ switch(decksType){
+ case RECTANGLE:
+ drawingDecks = new DrawingDecks();
+ break;
+ case TROPEC:
+ drawingDecks = new DrawingDecksTropec();
+ break;
+ case REVERSEDTR:
+ drawingDecks = new DrawingDecksReversedTr();
+ break;
+ }
+ drawingDecks.setNumberOfDecks(numberOfDecks);//палубы
}
public EntityShip getShip() {
@@ -109,4 +134,13 @@ public class DrawingShip {
_startPosY = _pictureHeight - _shipHeight;
}
}
-}
+ public float [] GetCurrentPosition()
+ {
+ float[] pos = new float[4];
+ pos[0] = _startPosX;
+ pos[1] = _startPosY;
+ pos[2] = _startPosX + _shipWidth;
+ pos[3] = _startPosY + _shipHeight;
+ return pos;
+ }
+}
\ No newline at end of file
diff --git a/ContainerShip/src/containership/EntityContainerShip.java b/ContainerShip/src/containership/EntityContainerShip.java
new file mode 100644
index 0000000..d4a6c47
--- /dev/null
+++ b/ContainerShip/src/containership/EntityContainerShip.java
@@ -0,0 +1,36 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package containership;
+import java.awt.*;
+/**
+ *
+ * @author ateks
+ */
+public class EntityContainerShip extends EntityShip {
+ private Color DopColor;
+ private boolean containers;
+ private boolean crane;
+
+
+ public Color getDopColor() {
+ return DopColor;
+ }
+
+ public boolean getContainers(){
+ return containers;
+ }
+
+ public boolean getCrane(){
+ return crane;
+ }
+
+ public EntityContainerShip(int speed, float weight, Color bodyColor, Color dopColor, boolean containers, boolean crane)
+ {
+ super(speed, weight, bodyColor);
+ DopColor = dopColor;
+ this.containers = containers;
+ this.crane = crane;
+ }
+}
diff --git a/ContainerShip/src/containership/EntityShip.java b/ContainerShip/src/containership/EntityShip.java
index dbc2590..d1a7513 100644
--- a/ContainerShip/src/containership/EntityShip.java
+++ b/ContainerShip/src/containership/EntityShip.java
@@ -30,9 +30,7 @@ public class EntityShip {
return BodyColor;
}
-
-
- public void Init(int speed, float weight, Color bodyColor){
+ public EntityShip(int speed, float weight, Color bodyColor){
Random rnd = new Random();
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
diff --git a/ContainerShip/src/containership/IDrawingObject.java b/ContainerShip/src/containership/IDrawingObject.java
new file mode 100644
index 0000000..cff20e2
--- /dev/null
+++ b/ContainerShip/src/containership/IDrawingObject.java
@@ -0,0 +1,40 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
+ */
+package containership;
+import java.awt.*;
+/**
+ *
+ * @author ateks
+ */
+public interface IDrawingObject {
+ ///