PIbd-11 Karakozov_AK LabWork03 Hard #3

Closed
insideq wants to merge 25 commits from LabWork03 into LabWork02
Showing only changes of commit 385f78a9e0 - Show all commits

View File

@ -1,207 +0,0 @@
import java.awt.*;
import java.util.Random;
public class DrawingExcavator {
private EntityExcavator EntityExcavator; // Класс-сущность
public DrawingRollers drawingRollers = null;
private Integer _startPosX; // Левая координата отрисовки
private Integer _startPosY; // Верхняя координата отрисовки
private Integer _pictureWidth; // Ширина окна отрисовки
private Integer _pictureHeight; // Высота окна отрисовки
private final int _drawingExcWidth = 120; // Ширина отрисовки трактора
private final int _drawingExcHeight = 70; // Высота отрисовки трактора
// Инициализация свойств
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean prop, boolean ladle){
EntityExcavator = new EntityExcavator();
EntityExcavator.Init(speed, weight, bodyColor, additionalColor, prop, ladle);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
drawingRollers = new DrawingRollers();
drawingRollers.setRollersCount((int)(Math.random() * 4));
}
// Смена границ формы отрисовки
public void SetPictureSize(int width, int height)
{
if (_drawingExcWidth > width || _drawingExcHeight > height)
{
return;
}
if (_startPosX != null && _startPosY != null) {
if (_startPosX < 0) { _startPosX = 0; }
if (_startPosX + _drawingExcWidth > width) { _startPosX = width - _drawingExcWidth; }
if (_startPosY < 0) { _startPosY = 0; }
if (_startPosY + _drawingExcHeight > height) { _startPosY = height - _drawingExcHeight; }
}
_pictureWidth = width;
_pictureHeight = height;
}
//Установка позиции Экскаватора
public void SetPosition(int x, int y){
if (_pictureWidth == null || _pictureHeight == null)
{
return;
}
if (x + _drawingExcWidth > _pictureWidth || x < 0) {
Random random = new Random();
_startPosX = random.nextInt(_pictureWidth - _drawingExcWidth);
}
else {
_startPosX = x;
}
if (y + _drawingExcHeight > _pictureHeight || y < 0) {
Random random = new Random();
_startPosY = random.nextInt(_pictureHeight - _drawingExcHeight);
}
else {
_startPosY = y;
}
}
// Изменение направления движения
public boolean MoveTransport(DirectionType direction){
if (EntityExcavator == null || _startPosX == null || _startPosY == null){
return false;
}
switch (direction) {
case Left:
if (_startPosX - EntityExcavator.Step > 0) {
_startPosX -= (int) EntityExcavator.Step;
}
return true;
case Up:
if (_startPosY - EntityExcavator.Step > 0) {
_startPosY -= (int) EntityExcavator.Step;
}
return true;
case Right:
if (_startPosX + EntityExcavator.Step < _pictureWidth - _drawingExcWidth) {
_startPosX += (int) EntityExcavator.Step;
}
return true;
case Down:
if (_startPosY + EntityExcavator.Step < _pictureHeight - _drawingExcHeight) {
_startPosY += (int) EntityExcavator.Step;
}
return true;
default:
return false;
}
}
// Отрисовка Экскаватора
public void DrawTransport(Graphics2D g){
if (EntityExcavator == null || _startPosX == null || _startPosY == null){
return;
}
// Границы экскаватора
g.setColor(Color.BLACK);
g.drawRect(_startPosX + 20, _startPosY + 25, 60, 20); // главная нижняя
g.drawRect(_startPosX + 35, _startPosY + 10, 5, 15);
g.drawRect(_startPosX + 55, _startPosY + 3, 22, 22); // кабина
g.setColor(EntityExcavator.getBodyColor());
g.fillRect(_startPosX + 21, _startPosY + 26, 59, 19);
g.fillRect(_startPosX + 36, _startPosY + 11, 4, 14);
g.setColor(Color.cyan);
g.fillRect(_startPosX + 56, _startPosY + 4, 21, 21);
// Гусеница
g.setColor(Color.BLACK);
g.drawRect(_startPosX + 24, _startPosY + 47, 48, 17);
// Основные катки
g.setColor(Color.BLACK);
g.drawOval(_startPosX + 15, _startPosY + 47, 17, 17);
g.drawOval(_startPosX + 63, _startPosY + 47, 17, 17);
g.setColor(EntityExcavator.getBodyColor());
g.fillOval(_startPosX + 15, _startPosY + 47, 17, 17);
g.fillOval(_startPosX + 63, _startPosY + 47, 17, 17);
// Малые катки
g.setColor(Color.BLACK);
g.drawOval(_startPosX + 40, _startPosY + 48, 5, 5);
g.drawOval(_startPosX + 50, _startPosY + 48, 5, 5);
g.setColor(EntityExcavator.getBodyColor());
g.fillOval(_startPosX + 40, _startPosY + 48, 5, 5);
g.fillOval(_startPosX + 50, _startPosY + 48, 5, 5);
if (EntityExcavator.getProp()){
g.setColor(Color.BLACK);
//Опоры
//справа
g.drawRect(_startPosX + 80, _startPosY + 40, 11, 3);
g.drawRect(_startPosX + 87, _startPosY + 43, 5, 25);
g.drawRect(_startPosX + 84, _startPosY + 68, 11, 3);
//слева
g.drawRect(_startPosX + 6, _startPosY + 40, 13, 3);
g.drawRect(_startPosX + 4, _startPosY + 43, 5, 25);
g.drawRect(_startPosX + 1, _startPosY + 68, 11, 3);
g.setColor(EntityExcavator.getAdditionalColor());
//покраска справа
g.fillRect(_startPosX + 81, _startPosY + 41, 10, 2);
g.fillRect(_startPosX + 88, _startPosY + 44, 4, 24);
g.fillRect(_startPosX + 85, _startPosY + 69, 10, 2);
//покраска слева
g.fillRect(_startPosX + 7, _startPosY + 41, 12, 2);
g.fillRect(_startPosX + 5, _startPosY + 44, 4, 24);
g.fillRect(_startPosX + 2, _startPosY + 69, 10, 2);
}
if(EntityExcavator.getLadle()){
g.setColor(Color.BLACK);
//Ковш
//ковш(стрела)
g.drawRect(_startPosX + 77, _startPosY + 17, 14, 8);
g.drawRect(_startPosX + 91, _startPosY + 9, 20, 7);
g.drawRect(_startPosX + 111, _startPosY + 17, 9, 20);
int[] pointsLadleX = {_startPosX + 120, _startPosX + 104, _startPosX + 120};
int[] pointsLadleY = {_startPosY + 37, _startPosY + 54, _startPosY + 54};
Polygon Ladle = new Polygon(pointsLadleX, pointsLadleY, 3);
g.drawPolygon(Ladle);
g.setColor(EntityExcavator.getAdditionalColor());
g.fillPolygon(Ladle);
//покраска
g.fillRect(_startPosX + 78, _startPosY + 18, 13, 7);
g.fillRect(_startPosX + 92, _startPosY + 10, 19, 6);
g.fillRect(_startPosX + 112, _startPosY + 18, 8, 19);
}
int x = _startPosX;
if (drawingRollers.getRollersCount() != null){
switch (drawingRollers.getRollersCount()){
case OneRoller:
drawingRollers.DrawRollers(g,x + 34, _startPosY + 55, 8, 8, EntityExcavator.getBodyColor());
break;
case TwoRollers:
drawingRollers.DrawRollers(g,x + 34, _startPosY + 55, 8, 8, EntityExcavator.getBodyColor());
drawingRollers.DrawRollers(g,x + 44, _startPosY + 55, 8, 8, EntityExcavator.getBodyColor());
break;
case ThreeRollers:
drawingRollers.DrawRollers(g,x + 34, _startPosY + 55, 8, 8, EntityExcavator.getBodyColor());
drawingRollers.DrawRollers(g,x + 44, _startPosY + 55, 8, 8, EntityExcavator.getBodyColor());
drawingRollers.DrawRollers(g,x + 54, _startPosY + 55, 8, 8, EntityExcavator.getBodyColor());
break;
}
}
}
}