Исправил

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
{
public enum DirectionType
public enum DirectionTypeBulldozer
{
Up = 1,

View File

@ -68,17 +68,19 @@ namespace Bulldozer
/// <param name="y">Координата Y</param>
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;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
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;

View File

@ -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();