промежуточная

This commit is contained in:
AnnaLioness 2023-10-07 21:42:37 +04:00
parent 911e8bfdc5
commit 7b57f7dc42
6 changed files with 171 additions and 104 deletions

View File

@ -1,103 +1,36 @@
import java.awt.*;
public class DrawingContainerShip {
public EntityContainerShip EntityContainerShip;
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
private int _shipWidth = 110;
private int _shipHeight = 65;
public class DrawingContainerShip extends DrawingShip{
@Override
public EntityContainerShip EntityContainerShip;
private DrawingDecks drawingDecks;
public boolean Init(int speed, double weight, Color bodyColor, Color
additionalColor, boolean crane, boolean container, int deck, int width, int height)
public DrawingContainerShip(int speed, double weight, Color bodyColor, Color
additionalColor, boolean crane, boolean containers,int deck, int width, int height)
{
super(speed, weight, bodyColor,width, height, 110, 65);
if (EntityShip != null)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth < _shipWidth || _pictureHeight < _shipHeight)
{
return false;
}
EntityContainerShip = new EntityContainerShip();
EntityContainerShip.Init(speed, weight, bodyColor, additionalColor,
crane, container, deck);
drawingDecks = new DrawingDecks();
drawingDecks.setNumDecks(deck);
return true;
}
public void SetPosition(int x, int y)
{
_startPosX = Math.min(x, _pictureWidth - _shipWidth);
_startPosY = Math.min(y, _pictureHeight - _shipHeight);
}
public void MoveTransport(Direction direction)
{
if (EntityContainerShip == null)
{
return;
}
switch (direction)
{
case Left:
if (_startPosX - EntityContainerShip.Step > 0)
{
_startPosX -= (int)EntityContainerShip.Step;
}
break;
case Up:
if (_startPosY - EntityContainerShip.Step > 0)
{
_startPosY -= (int)EntityContainerShip.Step;
}
break;
case Right:
if (_startPosX + EntityContainerShip.Step + _shipWidth < _pictureWidth)
{
_startPosX += (int)EntityContainerShip.Step;
}
break;
case Down:
if (_startPosY + EntityContainerShip.Step + _shipHeight< _pictureHeight)
{
_startPosY += (int)EntityContainerShip.Step;
}
break;
}
EntityShip = new EntityContainerShip(speed, weight, bodyColor,
additionalColor, crane, containers, deck);
}
}
public void DrawShip(Graphics2D g)
{
if (EntityContainerShip == null)
{
return;
}
//Pen pen = new Pen(Color.Black);
//Brush adbrush = new SolidBrush(EntityContainerShip.AdditionalColor);
//Brush brBlue = new SolidBrush(Color.Blue);
g.setPaint(Color.BLUE);
// заполнение борта
int x[] = {_startPosX+ 20, _startPosX+40, _startPosX+110, _startPosX+130, _startPosX+ 20};
int y[] = {_startPosY+65,_startPosY+85, _startPosY+85, _startPosY+65, _startPosY+65};
g.fillPolygon(x, y, 5);
//борт корабля контур
g.setPaint(Color.BLACK);
int _x[] = {_startPosX+ 20, _startPosX+40, _startPosX+110, _startPosX+130, _startPosX+ 20};
int _y[] = {_startPosY+65,_startPosY+85, _startPosY+85, _startPosY+65, _startPosY+65};
g.drawPolyline(_x, _y, 5);
//рисунок на борту
g.drawLine(_startPosX + 43, _startPosY + 80, _startPosX + 47, _startPosY + 80);
g.drawLine(_startPosX + 45, _startPosY + 70, _startPosX + 45, _startPosY + 80);
g.drawLine(_startPosX + 40, _startPosY + 75, _startPosX + 50, _startPosY + 75);
if(EntityShip == null)
{
return;
}
if(!(EntityShip is EntityContainerShip)) {
return;
}
//контейнеры
if (EntityContainerShip.Conteiners)
{
g.setPaint(EntityContainerShip.AdditionalColor);
g.setPaint((EntityShip as EntityContainerShip).AdditionalColor);
super(DrawShip(g));
g.fillRect(_startPosX + 50, _startPosY + 55, 35, 10);
g.fillRect(_startPosX + 85, _startPosY + 55, 20, 10);
g.fillRect(_startPosX + 105, _startPosY + 50, 15, 15);

121
DrawingShip.java Normal file
View File

@ -0,0 +1,121 @@
import java.awt.*;
public class DrawingShip {
public EntityShip EntityShip;
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
private int _shipWidth = 110;
private int _shipHeight = 65;
private DrawingDecks drawingDecks;
public boolean CanMove(Direction direction)
{
if(EntityShip == null) return false;
switch(direction)
{
case Left:
return _startPosX - EntityShip.Step > 0;
case Right:
return _startPosX + _shipWidth + EntityShip.Step < _pictureWidth;
case Up:
return _startPosY - EntityShip.Step > 0;
case Down:
return _startPosY + _shipHeight+ EntityShip.Step < _pictureHeight;
default:
return false;
}
}
public DrawingShip(int speed, double weight, Color bodyColor, int width, int height)
{
if(width < _shipWidth || height < _shipHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityShip = new EntityShip(speed, weight, bodyColor);
}
protected DrawingShip(int speed, double weight, Color bodyColor, int width, int height, int shipWidth, int shipHeight)
{
if (width < _shipWidth || height < _shipHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_shipHeight = shipHeight;
_shipWidth = shipWidth;
EntityShip = new EntityShip(speed, weight, bodyColor);
}
public void SetPosition(int x, int y)
{
_startPosX = Math.min(x, _pictureWidth - _shipWidth);
_startPosY = Math.min(y, _pictureHeight - _shipHeight);
}
public void MoveTransport(Direction direction)
{
if (EntityShip == null)
{
return;
}
switch (direction)
{
case Left:
if (_startPosX - EntityShip.Step > 0)
{
_startPosX -= (int)EntityShip.Step;
}
break;
case Up:
if (_startPosY - EntityShip.Step > 0)
{
_startPosY -= (int)EntityShip.Step;
}
break;
case Right:
if (_startPosX + EntityShip.Step + _shipWidth < _pictureWidth)
{
_startPosX += (int)EntityShip.Step;
}
break;
case Down:
if (_startPosY + EntityShip.Step + _shipHeight< _pictureHeight)
{
_startPosY += (int)EntityShip.Step;
}
break;
}
}
public void DrawShip(Graphics2D g)
{
if (EntityShip == null)
{
return;
}
//Pen pen = new Pen(Color.Black);
//Brush adbrush = new SolidBrush(EntityContainerShip.AdditionalColor);
//Brush brBlue = new SolidBrush(Color.Blue);
g.setPaint(EntityShip.BodyColor);
// заполнение борта
int x[] = {_startPosX+ 20, _startPosX+40, _startPosX+110, _startPosX+130, _startPosX+ 20};
int y[] = {_startPosY+65,_startPosY+85, _startPosY+85, _startPosY+65, _startPosY+65};
g.fillPolygon(x, y, 5);
//борт корабля контур
g.setPaint(Color.BLACK);
int _x[] = {_startPosX+ 20, _startPosX+40, _startPosX+110, _startPosX+130, _startPosX+ 20};
int _y[] = {_startPosY+65,_startPosY+85, _startPosY+85, _startPosY+65, _startPosY+65};
g.drawPolyline(_x, _y, 5);
//рисунок на борту
g.drawLine(_startPosX + 43, _startPosY + 80, _startPosX + 47, _startPosY + 80);
g.drawLine(_startPosX + 45, _startPosY + 70, _startPosX + 45, _startPosY + 80);
g.drawLine(_startPosX + 40, _startPosY + 75, _startPosX + 50, _startPosY + 75);
drawingDecks.DrawDeck(_startPosX, _startPosY, g);
}
}

View File

@ -1,25 +1,19 @@
import java.awt.*;
public class EntityContainerShip {
public int Speed;
public double Weight;
public Color BodyColor;
public class EntityContainerShip extends EntityShip{
public Color AdditionalColor;
public boolean Crane;
public boolean Conteiners;
public int Deck;
public double Step;
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, boolean crane, boolean containers, int deck)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
public EntityContainerShip(int speed, double weight, Color bodyColor, Color
additionalColor, boolean crane, boolean containers, int deck)
{
super(speed, weight,bodyColor);
AdditionalColor = additionalColor;
Crane = crane;
Conteiners = containers;
Deck = deck;
Step = (double)Speed * 100 / Weight;
}
}

14
EntityShip.java Normal file
View File

@ -0,0 +1,14 @@
import java.awt.*;
public class EntityShip {
public int Speed;
public double Weight;
public Color BodyColor;
public double Step;
public EntityShip(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
Step = (double)Speed * 100 / Weight;
}
}

View File

@ -17,25 +17,25 @@ public class Form1 {
up.setFocusPainted(false);
up.setContentAreaFilled(false);
up.setName("up");
up.setIcon(new ImageIcon("photo11.png"));
up.setIcon(new ImageIcon("D:\\рабочий стол\\рпп\\лаб1.репозит.сложная\\PIbd21.LyovushkinaA.A.Container_ship.Complicated\\photo11.png"));
JButton down = new JButton();
down.setBorderPainted(false);
down.setFocusPainted(false);
down.setContentAreaFilled(false);
down.setName("down");
down.setIcon(new ImageIcon("photo33.png"));
down.setIcon(new ImageIcon("D:\\рабочий стол\\рпп\\лаб1.репозит.сложная\\PIbd21.LyovushkinaA.A.Container_ship.Complicated\\photo33.png"));
JButton left = new JButton();
left.setBorderPainted(false);
left.setFocusPainted(false);
left.setContentAreaFilled(false);
left.setName("left");
left.setIcon(new ImageIcon("photo44.png"));
left.setIcon(new ImageIcon("D:\\рабочий стол\\рпп\\лаб1.репозит.сложная\\PIbd21.LyovushkinaA.A.Container_ship.Complicated\\photo44.png"));
JButton right = new JButton();
right.setBorderPainted(false);
right.setFocusPainted(false);
right.setContentAreaFilled(false);
right.setName("right");
right.setIcon(new ImageIcon("photo22.png"));
right.setIcon(new ImageIcon("D:\\рабочий стол\\рпп\\лаб1.репозит.сложная\\PIbd21.LyovushkinaA.A.Container_ship.Complicated\\photo22.png"));
buttonCreate.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e){

5
Status.java Normal file
View File

@ -0,0 +1,5 @@
public enum Status {
NotInit,
InProgress,
Finish
}