Compare commits

..

No commits in common. "LabWork02" and "master" have entirely different histories.

25 changed files with 0 additions and 1363 deletions

View File

@ -1,117 +0,0 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;
public abstract class AbstractMap {
private IDrawningObject _drawningObject = null;
protected int[][] _map = null;
protected int _width;
protected int _height;
protected float _size_x;
protected float _size_y;
protected final Random _random = new Random();
protected final int _freeRoad = 0;
protected final int _barrier = 1;
public Image CreateMap(int width, int height, IDrawningObject drawningObject)
{
_width = width;
_height = height;
_drawningObject = drawningObject;
do {
GenerateMap();
} while (!SetObjectOnMap());
return DrawMapWithObject();
}
public Image MoveObject(Direction direction)
{
_drawningObject.moveObject(direction);
if (objectIntersects()) {
switch (direction) {
case Left -> _drawningObject.moveObject(Direction.Right);
case Right -> _drawningObject.moveObject(Direction.Left);
case Up -> _drawningObject.moveObject(Direction.Down);
case Down -> _drawningObject.moveObject(Direction.Up);
}
}
return DrawMapWithObject();
}
private boolean SetObjectOnMap()
{
if (_drawningObject == null || _map == null)
{
return false;
}
int x = _random.nextInt(0, 10);
int y = _random.nextInt(0, 10);
_drawningObject.setObject(x, y, _width, _height);
var Location = _drawningObject.getCurrentPosition();
if (objectIntersects()){
int startLocX = (int)(Location[0] / _size_x);
int startLocY = (int)(Location[2] / _size_y);
int endLocX = (int)(Location[1] / _size_x);
int endLocY = (int)(Location[3] / _size_y);
for (int j = startLocX; j <= endLocX; j++)
{
for (int i = startLocY; i <= endLocY; i++)
{
if (_map[i][j] == _barrier) _map[i][j] = _freeRoad;
}
}
}
return true;
}
private boolean objectIntersects() {
float[] location = _drawningObject.getCurrentPosition();
Rectangle self = new Rectangle((int) location[0], (int) location[2], (int) location[1] - (int) location[0], (int) location[3] - (int) location[2]);
for (int i = 0; i < _map.length; i++)
{
for (int j = 0; j < _map[i].length; j++)
{
if (_map[i][j] == _barrier)
{
if (self.intersects(new Rectangle(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y)))
{
return true;
}
}
}
}
return false;
}
private Image DrawMapWithObject() {
Image img = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB);
if (_drawningObject == null || _map == null) {
return img;
}
Graphics2D g = (Graphics2D) img.getGraphics();
for (int i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[i].length; ++j)
{
if (_map[i][j] == _freeRoad)
{
DrawRoadPart(g, i, j);
} else if (_map[i][j] == _barrier)
{
DrawBarrierPart(g, i, j);
}
}
}
_drawningObject.drawningObject(g);
return img;
}
protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics2D g, int i, int j);
protected abstract void DrawBarrierPart(Graphics2D g, int i, int j);
}

View File

@ -1,7 +0,0 @@
public enum Direction {
Up,
Down,
Left,
Right,
None
}

View File

@ -1,94 +0,0 @@
import java.awt.*;
public class DrawningCrossRollers implements IDrawningRollers{
private RollersCount rollersCount;
private Color colorRollers;
public void setRollersCount(int count){
switch (count) {
case 4 -> rollersCount = RollersCount.Four;
case 5 -> rollersCount = RollersCount.Five;
case 6 -> rollersCount = RollersCount.Six;
default -> rollersCount = RollersCount.Four;
}
}
public DrawningCrossRollers(int count, Color colorRollers){
setRollersCount(count);
this.colorRollers = colorRollers;
}
public void DrawRollers(Graphics2D g, float _startPosX, float _startPosY){
Color penColor = Color.BLACK;
Color mainColor = colorRollers==null ? Color.LIGHT_GRAY : colorRollers;
// Крупные катки - всегда
// 1
g.setColor(mainColor);
g.fillOval((int)_startPosX + 5, (int)_startPosY + 60, 22, 22);
g.setColor(penColor);
g.drawOval((int)_startPosX + 5, (int)_startPosY + 60, 22, 22);
// вертикальное перекрестие
g.fillRect((int)_startPosX + 14, (int)_startPosY + 65, 5, 14);
// горизонтальное перекрестие
g.fillRect((int)_startPosX + 10, (int)_startPosY + 69, 13, 5);
// 2
g.setColor(mainColor);
g.fillOval((int)_startPosX + 83, (int)_startPosY + 60, 22, 22);
g.setColor(penColor);
g.drawOval((int)_startPosX + 83, (int)_startPosY + 60, 22, 22);
// вертикальное перекрестие
g.fillRect((int)_startPosX + 92, (int)_startPosY + 65, 5, 14);
// горизонтальное перекрестие
g.fillRect((int)_startPosX + 88, (int)_startPosY + 69, 13, 5);
// Малые катки - всегда
// 1
g.setColor(mainColor);
g.fillOval((int)_startPosX + 43, (int)_startPosY + 58, 6, 6);
g.setColor(penColor);
g.drawOval((int)_startPosX + 43, (int)_startPosY + 58, 6, 6);
// вертикальное перекрестие
g.fillRect((int)_startPosX + 46, (int)_startPosY + 60, 1, 3);
// горизонтальное перекрестие
g.fillRect((int)_startPosX + 45, (int)_startPosY + 61, 3, 1);
// 2
g.setColor(mainColor);
g.fillOval((int)_startPosX + 61, (int)_startPosY + 58, 6, 6);
g.setColor(penColor);
g.drawOval((int)_startPosX + 61, (int)_startPosY + 58, 6, 6);
// вертикальное перекрестие
g.fillRect((int)_startPosX + 64, (int)_startPosY + 60, 1, 3);
// горизонтальное перекрестие
g.fillRect((int)_startPosX + 63, (int)_startPosY + 61, 3, 1);
// Средние катки - не всегда
switch (rollersCount){
case Six:
// 1
g.setColor(mainColor);
g.fillOval((int)_startPosX + 33, (int)_startPosY + 73, 10, 10);
g.setColor(penColor);
g.drawOval((int)_startPosX + 33, (int)_startPosY + 73, 10, 10);
// вертикальное перекрестие
g.fillRect((int)_startPosX + 37, (int)_startPosY + 75, 2, 6);
// горизонтальное перекрестие
g.fillRect((int)_startPosX + 35, (int)_startPosY + 77, 6, 2);
case Five:
// 2
g.setColor(mainColor);
g.fillOval((int)_startPosX + 68, (int)_startPosY + 73, 10, 10);
g.setColor(penColor);
g.drawOval((int)_startPosX + 68, (int)_startPosY + 73, 10, 10);
// вертикальное перекрестие
g.fillRect((int)_startPosX + 72, (int)_startPosY + 75, 2, 6);
// горизонтальное перекрестие
g.fillRect((int)_startPosX + 70, (int)_startPosY + 77, 6, 2);
}
// Центры крупных катков
g.setColor(Color.BLACK);
g.fillOval((int)_startPosX + 13, (int)_startPosY + 68, 6, 6);
g.fillOval((int)_startPosX + 91, (int)_startPosY + 68, 6, 6);
}
}

View File

@ -1,38 +0,0 @@
import javax.print.DocFlavor;
import java.awt.*;
public class DrawningObjectExcavator implements IDrawningObject{
private DrawningTracktor _tracktor = null;
public DrawningObjectExcavator(DrawningTracktor tracktor) {
this._tracktor = tracktor;
}
public float getStep() {
if (_tracktor != null && _tracktor.Tracktor != null) {
return _tracktor.Tracktor.getStep();
}
return 0;
}
public float[] getCurrentPosition() {
if (_tracktor != null) {
return _tracktor.getCurrentPosition();
}
return new float[] { 0, 0, 0, 0 };
}
public void moveObject(Direction direction) {
if (_tracktor != null) {
_tracktor.MoveTransport(direction);
}
}
public void setObject(int x, int y, int width, int height) {
_tracktor.SetPosition(x, y, width, height);
}
public void drawningObject(Graphics2D g) {
_tracktor.DrawTransport(g);
}
}

View File

@ -1,70 +0,0 @@
import java.awt.*;
public class DrawningRollers implements IDrawningRollers {
private RollersCount rollersCount;
private Color colorRollers;
public void setRollersCount(int count){
switch (count) {
case 4 -> rollersCount = RollersCount.Four;
case 5 -> rollersCount = RollersCount.Five;
case 6 -> rollersCount = RollersCount.Six;
default -> rollersCount = RollersCount.Four;
}
}
public DrawningRollers(int count, Color colorRollers){
setRollersCount(count);
this.colorRollers = colorRollers;
}
public void DrawRollers(Graphics2D g, float _startPosX, float _startPosY){
Color penColor = Color.BLACK;
Color mainColor = colorRollers==null ? Color.LIGHT_GRAY : colorRollers;
// Крупные катки - всегда
// 1
g.setColor(mainColor);
g.fillOval((int)_startPosX + 5, (int)_startPosY + 60, 22, 22);
g.setColor(penColor);
g.drawOval((int)_startPosX + 5, (int)_startPosY + 60, 22, 22);
// 2
g.setColor(mainColor);
g.fillOval((int)_startPosX + 83, (int)_startPosY + 60, 22, 22);
g.setColor(penColor);
g.drawOval((int)_startPosX + 83, (int)_startPosY + 60, 22, 22);
// Малые катки - всегда
// 1
g.setColor(mainColor);
g.fillOval((int)_startPosX + 43, (int)_startPosY + 58, 6, 6);
g.setColor(penColor);
g.drawOval((int)_startPosX + 43, (int)_startPosY + 58, 6, 6);
// 2
g.setColor(mainColor);
g.fillOval((int)_startPosX + 61, (int)_startPosY + 58, 6, 6);
g.setColor(penColor);
g.drawOval((int)_startPosX + 61, (int)_startPosY + 58, 6, 6);
// Средние катки - не всегда
switch (rollersCount){
case Six:
// 1
g.setColor(mainColor);
g.fillOval((int)_startPosX + 33, (int)_startPosY + 73, 10, 10);
g.setColor(penColor);
g.drawOval((int)_startPosX + 33, (int)_startPosY + 73, 10, 10);
case Five:
// 2
g.setColor(mainColor);
g.fillOval((int)_startPosX + 68, (int)_startPosY + 73, 10, 10);
g.setColor(penColor);
g.drawOval((int)_startPosX + 68, (int)_startPosY + 73, 10, 10);
}
// Центры крупных катков
g.setColor(Color.BLACK);
g.fillOval((int)_startPosX + 13, (int)_startPosY + 68, 6, 6);
g.fillOval((int)_startPosX + 91, (int)_startPosY + 68, 6, 6);
}
}

View File

@ -1,125 +0,0 @@
import java.awt.*;
public class DrawningSquaredRollers implements IDrawningRollers {
private RollersCount rollersCount;
private Color colorRollers;
public void setRollersCount(int count){
switch (count) {
case 4 -> rollersCount = RollersCount.Four;
case 5 -> rollersCount = RollersCount.Five;
case 6 -> rollersCount = RollersCount.Six;
default -> rollersCount = RollersCount.Four;
}
}
public DrawningSquaredRollers(int count, Color colorRollers){
setRollersCount(count);
this.colorRollers = colorRollers;
}
public void DrawRollers(Graphics2D g, float _startPosX, float _startPosY){
Color penColor = Color.BLACK;
Color mainColor = colorRollers==null ? Color.LIGHT_GRAY : colorRollers;
// Крупные катки - всегда
// Узор для больших катков
Polygon bigRomb = new Polygon(
new int[]{(int)_startPosX + 5, (int)_startPosX + 16, (int)_startPosX + 27, (int)_startPosX + 16},
new int[]{(int)_startPosY + 71, (int)_startPosY + 60, (int)_startPosY + 71, (int)_startPosY + 82},
4
);
Polygon bigCube = new Polygon(
new int[]{(int)_startPosX + 10, (int)_startPosX + 22, (int)_startPosX + 22, (int)_startPosX + 10},
new int[]{(int)_startPosY + 65, (int)_startPosY + 65, (int)_startPosY + 77, (int)_startPosY + 77},
4
);
// 1
g.setColor(mainColor);
g.fillOval((int)_startPosX + 5, (int)_startPosY + 60, 22, 22);
g.setColor(penColor);
g.drawOval((int)_startPosX + 5, (int)_startPosY + 60, 22, 22);
g.drawPolygon(bigRomb);
g.drawPolygon(bigCube);
// Сдвиг
bigRomb.translate(78,0);
bigCube.translate(78,0);
// 2
g.setColor(mainColor);
g.fillOval((int)_startPosX + 83, (int)_startPosY + 60, 22, 22);
g.setColor(penColor);
g.drawOval((int)_startPosX + 83, (int)_startPosY + 60, 22, 22);
g.drawPolygon(bigRomb);
g.drawPolygon(bigCube);
// Малые катки - всегда
// Узор
Polygon smallRomb = new Polygon(
new int[]{(int)_startPosX + 43, (int)_startPosX + 46, (int)_startPosX + 49, (int)_startPosX + 46},
new int[]{(int)_startPosY + 61, (int)_startPosY + 58, (int)_startPosY + 61, (int)_startPosY + 64},
4
);
Polygon smallCube = new Polygon(
new int[]{(int)_startPosX + 44, (int)_startPosX + 48, (int)_startPosX + 48, (int)_startPosX + 44},
new int[]{(int)_startPosY + 59, (int)_startPosY + 63, (int)_startPosY + 63, (int)_startPosY + 59},
4
);
// 1
g.setColor(mainColor);
g.fillOval((int)_startPosX + 43, (int)_startPosY + 58, 6, 6);
g.setColor(penColor);
g.drawOval((int)_startPosX + 43, (int)_startPosY + 58, 6, 6);
g.drawPolygon(smallRomb);
g.drawPolygon(smallCube);
// Сдвиг
smallRomb.translate(18,0);
smallCube.translate(18,0);
// 2
g.setColor(mainColor);
g.fillOval((int)_startPosX + 61, (int)_startPosY + 58, 6, 6);
g.setColor(penColor);
g.drawOval((int)_startPosX + 61, (int)_startPosY + 58, 6, 6);
g.drawPolygon(smallRomb);
g.drawPolygon(smallCube);
// Средние катки - не всегда
// Узор
Polygon middleRomb = new Polygon(
new int[]{(int)_startPosX + 33, (int)_startPosX + 38, (int)_startPosX + 43, (int)_startPosX + 38},
new int[]{(int)_startPosY + 78, (int)_startPosY + 73, (int)_startPosY + 78, (int)_startPosY + 83},
4
);
Polygon middleCube = new Polygon(
new int[]{(int)_startPosX + 35, (int)_startPosX + 41, (int)_startPosX + 41, (int)_startPosX + 35},
new int[]{(int)_startPosY + 75, (int)_startPosY + 75, (int)_startPosY + 81, (int)_startPosY + 81},
4
);
switch (rollersCount){
case Six:
// 1
g.setColor(mainColor);
g.fillOval((int)_startPosX + 33, (int)_startPosY + 73, 10, 10);
g.setColor(penColor);
g.drawOval((int)_startPosX + 33, (int)_startPosY + 73, 10, 10);
g.drawPolygon(middleRomb);
g.drawPolygon(middleCube);
case Five:
// Сдвиг
middleRomb.translate(35,0);
middleCube.translate(35,0);
// 2
g.setColor(mainColor);
g.fillOval((int)_startPosX + 68, (int)_startPosY + 73, 10, 10);
g.setColor(penColor);
g.drawOval((int)_startPosX + 68, (int)_startPosY + 73, 10, 10);
g.drawPolygon(middleRomb);
g.drawPolygon(middleCube);
}
// Центры крупных катков
g.setColor(Color.BLACK);
g.fillOval((int)_startPosX + 13, (int)_startPosY + 68, 6, 6);
g.fillOval((int)_startPosX + 91, (int)_startPosY + 68, 6, 6);
}
}

View File

@ -1,57 +0,0 @@
import java.awt.*;
public class DrawningTrackedVehicle extends DrawningTracktor {
public DrawningTrackedVehicle(int speed, float weight, Color bodyColor, int countRollers, Color dopColor, boolean bucket, boolean supports){
super(speed, weight, bodyColor, countRollers, 130, 87);
Tracktor = new EntityTrackedVehicle(speed, weight, bodyColor, dopColor, bucket, supports);
}
@Override
public void DrawTransport(Graphics2D g){
if (!(Tracktor instanceof EntityTrackedVehicle trackedVehicle))
{
return;
}
Color pen;
Color dopBrush = trackedVehicle.getDopColor();
if (trackedVehicle.getBucket())
{
pen = trackedVehicle.getDopColor();
g.setStroke(new BasicStroke(5));
g.setColor(pen);
g.drawLine((int)_startPosX + 1, (int)_startPosY + 90, (int)_startPosX + 15, (int)_startPosY + 70);
g.drawLine((int)_startPosX + 15, (int)_startPosY + 72, (int)_startPosX + 15, (int)_startPosY + 50);
g.drawLine((int)_startPosX + 15, (int)_startPosY + 52, (int)_startPosX + 10, (int)_startPosY + 45);
g.drawLine((int)_startPosX + 15, (int)_startPosY + 60, (int)_startPosX + 40, (int)_startPosY + 50);
g.setStroke(new BasicStroke(1));
}
_startPosX += 20;
_startPosY += 5;
super.DrawTransport(g);
_startPosX -= 20;
_startPosY -= 5;
if (trackedVehicle.getSupports())
{
pen = Color.BLACK;
g.setColor(dopBrush);
g.fillRect((int)_startPosX + 100, (int)_startPosY + 50, 10, 42);
g.setColor(pen);
g.drawRect((int)_startPosX + 100, (int)_startPosY + 50, 10, 42);
g.setColor(dopBrush);
g.fillRect((int)_startPosX + 90, (int)_startPosY + 82, 30, 10);
g.setColor(pen);
g.drawRect((int)_startPosX + 90, (int)_startPosY + 82, 30, 10);
g.setColor(dopBrush);
g.fillRect((int)_startPosX + 45, (int)_startPosY + 50, 10, 42);
g.setColor(pen);
g.drawRect((int)_startPosX + 45, (int)_startPosY + 50, 10, 42);
g.setColor(dopBrush);
g.fillRect((int)_startPosX + 35, (int)_startPosY + 82, 30, 10);
g.setColor(pen);
g.drawRect((int)_startPosX + 35, (int)_startPosY + 82, 30, 10);
}
}
}

View File

@ -1,172 +0,0 @@
import java.awt.*;
// Класс, отвечающий за прорисовку и перемещение объекта-сущности
public class DrawningTracktor {
protected EntityTracktor Tracktor; // Класс-сущность
public EntityTracktor getTracktor(){
return Tracktor;
}
protected float _startPosX; // Левая координата отрисовки трактора
protected float _startPosY; // Верхняя кооридната отрисовки трактора
private Integer _pictureWidth = null; // Ширина окна отрисовки
private Integer _pictureHeight = null; // Высота окна отрисовки
protected int _tracktorWidth = 110; // Ширина отрисовки трактора
protected int _tracktorHeight = 87; // Высота отрисовки трактора
private IDrawningRollers drawningRollers;
// Инициализация свойств
public DrawningTracktor(int speed, float weight, Color bodyColor, int countRollers)
{
Tracktor = new EntityTracktor(speed, weight, bodyColor);
drawningRollers = RollersType.random(countRollers, bodyColor);
}
protected DrawningTracktor(int speed, float weight, Color bodyColor, int countRollers, int tracktorWidth, int tracktorHeight){
this(speed, weight, bodyColor, countRollers);
_tracktorWidth = tracktorWidth;
_tracktorHeight = tracktorHeight;
}
// Установка позиции Трактора
public void SetPosition(int x, int y, int width, int height)
{
if (x + _tracktorWidth > width ||
x < 0 ||
y + _tracktorHeight > height ||
y < 0)
{
return;
}
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
// Изменение направления перемещения
public void MoveTransport(Direction direction)
{
if (_pictureWidth == null || _pictureHeight == null)
{
return;
}
switch (direction)
{
// вправо
case Right:
if (_startPosX + _tracktorWidth + Tracktor.getStep() < _pictureWidth)
{
_startPosX += Tracktor.getStep();
}
break;
//влево
case Left:
if (_startPosX - Tracktor.getStep() > 0)
{
_startPosX -= Tracktor.getStep();
}
break;
//вверх
case Up:
if (_startPosY - Tracktor.getStep() > 0)
{
_startPosY -= Tracktor.getStep();
}
break;
//вниз
case Down:
if (_startPosY + _tracktorHeight + Tracktor.getStep() < _pictureHeight)
{
_startPosY += Tracktor.getStep();
}
break;
}
}
// Отрисовка Трактора
public void DrawTransport(Graphics2D g)
{
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
{
return;
}
Color penColor = Color.BLACK;
// корпус
Color br = Tracktor!=null ? Tracktor.getBodyColor() : Color.GRAY ;
g.setColor(br);
g.fillRect((int)_startPosX + 10, (int)_startPosY + 30, 90, 25);
g.setColor(penColor);
g.drawRect((int)_startPosX + 10, (int)_startPosY + 30, 90, 25);
// окно
g.setColor(Color.CYAN);
g.fillRect((int)_startPosX + 65, (int)_startPosY + 1, 30, 29);
g.setColor(penColor);
g.drawRect((int)_startPosX + 65, (int)_startPosY + 1, 30, 29);
// труба
g.setColor(Color.RED);
g.fillRect((int)_startPosX + 30, (int)_startPosY + 10, 10, 20);
g.setColor(penColor);
g.drawRect((int)_startPosX + 30, (int)_startPosY + 10, 10, 20);
// гусеница
g.setColor(Color.DARK_GRAY);
g.fillOval((int)_startPosX + 1, (int)_startPosY + 57, 20, 20);
g.setColor(penColor);
g.drawOval((int)_startPosX + 1, (int)_startPosY + 57, 20, 20);
g.setColor(Color.DARK_GRAY);
g.fillOval((int)_startPosX + 1, (int)_startPosY + 65, 20, 20);
g.setColor(penColor);
g.drawOval((int)_startPosX + 1, (int)_startPosY + 65, 20, 20);
g.setColor(Color.DARK_GRAY);
g.fillOval((int)_startPosX + 90, (int)_startPosY + 57, 20, 20);
g.setColor(penColor);
g.drawOval((int)_startPosX + 90, (int)_startPosY + 57, 20, 20);
g.setColor(Color.DARK_GRAY);
g.fillOval((int)_startPosX + 90, (int)_startPosY + 65, 20, 20);
g.setColor(penColor);
g.drawOval((int)_startPosX + 90, (int)_startPosY + 65, 20, 20);
g.setColor(Color.DARK_GRAY);
g.fillRect((int)_startPosX + 10, (int)_startPosY + 57, 90, 30);
g.fillRect((int)_startPosX + 1, (int)_startPosY + 65, 110, 10);
g.setColor(penColor);
g.drawLine((int)_startPosX + 10, (int)_startPosY + 57, (int)_startPosX + 100, (int)_startPosY + 57);
g.drawLine((int)_startPosX + 10, (int)_startPosY + 86, (int)_startPosX + 100, (int)_startPosY + 86);
g.drawLine((int)_startPosX + 1, (int)_startPosY + 65, (int)_startPosX + 1, (int)_startPosY + 75);
g.drawLine((int)_startPosX + 110, (int)_startPosY + 65, (int)_startPosX + 110, (int)_startPosY + 75);
drawningRollers.DrawRollers(g, (int) _startPosX, (int) _startPosY);
}
// Смена границ формы отрисовки
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _tracktorWidth || _pictureHeight <= _tracktorHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _tracktorWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _tracktorWidth;
}
if (_startPosY + _tracktorHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _tracktorHeight;
}
}
public float[] getCurrentPosition() {
return new float[] { _startPosX, _startPosX + _tracktorWidth - 1, _startPosY, _startPosY + _tracktorHeight - 1 };
// Left - 0
// Right - 1
// Top - 2
// Bottom - 3
}
}

View File

@ -1,58 +0,0 @@
import java.awt.*;
public class DumpMap extends AbstractMap{
private final Color barrierColor = new Color(165,42,42);
private final Color roadColor = Color.LIGHT_GRAY;
@Override
protected void DrawBarrierPart(Graphics2D g, int j, int i)
{
g.setColor(barrierColor);
g.fillRect(i * (int)_size_x, j * (int)_size_y, (int)_size_x, (int)_size_y);
}
@Override
protected void DrawRoadPart(Graphics2D g, int j, int i)
{
g.setColor(roadColor);
g.fillRect(i * (int)_size_x, j * (int)_size_y, (int)_size_x, (int)_size_y);
}
@Override
protected void GenerateMap()
{
_map = new int[100][100];
_size_x = (float)_width / _map[0].length;
_size_y = (float)_height / _map.length;
int counter = 0;
for (int i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[0].length; ++j)
{
_map[i][j] = _freeRoad;
}
}
while (counter < 20)
{
int x = _random.nextInt(0, 100);
int y = _random.nextInt(0, 100);
if (_map[y][x] == _freeRoad && x > 1 && x < 98 && y > 1 && y < 98)
{
_map[y][x] = _barrier;
_map[y][x + 1] = _barrier;
_map[y][x + 2] = _barrier;
_map[y][x - 1] = _barrier;
_map[y][x - 2] = _barrier;
_map[y + 1][x] = _barrier;
_map[y + 2][x] = _barrier;
_map[y - 1][x] = _barrier;
_map[y - 2][x] = _barrier;
_map[y + 1][x + 1] = _barrier;
_map[y - 1][x + 1] = _barrier;
_map[y + 1][x - 1] = _barrier;
_map[y - 1][x - 1] = _barrier;
counter++;
}
}
}
}

View File

@ -1,29 +0,0 @@
import java.awt.*;
public class EntityTrackedVehicle extends EntityTracktor {
// Дополнительный цвет
private Color dopColor;
// Признак наличия ковша
private boolean bucket;
// Признак наличия опор
private boolean supports;
public EntityTrackedVehicle(int speed, float weight, Color bodyColor, Color dopColor, boolean bucket, boolean supports){
super(speed, weight, bodyColor);
this.dopColor = dopColor;
this.bucket = bucket;
this.supports = supports;
}
public Color getDopColor(){
return dopColor;
}
public boolean getBucket(){
return bucket;
}
public boolean getSupports(){
return supports;
}
}

View File

@ -1,31 +0,0 @@
import java.awt.*;
import java.util.Random;
// Класс-сущность "Трактор"
public class EntityTracktor {
private int Speed;
private float Weight;
private Color BodyColor;
public int getSpeed() {
return Speed;
}
public float getWeight(){
return Weight;
}
public Color getBodyColor(){
return BodyColor;
}
public float getStep(){
return Speed * 100 / Weight;
}
// Инициализация полей объекта-класса Трактора
public EntityTracktor(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
BodyColor = bodyColor;
}
}

View File

@ -1,137 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMap">
<grid id="27dc6" binding="ContentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="649" height="378"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="c78b3">
<constraints>
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="a12e7" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/arrowUp.png"/>
<text value=""/>
</properties>
</component>
<component id="5942f" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/arrowLeft.png"/>
<text value=""/>
</properties>
</component>
<component id="65b3a" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/arrowDown.png"/>
<text value=""/>
</properties>
</component>
<component id="233b7" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/arrowRight.png"/>
<text value=""/>
</properties>
</component>
<component id="22c" class="javax.swing.JLabel" binding="speedLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Скорость:"/>
</properties>
</component>
<component id="98c1e" class="javax.swing.JLabel" binding="weightLabel">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Вес:"/>
</properties>
</component>
<component id="252d3" class="javax.swing.JLabel" binding="colorLabel">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Цвет:"/>
</properties>
</component>
<component id="7e6d3" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<component id="f3e60" class="javax.swing.JButton" binding="buttonCreateModif">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Модификация"/>
</properties>
</component>
<grid id="98ed5" binding="pictureBox" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="ee7c6" class="javax.swing.JComboBox" binding="comboBoxMapSelector">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="Простая карта"/>
<item value="Свалка карта"/>
</model>
</properties>
</component>
<hspacer id="4e1e1">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="d19f">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -1,116 +0,0 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.util.Random;
public class FormMap extends JFrame {
private JPanel ContentPanel;
private JButton buttonCreate;
private JLabel speedLabel;
private JLabel weightLabel;
private JLabel colorLabel;
private JButton buttonLeft;
private JButton buttonDown;
private JButton buttonRight;
private JButton buttonUp;
private JPanel pictureBox;
private JButton buttonCreateModif;
private JComboBox<String> comboBoxMapSelector;
private AbstractMap _abstractMap;
private Image imageBuffer;
public FormMap(){
setTitle("Трактор");
setContentPane(ContentPanel);
setSize(800, 500);
_abstractMap = new SimpleMap();
// Обработка нажатия кнопки "Создать"
buttonCreate.addActionListener(e->{
Random rnd = new Random();
var _tracktor = new DrawningTracktor(
rnd.nextInt(100, 300),
rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
rnd.nextInt(3,8)
);
setData(_tracktor);
});
// Обработка нажатия кнопки "Модификация"
buttonCreateModif.addActionListener(e->{
Random rnd = new Random();
var _tracktor = new DrawningTrackedVehicle(
rnd.nextInt(100, 300),
rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
rnd.nextInt(3,8),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
rnd.nextBoolean(),
rnd.nextBoolean()
);
setData(_tracktor);
});
buttonUp.addActionListener(e->{
if (_abstractMap != null){
imageBuffer = _abstractMap.MoveObject(Direction.Up);
repaint();
}
});
buttonLeft.addActionListener(e->{
if (_abstractMap != null){
imageBuffer = _abstractMap.MoveObject(Direction.Left);
repaint();
}
});
buttonDown.addActionListener(e->{
if (_abstractMap != null){
imageBuffer = _abstractMap.MoveObject(Direction.Down);
repaint();
}
});
buttonRight.addActionListener(e->{
if (_abstractMap != null){
imageBuffer = _abstractMap.MoveObject(Direction.Right);
repaint();
}
});
comboBoxMapSelector.addItemListener(e->{
if (e.getStateChange()== ItemEvent.SELECTED){
switch (e.getItem().toString()) {
case "Простая карта" -> _abstractMap = new SimpleMap();
case "Свалка карта" -> _abstractMap = new DumpMap();
}
repaint();
}
});
}
private void setData(DrawningTracktor _tracktor) {
Random rnd = new Random();
_tracktor.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), pictureBox.getWidth(), pictureBox.getHeight());
speedLabel.setText("Скорость: " + _tracktor.getTracktor().getSpeed());
weightLabel.setText("Вес: " + _tracktor.getTracktor().getWeight());
colorLabel.setText("Цвет: " + String.format("%h",_tracktor.getTracktor().getBodyColor()));
imageBuffer = _abstractMap.CreateMap(pictureBox.getWidth(), pictureBox.getHeight(), new DrawningObjectExcavator(_tracktor));
repaint();
}
@Override
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D)pictureBox.getGraphics();
if (imageBuffer != null){
pictureBox.paintComponents(imageBuffer.getGraphics());
g2d.drawImage(imageBuffer,0,0,null);
}
}
}

View File

@ -1,115 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormTracktor">
<grid id="27dc6" binding="ContentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="8" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="661" height="428"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="eb389" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<hspacer id="7a016">
<constraints>
<grid row="1" column="2" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="83511" class="javax.swing.JLabel" binding="speedLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Скорость:"/>
</properties>
</component>
<component id="49134" class="javax.swing.JLabel" binding="weightLabel">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Вес:"/>
</properties>
</component>
<component id="15fa4" class="javax.swing.JLabel" binding="colorLabel">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Цвет:"/>
</properties>
</component>
<grid id="2fbf8" binding="pictureBox" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="8" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<component id="5a9f4" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/arrowLeft.png"/>
<text value=""/>
</properties>
</component>
<component id="3c09f" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/arrowDown.png"/>
<text value=""/>
</properties>
</component>
<component id="6d42a" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="2" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/arrowRight.png"/>
<text value=""/>
</properties>
</component>
<component id="82038" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="1" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/arrowUp.png"/>
<text value=""/>
</properties>
</component>
<component id="a11cc" class="javax.swing.JButton" binding="buttonCreateModif">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Модификация"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@ -1,111 +0,0 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Random;
public class FormTracktor extends JFrame {
private JPanel ContentPanel;
private JButton buttonCreate;
private JLabel speedLabel;
private JLabel weightLabel;
private JLabel colorLabel;
private JButton buttonLeft;
private JButton buttonDown;
private JButton buttonRight;
private JButton buttonUp;
private JPanel pictureBox;
private JButton buttonCreateModif;
private DrawningTracktor _tracktor;
public FormTracktor(){
setTitle("Трактор");
setContentPane(ContentPanel);
setSize(800, 500);
// Обработка нажатия кнопки "Создать"
buttonCreate.addActionListener(e->{
Random rnd = new Random();
_tracktor = new DrawningTracktor(
rnd.nextInt(100, 300),
rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
rnd.nextInt(3,8)
);
setData();
});
// Обработка нажатия кнопки "Модификация"
buttonCreateModif.addActionListener(e->{
Random rnd = new Random();
_tracktor = new DrawningTrackedVehicle(
rnd.nextInt(100, 300),
rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
rnd.nextInt(3,8),
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
rnd.nextBoolean(),
rnd.nextBoolean()
);
setData();
});
buttonUp.addActionListener(e->{
if (_tracktor != null){
_tracktor.MoveTransport(Direction.Up);
repaint();
}
});
buttonLeft.addActionListener(e->{
if (_tracktor != null){
_tracktor.MoveTransport(Direction.Left);
repaint();
}
});
buttonDown.addActionListener(e->{
if (_tracktor != null){
_tracktor.MoveTransport(Direction.Down);
repaint();
}
});
buttonRight.addActionListener(e->{
if (_tracktor != null){
_tracktor.MoveTransport(Direction.Right);
repaint();
}
});
pictureBox.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
if (_tracktor != null){
_tracktor.ChangeBorders(e.getComponent().getWidth(), e.getComponent().getHeight());
repaint();
}
}
});
}
private void setData() {
Random rnd = new Random();
_tracktor.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), pictureBox.getWidth(), pictureBox.getHeight());
speedLabel.setText("Скорость: " + _tracktor.getTracktor().getSpeed());
weightLabel.setText("Вес: " + _tracktor.getTracktor().getWeight());
colorLabel.setText("Цвет: " + String.format("%h",_tracktor.getTracktor().getBodyColor()));
repaint();
}
@Override
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D)pictureBox.getGraphics();
if (_tracktor != null){
_tracktor.DrawTransport(g2d);
}
}
}

View File

@ -1,9 +0,0 @@
import java.awt.*;
public interface IDrawningObject {
float getStep();
void setObject(int x, int y, int width, int height);
void moveObject(Direction direction);
void drawningObject(Graphics2D g);
float[] getCurrentPosition();
}

View File

@ -1,6 +0,0 @@
import java.awt.*;
public interface IDrawningRollers {
void setRollersCount(int count);
void DrawRollers(Graphics2D g, float _startPosX, float _startPosY);
}

View File

@ -1,9 +0,0 @@
import javax.swing.*;
public class Program {
public static void main(String[] args){
FormMap formMap = new FormMap();
formMap.setVisible(true);
formMap.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -1,5 +0,0 @@
public enum RollersCount {
Four,
Five,
Six
}

View File

@ -1,17 +0,0 @@
import java.awt.*;
import java.util.Random;
public enum RollersType {
Standard,
Squared,
Cross;
public static IDrawningRollers random(int rollersCount, Color bodyColor) {
return switch (new Random().nextInt(RollersType.values().length)) {
case 0 -> new DrawningRollers(rollersCount, bodyColor);
case 1 -> new DrawningSquaredRollers(rollersCount, bodyColor);
case 2 -> new DrawningCrossRollers(rollersCount, bodyColor);
default -> null;
};
}
}

View File

@ -1,40 +0,0 @@
import java.awt.*;
import java.util.Arrays;
public class SimpleMap extends AbstractMap{
private final Color barrierColor = Color.BLACK;
private final Color roadColor = Color.GRAY;
@Override
protected void DrawBarrierPart(Graphics2D g, int i, int j) {
g.setColor(barrierColor);
g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y);
}
@Override
protected void DrawRoadPart(Graphics2D g, int i, int j) {
g.setColor(roadColor);
g.fillRect(j * (int) _size_x, i * (int) _size_y, (int) _size_x, (int) _size_y);
}
@Override
protected void GenerateMap() {
_map = new int[100][100];
_size_x = (float)_width / _map[0].length;
_size_y = (float)_height / _map.length;
int counter = 0;
for (int[] row : _map) {
Arrays.fill(row, _freeRoad);
}
while (counter < 50)
{
int x = _random.nextInt(0, (int)_map[0].length);
int y = _random.nextInt(0, (int)_map.length);
if (_map[y][x] == _freeRoad)
{
_map[y][x] = _barrier;
counter++;
}
}
}
}