diff --git a/ProjectCleaningCar/ProjectCleaningCar/DrawningCleaningCar.cs b/ProjectCleaningCar/ProjectCleaningCar/DrawningCleaningCar.cs
index 0880ef6..8f96e69 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/DrawningCleaningCar.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/DrawningCleaningCar.cs
@@ -64,49 +64,56 @@ public class DrawningCleaningCar
/// Высота поля
/// true - границы заданы, false - проверка не найдена, нельзя разместить
/// объект в этих размерах
- public void SetPictureSize(int width, int height)
+ public Boolean SetPictureSize(int width, int height)
{
+ if (width <= _drawningCleaningCarWidth || height <= _drawningCleaningCarHeight) return false;
_pictureWidth = width;
_pictureHeight = height;
- if (_pictureWidth <= _drawningCleaningCarWidth || _pictureHeight <= _drawningCleaningCarHeight)
+ if (_startPosX.HasValue && _startPosY.HasValue)
{
- _pictureWidth = null;
- _pictureHeight = null;
- return;
- }
- if (_startPosX + _drawningCleaningCarWidth > _pictureWidth)
- {
- _startPosX = _pictureWidth.Value - _drawningCleaningCarWidth;
- }
- if (_startPosY + _drawningCleaningCarHeight > _pictureHeight)
- {
- _startPosY = _pictureHeight.Value - _drawningCleaningCarHeight;
+ if (_startPosX + _drawningCleaningCarWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth.Value - _drawningCleaningCarWidth;
+ }
+ if (_startPosY + _drawningCleaningCarHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight.Value - _drawningCleaningCarHeight;
+ }
}
+
+ return true;
}
///
/// Установка позиция
///
/// Координата Х
/// Координата Y
- public void SetPosition(int x, int y, int width, int height)
- {
- //if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) return;
- if (width < _drawningCleaningCarWidth || height < _drawningCleaningCarHeight) return;
- if (x + _drawningCleaningCarWidth > width || x < 0) return;
- if (y + _drawningCleaningCarHeight > height || y < 0) return;
+ public void SetPosition(int x, int y)
+ {
+ if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
+ {
+ return;
+ }
- _startPosX = x;
- _startPosY = y;
+ _startPosX = x;
+ _startPosY = y;
- _pictureWidth = width;
- _pictureHeight = height;
- }
- ///
- /// Изменение направления перемещения
- ///
- /// Направление
- /// true - перемещение выполнено, false - перемещение невозможно
- public bool MoveTransport(DirectionType direction)
+ if (_drawningCleaningCarHeight + y > _pictureHeight || y < 0)
+ {
+ _startPosY = 0;
+ }
+ if (_drawningCleaningCarWidth + x > _pictureWidth || x < 0)
+ {
+ _startPosX = 0;
+ }
+ return;
+ }
+ ///
+ /// Изменение направления перемещения
+ ///
+ /// Направление
+ /// true - перемещение выполнено, false - перемещение невозможно
+ public bool MoveTransport(DirectionType direction)
{
if (EntityCleaningCar == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs
index ac56289..2e55cc9 100644
--- a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs
+++ b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs
@@ -55,8 +55,8 @@ namespace ProjectCleaningCar
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)));
- //_drawningCleaningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
- _drawningCleaningCar.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
+ _drawningCleaningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
+ _drawningCleaningCar.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
///