Лабораторная работа №2

This commit is contained in:
Олег Кудринский 2024-06-08 13:34:28 +04:00
parent 7aa6219c78
commit 52c006a00a
7 changed files with 35 additions and 15 deletions

View File

@ -1,5 +1,5 @@
package DrawingShip; package DrawingShip;
import Entities.EntityContainerShip; import DiffDecks.DecksCount;
import Entities.EntityContainerShip; import Entities.EntityContainerShip;
import java.awt.*; import java.awt.*;
@ -9,28 +9,39 @@ public class DrawingContainerShip extends DrawingShip {
EntityShip = new EntityContainerShip(speed, weight, bodycolor, additionalcolor, crane, container); EntityShip = new EntityContainerShip(speed, weight, bodycolor, additionalcolor, crane, container);
SetAmountandTypeDecks(); SetAmountandTypeDecks();
} }
@Override @Override
public void DrawTransport(Graphics2D g) { public void DrawTransport(Graphics2D g) {
if (EntityShip == null || !(EntityShip instanceof EntityContainerShip containerShip) || _StartPosX == null || _StartPosY == null) if (EntityShip == null || !(EntityShip instanceof EntityContainerShip containerShip) || _StartPosX == null || _StartPosY == null)
return; return;
int y = _StartPosY;
int originalStartPosY = _StartPosY;
int containerOffsetY = 0;
if (containerShip.Crane) { if (containerShip.Crane) {
int craneX = _StartPosX + drawingShipWidth - 40; int craneX = _StartPosX + drawingShipWidth - 40;
int craneY = _StartPosY + drawingShipHeight - 90; int craneY = _StartPosY + drawingShipHeight - 90;
//кран
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
g.drawLine(craneX + 10, craneY + 40, craneX + 10, craneY); g.drawLine(craneX + 10, craneY + 40, craneX + 10, craneY);
g.drawLine(craneX + 10, craneY, craneX + 50, craneY); g.drawLine(craneX + 10, craneY, craneX + 50, craneY);
g.drawLine(craneX + 10, craneY, craneX + 50, craneY + 5); g.drawLine(craneX + 10, craneY, craneX + 50, craneY + 5);
g.drawLine(craneX + 50, craneY, craneX + 50, craneY + 30); g.drawLine(craneX + 50, craneY, craneX + 50, craneY + 30);
// хваталка крана
g.drawLine(craneX + 40, craneY + 30, craneX + 60, craneY + 30); g.drawLine(craneX + 40, craneY + 30, craneX + 60, craneY + 30);
g.drawLine(craneX + 40, craneY + 30, craneX + 40, craneY + 35); g.drawLine(craneX + 40, craneY + 30, craneX + 40, craneY + 35);
g.drawLine(craneX + 60, craneY + 30, craneX + 60, craneY + 35); g.drawLine(craneX + 60, craneY + 30, craneX + 60, craneY + 35);
_StartPosY += 30; containerOffsetY += 30;
} }
_StartPosY += containerOffsetY;
super.DrawTransport(g); super.DrawTransport(g);
_StartPosY = originalStartPosY;
int count_decks = 0; int count_decks = 0;
if (drawingDecks.getNumberOfDecks() != null) { if (drawingDecks.getNumberOfDecks() != null) {
switch (drawingDecks.getNumberOfDecks()) { switch (drawingDecks.getNumberOfDecks()) {
@ -45,19 +56,27 @@ public class DrawingContainerShip extends DrawingShip {
break; break;
} }
} }
if (containerShip.Container) {
g.setColor(Color.BLACK);
g.drawRect(_StartPosX + 70, _StartPosY + 15, 40, 15);
g.setColor(containerShip.getAdditionalColor());
g.fillRect(_StartPosX + 70, _StartPosY + 15, 40, 15);
g.setColor(Color.BLACK);
g.drawRect(_StartPosX + 90, _StartPosY + 20, 40, 15);
g.setColor(containerShip.getAdditionalColor());
g.fillRect(_StartPosX + 90, _StartPosY + 20, 40, 15);
int containerY;
if (count_decks == 0) {
containerY = _StartPosY + 15;
} else {
containerY = _StartPosY + 15 + containerOffsetY;
} }
if (containerShip.Container) {
// Draw containers
g.setColor(Color.BLACK);
g.drawRect(_StartPosX + 40, containerY, 40, 15);
g.setColor(containerShip.getAdditionalColor());
g.fillRect(_StartPosX + 40, containerY, 40, 15);
g.setColor(Color.BLACK);
g.drawRect(_StartPosX + 60, containerY + 5, 40, 15);
g.setColor(containerShip.getAdditionalColor());
g.fillRect(_StartPosX + 60, containerY + 5, 40, 15);
}
if (containerShip.Crane) { if (containerShip.Crane) {
_StartPosY -= 30;
drawingShipHeight += 30; drawingShipHeight += 30;
} }
} }

View File

@ -119,6 +119,7 @@ public class DrawingShip extends JPanel {
int y = _StartPosY; int y = _StartPosY;
g.setColor(EntityShip.getBodyColor()); g.setColor(EntityShip.getBodyColor());
if (drawingDecks.getNumberOfDecks() != null) { if (drawingDecks.getNumberOfDecks() != null) {
y += 30;
switch (drawingDecks.getNumberOfDecks()) { switch (drawingDecks.getNumberOfDecks()) {
case OneDeck: case OneDeck:
drawingDecks.DrawDecks(g, _StartPosX + 30, y, 80, 15, EntityShip.getBodyColor()); drawingDecks.DrawDecks(g, _StartPosX + 30, y, 80, 15, EntityShip.getBodyColor());