Финальная версия исправленная 1 лабораторная

This commit is contained in:
RavilGismatullin 2023-12-01 14:14:13 +04:00
parent 05ea4c6edb
commit 032b12f96b
4 changed files with 47 additions and 129 deletions

View File

@ -8,22 +8,9 @@ namespace Bulldoser
{ {
internal enum Direction internal enum Direction
{ {
/// <summary>
/// Вверх
/// </summary>
Up = 1, Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2, Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3, Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4 Right = 4
} }
} }

View File

@ -8,62 +8,39 @@ namespace Bulldoser
{ {
internal class DrawningBulldoser internal class DrawningBulldoser
{ {
/// <summary>
/// Класс-сущность
/// </summary>
public EntityBulldoser? EntityBulldoser { get; private set; } public EntityBulldoser? EntityBulldoser { get; private set; }
/// <summary>
/// Ширина окна
/// </summary>
private int _pictureWidth; private int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int _pictureHeight; private int _pictureHeight;
/// <summary>
/// Левая координата прорисовки автомобиля
/// </summary>
private int _startPosX; private int _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// </summary>
private int _startPosY; private int _startPosY;
/// <summary> private readonly int _bulldoserWidth = 200;
/// Ширина прорисовки автомобиля private readonly int _bulldoserHeight = 100;
/// </summary>
private readonly int _bulldoserWidth = 110;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _bulldoserHeight = 60;
public bool Init(int speed, double weight, Color bodyColor, Color public bool Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool dump, bool ripper, bool road, int width, int height, bool bodyKit) additionalColor, bool dump, bool ripper, bool road, int width, int height, bool bodyKit)
{ {
// TODO: Продумать проверки
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
if (_pictureHeight < _bulldoserHeight && _pictureWidth < _bulldoserWidth) return false;
EntityBulldoser = new EntityBulldoser(); EntityBulldoser = new EntityBulldoser();
EntityBulldoser.Init(speed, weight, bodyColor, additionalColor, EntityBulldoser.Init(speed, weight, bodyColor, additionalColor,
dump, ripper, road, bodyKit); dump, ripper, road, bodyKit);
return true; return true;
} }
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y) public void SetPosition(int x, int y)
{ {
// TODO: Изменение x, y if ((x<0 ) || (y<0) || (_pictureHeight < _bulldoserHeight && _pictureWidth < _bulldoserWidth))
_startPosX = x; {
_startPosY = y; _startPosX = 0;
_startPosY = 0;
}
else {
_startPosX = x;
_startPosY = y;
}
} }
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
///
public void MoveTransport(Direction direction) public void MoveTransport(Direction direction)
{ {
if (EntityBulldoser == null || (!CanMove(direction))) if (EntityBulldoser == null || (!CanMove(direction)))
@ -73,28 +50,24 @@ namespace Bulldoser
switch (direction) switch (direction)
{ {
//влево
case Direction.Left: case Direction.Left:
if (_startPosX - EntityBulldoser.Step > 0) if (_startPosX - EntityBulldoser.Step > 0)
{ {
_startPosX -= (int)EntityBulldoser.Step; _startPosX -= (int)EntityBulldoser.Step;
} }
break; break;
//вверх
case Direction.Up: case Direction.Up:
if (_startPosY - EntityBulldoser.Step > 0) if (_startPosY - EntityBulldoser.Step > 0)
{ {
_startPosY -= (int)EntityBulldoser.Step; _startPosY -= (int)EntityBulldoser.Step;
} }
break; break;
// вправо
case Direction.Right: case Direction.Right:
if (_startPosX + EntityBulldoser.Step <= _pictureWidth) if (_startPosX + EntityBulldoser.Step <= _pictureWidth)
{ {
_startPosX += (int)EntityBulldoser.Step; _startPosX += (int)EntityBulldoser.Step;
} }
break; break;
//вниз
case Direction.Down: case Direction.Down:
if (_startPosY + EntityBulldoser.Step <= _pictureHeight) if (_startPosY + EntityBulldoser.Step <= _pictureHeight)
{ {
@ -103,55 +76,50 @@ namespace Bulldoser
break; break;
} }
} }
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g) public void DrawTransport(Graphics g)
{ {
if (EntityBulldoser == null) if (EntityBulldoser == null)
{ {
return; return;
} }
if (EntityBulldoser.BodyKit) Pen pen = new(Color.Black);
{ Brush additionalBrush = new SolidBrush(EntityBulldoser.AdditionalColor);
Pen pen = new(Color.Black); Brush brBlack = new SolidBrush(Color.Black);
Brush additionalBrush = new SolidBrush(EntityBulldoser.AdditionalColor); Brush brGray = new SolidBrush(Color.Gray);
Brush brBlack = new SolidBrush(Color.Black); //кузов
Brush brGray = new SolidBrush(Color.Gray); g.FillRectangle(additionalBrush, _startPosX + 35, _startPosY + 35, 120, 40);
//кузов g.FillRectangle(additionalBrush, _startPosX + 95, _startPosY + 0, 5, 35);
g.FillRectangle(additionalBrush, _startPosX + 50, _startPosY + 50, 120, 40); g.FillRectangle(additionalBrush, _startPosX + 150, _startPosY + 0, 5, 35);
g.FillRectangle(additionalBrush, _startPosX + 110, _startPosY + 15, 5, 35); g.FillRectangle(additionalBrush, _startPosX + 95, _startPosY + 0, 60, 5);
g.FillRectangle(additionalBrush, _startPosX + 165, _startPosY + 15, 5, 35); //труба
g.FillRectangle(additionalBrush, _startPosX + 110, _startPosY + 15, 60, 5); g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 5, 10, 30);
//труба //кабина
g.FillRectangle(additionalBrush, _startPosX + 70, _startPosY + 20, 10, 30); g.FillRectangle(brBlack, _startPosX + 100, _startPosY + 5, 50, 30);
//кабина //катки
g.FillRectangle(brBlack, _startPosX + 115, _startPosY + 20, 50, 30); g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 75, 30, 30);
//катки g.FillEllipse(brBlack, _startPosX + 135, _startPosY + 75, 30, 30);
g.FillEllipse(brBlack, _startPosX + 40, _startPosY + 90, 30, 30); g.FillRectangle(brBlack, _startPosX + 35, _startPosY + 75, 120, 30);
g.FillEllipse(brBlack, _startPosX + 150, _startPosY + 90, 30, 30); g.FillEllipse(brGray, _startPosX + 28, _startPosY + 78, 25, 25);
g.FillRectangle(brBlack, _startPosX + 50, _startPosY + 90, 120, 30); g.FillEllipse(brGray, _startPosX + 138, _startPosY + 78, 25, 25);
g.FillEllipse(brGray, _startPosX + 43, _startPosY + 93, 25, 25); g.FillEllipse(brGray, _startPosX + 58, _startPosY + 90, 15, 15);
g.FillEllipse(brGray, _startPosX + 153, _startPosY + 93, 25, 25); g.FillEllipse(brGray, _startPosX + 88, _startPosY + 90, 15, 15);
g.FillEllipse(brGray, _startPosX + 73, _startPosY + 105, 15, 15); g.FillEllipse(brGray, _startPosX + 118, _startPosY + 90, 15, 15);
g.FillEllipse(brGray, _startPosX + 103, _startPosY + 105, 15, 15); g.FillEllipse(brGray, _startPosX + 78, _startPosY + 78, 10, 10);
g.FillEllipse(brGray, _startPosX + 133, _startPosY + 105, 15, 15); g.FillEllipse(brGray, _startPosX + 105, _startPosY + 78, 10, 10);
g.FillEllipse(brGray, _startPosX + 93, _startPosY + 93, 10, 10);
g.FillEllipse(brGray, _startPosX + 120, _startPosY + 93, 10, 10);
if (EntityBulldoser.Dump) if (EntityBulldoser.Dump)
{ {
g.FillRectangle(additionalBrush, _startPosX + 35, _startPosY + 70, 15, 5); g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 55, 15, 5);
g.FillRectangle(brBlack, _startPosX + 25, _startPosY + 50, 10, 70); g.FillRectangle(brBlack, _startPosX + 10, _startPosY + 35, 10, 70);
g.FillRectangle(brBlack, _startPosX + 15, _startPosY + 115, 10, 5); g.FillRectangle(brBlack, _startPosX + 0, _startPosY + 100, 10, 5);
} }
if (EntityBulldoser.Ripper) if (EntityBulldoser.Ripper)
{ {
g.FillRectangle(additionalBrush, _startPosX + 170, _startPosY + 80, 40, 10); g.FillRectangle(additionalBrush, _startPosX + 155, _startPosY + 65, 40, 10);
g.FillRectangle(brBlack, _startPosX + 200, _startPosY + 90, 5, 30); g.FillRectangle(brBlack, _startPosX + 185, _startPosY + 75, 5, 30);
g.FillRectangle(brBlack, _startPosX + 190, _startPosY + 90, 5, 30); g.FillRectangle(brBlack, _startPosX + 175, _startPosY + 75, 5, 30);
} }
}
} }
public bool CanMove(Direction direction) public bool CanMove(Direction direction)
{ {

View File

@ -9,49 +9,15 @@ namespace Bulldoser
{ {
internal class EntityBulldoser internal class EntityBulldoser
{ {
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; } public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; } public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
public bool BodyKit { get; private set; } public bool BodyKit { get; private set; }
/// <summary>
/// Признак (опция) наличия отвала
/// </summary>
public bool Dump { get; private set; } public bool Dump { get; private set; }
/// <summary>
/// Признак (опция) наличия рыхлителя
/// </summary>
public bool Ripper { get; private set; } public bool Ripper { get; private set; }
/// <summary>
/// Признак (опция) наличия дорги
/// </summary>
public bool Road { get; private set; } public bool Road { get; private set; }
/// <summary>
/// Шаг перемещения бульдозера
/// </summary>
public double Step => (double)Speed * 100 / Weight; public double Step => (double)Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public void Init(int speed, double weight, Color bodyColor, Color public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool dump, bool ripper, bool road, bool bodyKit) additionalColor, bool dump, bool ripper, bool road, bool bodyKit)
{ {

View File

@ -8,9 +8,6 @@ namespace Bulldoser
{ {
InitializeComponent(); InitializeComponent();
} }
/// <summary>
/// <20>ועמה ןנמנטסמגךט לארטם<D798>
/// </summary>
private void Draw() private void Draw()
{ {
if (_drawningBulldoser == null) if (_drawningBulldoser == null)