Исправил

This commit is contained in:
[USERNAME] 2023-11-14 22:07:43 +04:00
parent f8096ea10a
commit 0c0472e328
3 changed files with 15 additions and 13 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Bulldozer namespace Bulldozer
{ {
public enum DirectionType public enum DirectionTypeBulldozer
{ {
Up = 1, Up = 1,

View File

@ -68,17 +68,19 @@ namespace Bulldozer
/// <param name="y">Координата Y</param> /// <param name="y">Координата Y</param>
public void SetPosition(int x, int 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; x = 10;
_startPosY = y; y = 10;
} }
_startPosX = x;
_startPosY = y;
} }
/// <summary> /// <summary>
/// Изменение направления перемещения /// Изменение направления перемещения
/// </summary> /// </summary>
/// <param name="direction">Направление</param> /// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction) public void MoveTransport(DirectionTypeBulldozer direction)
{ {
if (EntityBulldozer == null) if (EntityBulldozer == null)
@ -88,7 +90,7 @@ namespace Bulldozer
switch (direction) switch (direction)
{ {
//влево //влево
case DirectionType.Left: case DirectionTypeBulldozer.Left:
if (_startPosX - EntityBulldozer.Step > 0) if (_startPosX - EntityBulldozer.Step > 0)
{ {
_startPosX -= (int)EntityBulldozer.Step; _startPosX -= (int)EntityBulldozer.Step;
@ -99,7 +101,7 @@ namespace Bulldozer
} }
break; break;
//вверх //вверх
case DirectionType.Up: case DirectionTypeBulldozer.Up:
if (_startPosY - EntityBulldozer.Step > 0) if (_startPosY - EntityBulldozer.Step > 0)
{ {
_startPosY -= (int)EntityBulldozer.Step; _startPosY -= (int)EntityBulldozer.Step;
@ -110,7 +112,7 @@ namespace Bulldozer
} }
break; break;
// вправо // вправо
case DirectionType.Right: case DirectionTypeBulldozer.Right:
if (_startPosX + EntityBulldozer.Step + bulldozerWidth < _pictureWidth) if (_startPosX + EntityBulldozer.Step + bulldozerWidth < _pictureWidth)
{ {
_startPosX += (int)EntityBulldozer.Step; _startPosX += (int)EntityBulldozer.Step;
@ -121,7 +123,7 @@ namespace Bulldozer
} }
break; break;
//вниз //вниз
case DirectionType.Down: case DirectionTypeBulldozer.Down:
if (_startPosY + EntityBulldozer.Step + bulldozerHeight < _pictureHeight) if (_startPosY + EntityBulldozer.Step + bulldozerHeight < _pictureHeight)
{ {
_startPosY += (int)EntityBulldozer.Step; _startPosY += (int)EntityBulldozer.Step;

View File

@ -31,16 +31,16 @@ namespace Bulldozer
switch (name) switch (name)
{ {
case "buttonUp": case "buttonUp":
_drawningBulldozer.MoveTransport(DirectionType.Up); _drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Up);
break; break;
case "buttonDown": case "buttonDown":
_drawningBulldozer.MoveTransport(DirectionType.Down); _drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Down);
break; break;
case "buttonLeft": case "buttonLeft":
_drawningBulldozer.MoveTransport(DirectionType.Left); _drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Left);
break; break;
case "buttonRight": case "buttonRight":
_drawningBulldozer.MoveTransport(DirectionType.Right); _drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Right);
break; break;
} }
Draw(); Draw();