From eeb472e8b071b10abbbb267b5f79695d318a2c2b Mon Sep 17 00:00:00 2001
From: DanilaSm08 <149575842+DanilaSm08@users.noreply.github.com>
Date: Wed, 14 Feb 2024 15:10:07 +0400
Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?=
=?UTF-8?q?=D0=BA=D0=B0=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE?=
=?UTF-8?q?=D1=80=D0=BD=D0=BE=D0=B9=20=E2=84=961?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ProjectCleaningCar/DrawningCleaningCar.cs | 67 ++++++++++---------
.../ProjectCleaningCar/FormCleaningCar.cs | 4 +-
2 files changed, 39 insertions(+), 32 deletions(-)
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();
}
///