PIbd-23-Radaev-A.V.-Catamar.../DrawningCatamaran.java

167 lines
6.1 KiB
Java
Raw Normal View History

2023-12-01 20:37:58 +04:00
import java.awt.*;
import java.util.Random;
public class DrawningCatamaran {
2023-12-10 11:59:44 +04:00
protected EntityCatamaran EntityCatamaran;
2023-12-01 20:37:58 +04:00
private int _pictureWidth;
private int _pictureHeight;
2023-12-10 11:59:44 +04:00
protected int _startPosX = 0;
protected int _startPosY = 0;
protected int _catamaranWidth = 120;
protected int _catamaranHeight = 80;
protected IDraw DrawningOars;
2023-12-01 20:37:58 +04:00
2023-12-10 11:59:44 +04:00
public EntityCatamaran EntityCatamaran() {
2023-12-01 20:37:58 +04:00
return EntityCatamaran;
}
2023-12-10 11:59:44 +04:00
public DrawningCatamaran(int speed, double weight, Color bodyColor, Color oarColor, int width, int height,
boolean boduKit, boolean seats) {
if (width <= _catamaranWidth || height <= _catamaranHeight)
return;
2023-12-01 20:37:58 +04:00
Random rand = new Random();
_pictureWidth = width;
_pictureHeight = height;
2023-12-10 11:59:44 +04:00
EntityCatamaran = new EntityCatamaran(speed, weight, bodyColor, oarColor, boduKit, seats);
SetPosition(rand.nextInt(10,50),rand.nextInt(10,50));
DrawningOars = new DrawningOars(_startPosX, _startPosY, oarColor);
int variant = rand.nextInt(0, 3);
if (variant == 0)
DrawningOars = new DrawningOars(_startPosX, _startPosY, oarColor);
else if (variant == 1)
DrawningOars = new DrawningOarsOrn(_startPosX, _startPosY, oarColor);
else
DrawningOars = new DrawningOarsHandle(_startPosX, _startPosY, oarColor);
DrawningOars.ChangeOarsNumb(rand.nextInt(1, 4));
2023-12-01 20:37:58 +04:00
}
2023-12-10 11:59:44 +04:00
public void SetPosition(int x, int y) {
if (EntityCatamaran == null)
2023-12-01 20:37:58 +04:00
return;
_startPosX = x;
_startPosY = y;
2023-12-10 11:59:44 +04:00
// проверка говна - фикс
if (x + _catamaranWidth >= _pictureWidth || y + _catamaranHeight >= _pictureHeight) {
2023-12-01 20:37:58 +04:00
_startPosX = 0;
_startPosY = 0;
}
}
2023-12-10 11:59:44 +04:00
public int GetPosX() {
return _startPosX;
}
public int GetPosY() {
return _startPosY;
}
public int GetWidth() {
return _catamaranWidth;
}
public int GetHeight() {
return _catamaranHeight;
}
public boolean CanMove(DirectionType direction) {
2023-12-01 20:37:58 +04:00
if (EntityCatamaran == null)
2023-12-10 11:59:44 +04:00
return false;
boolean can = false;
switch (direction) {
case Left:
can = _startPosX - EntityCatamaran.Step() >= 0;
break;
case Right:
can = _startPosX + EntityCatamaran.Step() + _catamaranWidth < _pictureWidth;
break;
case Down:
can = _startPosY + EntityCatamaran.Step() + _catamaranHeight < _pictureHeight + 20;
break;
case Up:
can = _startPosY - EntityCatamaran.Step() >= 0;
break;
}
;
return can;
}
public void MoveTransport(DirectionType direction) {
if (!CanMove(direction) || EntityCatamaran == null)
2023-12-01 20:37:58 +04:00
return;
2023-12-10 11:59:44 +04:00
switch (direction) {
2023-12-01 20:37:58 +04:00
case Left:
if (_startPosX - EntityCatamaran.Step() >= 0)
2023-12-10 11:59:44 +04:00
_startPosX -= (int) EntityCatamaran.Step();
2023-12-01 20:37:58 +04:00
else
_startPosX = 0;
break;
case Up:
if (_startPosY - EntityCatamaran.Step() >= 0)
2023-12-10 11:59:44 +04:00
_startPosY -= (int) EntityCatamaran.Step();
2023-12-01 20:37:58 +04:00
else
_startPosY = 0;
break;
case Right:
if (_startPosX + _catamaranWidth + EntityCatamaran.Step() < _pictureWidth)
2023-12-10 11:59:44 +04:00
_startPosX += (int) EntityCatamaran.Step();
2023-12-01 20:37:58 +04:00
else
2023-12-10 11:59:44 +04:00
_startPosX = _pictureWidth - _catamaranWidth;
2023-12-01 20:37:58 +04:00
break;
case Down:
if (_startPosY + _catamaranHeight + EntityCatamaran.Step() < _pictureHeight)
2023-12-10 11:59:44 +04:00
_startPosY += (int) EntityCatamaran.Step();
2023-12-01 20:37:58 +04:00
else
_startPosY = _pictureHeight - _catamaranHeight;
break;
}
2023-12-10 11:59:44 +04:00
DrawningOars.ChangeX(_startPosX);
DrawningOars.ChangeY(_startPosY);
2023-12-01 20:37:58 +04:00
}
2023-12-10 11:59:44 +04:00
public void DrawnCatamaran(Graphics2D g2d) {
if (EntityCatamaran == null)
return;
2023-12-01 20:37:58 +04:00
g2d.setColor(EntityCatamaran.BodyColor());
// korpus
2023-12-10 11:59:44 +04:00
g2d.fillRect(_startPosX + 10, _startPosY + 10, _catamaranWidth - 50, 60);
2023-12-01 20:37:58 +04:00
// nos
2023-12-10 11:59:44 +04:00
int[] x_triag = { _startPosX + _catamaranWidth - 40, _startPosX + _catamaranWidth,
_startPosX + _catamaranWidth - 40 };
int[] y_triag = { _startPosY + 10, _startPosY + 40, _startPosY + 70 };
g2d.fillPolygon(x_triag, y_triag, 3);
2023-12-01 20:37:58 +04:00
// poplav
g2d.setColor(Color.DARK_GRAY);
2023-12-10 11:59:44 +04:00
int[] poplav1_x = { _startPosX + _catamaranWidth - 20, _startPosX + _catamaranWidth,
_startPosX + _catamaranWidth - 20 };
int[] poplav1_y = { _startPosY, _startPosY + 5, _startPosY + 10 };
g2d.fillPolygon(poplav1_x, poplav1_y, 3);
int[] poplav2_x = { _startPosX + _catamaranWidth - 20, _startPosX + _catamaranWidth,
_startPosX + _catamaranWidth - 20 };
int[] poplav2_y = { _startPosY + 70, _startPosY + 75, _startPosY + 80 };
g2d.fillPolygon(poplav2_x, poplav2_y, 3);
2023-12-01 20:37:58 +04:00
g2d.fillRect(_startPosX, _startPosY, _catamaranWidth - 20, 10);
2023-12-10 11:59:44 +04:00
g2d.fillRect(_startPosX, _startPosY + 70, _catamaranWidth - 20, 10);
2023-12-01 20:37:58 +04:00
//
g2d.setColor(Color.BLACK);
2023-12-10 11:59:44 +04:00
g2d.drawPolygon(poplav1_x, poplav1_y, 3);
g2d.drawPolygon(poplav2_x, poplav2_y, 3);
g2d.drawPolygon(x_triag, y_triag, 3);
g2d.drawRect(_startPosX + 10, _startPosY + 10, _catamaranWidth - 50, 60);
2023-12-01 20:37:58 +04:00
g2d.drawRect(_startPosX, _startPosY, _catamaranWidth - 20, 10);
2023-12-10 11:59:44 +04:00
g2d.drawRect(_startPosX, _startPosY + 70, _catamaranWidth - 20, 10);
2023-12-01 20:37:58 +04:00
// sedenie
g2d.setColor(Color.CYAN);
g2d.fillOval(_startPosX + 15, _startPosY + 25, 60, 30);
2023-12-10 11:59:44 +04:00
if (EntityCatamaran.Seats()) {
2023-12-01 20:37:58 +04:00
g2d.setColor(Color.ORANGE);
g2d.fillOval(_startPosX + 20, _startPosY + 35, 10, 10);
g2d.fillOval(_startPosX + 35, _startPosY + 35, 10, 10);
g2d.fillOval(_startPosX + 50, _startPosY + 35, 10, 10);
}
2023-12-10 11:59:44 +04:00
DrawningOars.DrawOars(g2d);
2023-12-01 20:37:58 +04:00
}
}