PIbd-21. Kryukov A.I. Lab work 02 base #17

Closed
SooNooClose wants to merge 10 commits from lab_2 into lab_1
2 changed files with 38 additions and 67 deletions
Showing only changes of commit 5f13150a3b - Show all commits

View File

@ -38,40 +38,6 @@ namespace ProjectExcavator.DrawningObjects
/// </summary>
protected readonly int _excavatorHeight = 80;
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// Ширина объекта
/// </summary>
public int GetWidth => _excavatorWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _excavatorHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawningExcavator(int speed, double weight, Color bodyColor, int
width, int height)
{
if (_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
@ -88,13 +54,13 @@ namespace ProjectExcavator.DrawningObjects
{
_pictureWidth = width;
_pictureHeight = height;
_excavatorWidth = excavatorWidth;
_excavatorHeight = excavatorHeight;
if (_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth)
if(_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth)
{
return;
return false;
}
EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
EntityExcavator = new EntityExcavator();
EntityExcavator.Init(speed, weight, bodyColor, additionalColor, bodyKit, backet);
return true;
}
/// <summary>
/// Установка позиции
@ -103,32 +69,11 @@ namespace ProjectExcavator.DrawningObjects
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
_startPosX = Math.Min(x,_pictureWidth - _excavatorWidth);
_startPosY = Math.Min(y,_pictureHeight - _excavatorHeight);
}
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
public bool CanMove(DirectionType direction)
{
if(EntityExcavator == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityExcavator.Step >0,
//вверх
DirectionType.Up => _startPosY - EntityExcavator.Step > 0,
//вправо
DirectionType.Right => _startPosX + EntityExcavator.Step < _pictureWidth - _excavatorWidth,
//вниз
DirectionType.Down => _startPosY + EntityExcavator.Step < _pictureHeight - _excavatorHeight,
_ => false,
};
}
/// <summary>
/// Изменение направления перемещения
@ -148,7 +93,10 @@ namespace ProjectExcavator.DrawningObjects
break;
//вверх
case DirectionType.Up:
_startPosY -= (int)EntityExcavator.Step;
if (_startPosY - EntityExcavator.Step > 0)
{
_startPosY -= (int)EntityExcavator.Step;
}
break;
// вправо
case DirectionType.Right:
@ -156,7 +104,10 @@ namespace ProjectExcavator.DrawningObjects
break;
//вниз
case DirectionType.Down:
_startPosY += (int)EntityExcavator.Step;
if (_startPosY + EntityExcavator.Step < _pictureHeight - _excavatorHeight)
{
_startPosY += (int)EntityExcavator.Step;
}
break;
}
}
@ -171,6 +122,12 @@ namespace ProjectExcavator.DrawningObjects
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityExcavator.AdditionalColor);
if (EntityExcavator.BodyKit)
{
g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 70, 130, 10);
g.DrawLine(pen, _startPosX + 20, _startPosY + 70, _startPosX + 150, _startPosY + 70);
}
//корпус
Brush bodyBrush = new SolidBrush(EntityExcavator.BodyColor);
g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 60, 130, 20);
@ -196,7 +153,17 @@ namespace ProjectExcavator.DrawningObjects
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 80, 20, 20);
g.DrawEllipse(pen, _startPosX + 100, _startPosY + 80, 20, 20);
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 80, 20, 20);
//ковш
if (EntityExcavator.Backet)
{
Point[] pointsBacket = {
new Point(_startPosX + 150, _startPosY + 25),
new Point(_startPosX + 150, _startPosY + 85),
new Point(_startPosX + 195, _startPosY + 85),
};
g.FillPolygon(additionalBrush, pointsBacket);
g.DrawPolygon(pen, pointsBacket);
}
}
}
}

View File

@ -30,7 +30,11 @@ namespace ProjectExcavator.Entities
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес экскаватора</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityExcavator(int speed, double weight, Color bodyColor)
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="backet">Признак наличия антикрыла</param>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool backet)
{
Speed = speed;
Weight = weight;