From 0c0472e3284fe4f1ba1488dfd383204712202888 Mon Sep 17 00:00:00 2001 From: "[USERNAME]" Date: Tue, 14 Nov 2023 22:07:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{Direction.cs => DirectionBulldozer.cs} | 2 +- Bulldozer/Bulldozer/DrawningBulldozer.cs | 18 ++++++++++-------- Bulldozer/Bulldozer/FormBulldozer.cs | 8 ++++---- 3 files changed, 15 insertions(+), 13 deletions(-) rename Bulldozer/Bulldozer/{Direction.cs => DirectionBulldozer.cs} (85%) diff --git a/Bulldozer/Bulldozer/Direction.cs b/Bulldozer/Bulldozer/DirectionBulldozer.cs similarity index 85% rename from Bulldozer/Bulldozer/Direction.cs rename to Bulldozer/Bulldozer/DirectionBulldozer.cs index 9dd27b4..1704ed9 100644 --- a/Bulldozer/Bulldozer/Direction.cs +++ b/Bulldozer/Bulldozer/DirectionBulldozer.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Bulldozer { - public enum DirectionType + public enum DirectionTypeBulldozer { Up = 1, diff --git a/Bulldozer/Bulldozer/DrawningBulldozer.cs b/Bulldozer/Bulldozer/DrawningBulldozer.cs index 0ad080c..0badc2a 100644 --- a/Bulldozer/Bulldozer/DrawningBulldozer.cs +++ b/Bulldozer/Bulldozer/DrawningBulldozer.cs @@ -68,17 +68,19 @@ namespace Bulldozer /// Координата Y public void SetPosition(int x, int y) { - if (x <= _pictureWidth - bulldozerWidth && y <= _pictureHeight - bulldozerHeight) + if (x < 0 || y < 0 || x + bulldozerWidth > _pictureWidth || y + bulldozerHeight > _pictureHeight) { - _startPosX = x; - _startPosY = y; + x = 10; + y = 10; } + _startPosX = x; + _startPosY = y; } /// /// Изменение направления перемещения /// /// Направление - public void MoveTransport(DirectionType direction) + public void MoveTransport(DirectionTypeBulldozer direction) { if (EntityBulldozer == null) @@ -88,7 +90,7 @@ namespace Bulldozer switch (direction) { //влево - case DirectionType.Left: + case DirectionTypeBulldozer.Left: if (_startPosX - EntityBulldozer.Step > 0) { _startPosX -= (int)EntityBulldozer.Step; @@ -99,7 +101,7 @@ namespace Bulldozer } break; //вверх - case DirectionType.Up: + case DirectionTypeBulldozer.Up: if (_startPosY - EntityBulldozer.Step > 0) { _startPosY -= (int)EntityBulldozer.Step; @@ -110,7 +112,7 @@ namespace Bulldozer } break; // вправо - case DirectionType.Right: + case DirectionTypeBulldozer.Right: if (_startPosX + EntityBulldozer.Step + bulldozerWidth < _pictureWidth) { _startPosX += (int)EntityBulldozer.Step; @@ -121,7 +123,7 @@ namespace Bulldozer } break; //вниз - case DirectionType.Down: + case DirectionTypeBulldozer.Down: if (_startPosY + EntityBulldozer.Step + bulldozerHeight < _pictureHeight) { _startPosY += (int)EntityBulldozer.Step; diff --git a/Bulldozer/Bulldozer/FormBulldozer.cs b/Bulldozer/Bulldozer/FormBulldozer.cs index 516e779..4e1870e 100644 --- a/Bulldozer/Bulldozer/FormBulldozer.cs +++ b/Bulldozer/Bulldozer/FormBulldozer.cs @@ -31,16 +31,16 @@ namespace Bulldozer switch (name) { case "buttonUp": - _drawningBulldozer.MoveTransport(DirectionType.Up); + _drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Up); break; case "buttonDown": - _drawningBulldozer.MoveTransport(DirectionType.Down); + _drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Down); break; case "buttonLeft": - _drawningBulldozer.MoveTransport(DirectionType.Left); + _drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Left); break; case "buttonRight": - _drawningBulldozer.MoveTransport(DirectionType.Right); + _drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Right); break; } Draw();