файлы лабораторной

This commit is contained in:
Ivan_Starostin 2023-12-22 20:02:38 +04:00
parent 8a00c20a62
commit 23de842f82
4 changed files with 209 additions and 0 deletions

View File

@ -0,0 +1,7 @@
package drawing_objects;
public enum DecksNumber {
ONE,
TWO,
THREE
}

View File

@ -0,0 +1,8 @@
package drawing_objects;
public enum DirectionType {
UP,
DOWN,
LEFT,
RIGHT
}

View File

@ -0,0 +1,55 @@
package drawing_objects;
import java.awt.*;
//import java.util.Random;
public class DrawingDecks {
private DecksNumber number;
public void setNumber(int x){
switch (x){
case 1:
number = DecksNumber.ONE;
break;
case 2:
number = DecksNumber.TWO;
break;
case 3:
number = DecksNumber.THREE;
break;
default:
number = DecksNumber.ONE;
break;
}
}
public void drawAddDecks(Graphics2D graphics2D, int _startX, int _startY, int lainerwidth, Color color){
//прописать логику отрисовки палуб
int limit = 0;
if(number == DecksNumber.ONE){
limit = 1;
}
else if(number == DecksNumber.TWO){
limit = 2;
}
if(number == DecksNumber.THREE){
limit = 3;
}
BasicStroke pen = new BasicStroke(2);
graphics2D.setStroke(pen);
for(int i = 0; i < limit; i++) {
graphics2D.setPaint(Color.BLACK);
graphics2D.drawRect(_startX + i * 3, _startY - i * 10, lainerwidth - 5 * i -20, 8);
graphics2D.setPaint(color);
graphics2D.fillRect(_startX + i * 3, _startY - i * 10, lainerwidth - 5 * i -20, 9);
}
}
}
/*if(x <= 1 || x > 3){
number = DecksNumber.ONE;
}
if(x == 2)
number = DecksNumber.TWO;
if(x == 3)
number = DecksNumber.THREE;*/
//if(x == 1)
//number = DecksNumber.ONE;

View File

@ -0,0 +1,139 @@
package drawing_objects;
import entities.EntityLainer;
import java.awt.*;
public class DrawingLainer {
private EntityLainer entityLainer;
public EntityLainer getEntityLainer() {
return entityLainer;
}
private int pictureWidth;
private int pictureHeight;
private int startPosX;
private int startPosY;
private final int LAINER_WIDTH = 110;
public int getShipWidth() {return LAINER_WIDTH;}
private final int LAINER_HEIGHT = 70;
public int getShipHeight() {return LAINER_HEIGHT;}
private DrawingDecks drawingBlocks;
public boolean init(int speed, double weight, Color bodyColor, Color
additionalColor, boolean pool, boolean decks, int width, int height, int blocksNumber) {
if (width < LAINER_WIDTH || height < LAINER_HEIGHT)
return false;
pictureWidth = width;
pictureHeight = height;
entityLainer = new EntityLainer();
entityLainer.init(speed, weight, bodyColor, additionalColor, pool, decks);
drawingBlocks = new DrawingDecks();
drawingBlocks.setNumber(blocksNumber);
return true;
}
public void setPosition(int x, int y) {
if (x < 0 || y < 0 || x + LAINER_WIDTH > pictureWidth || y + LAINER_HEIGHT > pictureHeight) {
x = 0;
y = 0;
}
startPosX = x;
startPosY = y;
}
public void moveTransport(DirectionType direction) {
if (entityLainer == null)
return;
switch (direction) {
//влево
case LEFT :
if (startPosX - (int)entityLainer.getStep() > 0) {
startPosX -= (int) entityLainer.getStep();
}
else{
startPosX = 1;
}
break;
//вверх
case UP :
if (startPosY - (int)entityLainer.getStep() > 0) {
startPosY -= (int) entityLainer.getStep();
}
else{
startPosY = 1;
}
break;
// вправо
case RIGHT:
if (startPosX + LAINER_WIDTH + (int)entityLainer.getStep() < pictureWidth) {
startPosX += (int) entityLainer.getStep();
}
else{
startPosX = pictureWidth - LAINER_WIDTH;
}
break;
//вниз
case DOWN :
if (startPosY + LAINER_HEIGHT + (int)entityLainer.getStep() < pictureHeight) {
startPosY += (int) entityLainer.getStep();
}
else{
startPosY = pictureHeight - LAINER_HEIGHT - 1;
}
break;
}
}
public void drawTransport(Graphics2D graphics2D) {
if (entityLainer == null)
return;
BasicStroke pen = new BasicStroke(2);
graphics2D.setStroke(pen);
Color bodyColor = entityLainer.getBodyColor();
Color additionalColor = entityLainer.getAdditionalColor();
//корпус
graphics2D.setPaint(Color.BLUE);
int[] pointsX = { startPosX, startPosX + LAINER_WIDTH, startPosX + 80, startPosX + 20 };
int[] pointsY = { startPosY +40, startPosY + 40, startPosY + 70, startPosY + 70 };
Polygon pol = new Polygon(pointsX, pointsY, 4);
graphics2D.fillPolygon(pol);
//возможно трубы
/*Brush brush = new SolidBrush(Color.Black);
Rectangle smokestack1 = new Rectangle(_startPosX + 20, _startPosY, 20, 50);
Rectangle smokestack2 = new Rectangle(_startPosX + 60, _startPosY, 20, 50);
g.FillRectangle(brush, smokestack1);
g.FillRectangle(brush, smokestack2);*/
//1 палуба
int newposX = startPosX+5;
int newposY = startPosY+30;
graphics2D.setPaint(bodyColor);
graphics2D.fillRect(newposX, newposY, LAINER_WIDTH - 10, 10);
newposX+=2;
newposY-=10;
//доп палубы
if (drawingBlocks != null){
drawingBlocks.drawAddDecks(graphics2D, newposX, newposY, LAINER_WIDTH, additionalColor);
}
for (int i = 1; i < 5; i++)
{
graphics2D.setPaint(Color.cyan);
graphics2D.fillOval(startPosX + i * 16, startPosY+ 28, 12, 12);
}
//бассейн
if (entityLainer.getPool()) {
graphics2D.setPaint(Color.cyan);
graphics2D.fillOval(startPosX + 15, startPosY + 35, 35, 12);
graphics2D.setPaint(Color.DARK_GRAY);
graphics2D.fillRect(startPosX + 15, startPosY + 30, 35, 20);
//лестница
graphics2D.setPaint(Color.BLACK);
graphics2D.setStroke(pen);
graphics2D.drawLine(startPosX + 18, startPosY + 35, startPosX + 18, startPosY + 70);
graphics2D.drawLine(startPosX + 30, startPosY + 35, startPosX + 30, startPosY + 70);
for(int i = 0; i < 4; i++)
{
graphics2D.drawLine(startPosX + 18, startPosY + 35 + i*10, startPosX + 30, startPosY + 35 + i * 10);
}
}
}
}