Почти доделал лабораторную

This commit is contained in:
Shtyrkin_Egor 2024-04-15 10:59:07 +04:00
parent f3f138ff62
commit 6d9ac5d186
3 changed files with 38 additions and 40 deletions

View File

@ -35,8 +35,7 @@ public class DrawningAircraftCarrier : DrawningWarship
_startPosX += 5;
_startPosY += 10;
base.DrawTransport(g);
_startPosX -= 5;
_startPosX -= 10;
//рубка управления
if (warship.ControlRoom)
@ -69,6 +68,9 @@ public class DrawningAircraftCarrier : DrawningWarship
g.FillPolygon(additionalBrush, DeckPoint);
g.DrawPolygon(pen, DeckPoint);
g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 35, _startPosX.Value + 50, _startPosY.Value + 10);
_startPosX -= 5;
_startPosX -= 10;
}
}
}

View File

@ -94,10 +94,10 @@ public class DrawningWarship
/// </summary>
/// <param name="drawningWarshipWidth">Ширина прорисовки военного корабля</param>
/// <param name="drawningWarshipHeight">Высота прорисовки военного корабля</param>
protected DrawningWarship(int drawningWarshipWidth, int drawningWarshipHeight) : this()
protected DrawningWarship(int drawningAircraftCarrierWidth, int drawningAircraftCarrierHeight) : this()
{
_drawningWarshipWidth = drawningWarshipWidth;
_drawningWarshipHeight = drawningWarshipHeight;
_drawningWarshipWidth = drawningAircraftCarrierWidth;
_drawningWarshipHeight = drawningAircraftCarrierHeight;
}
/// <summary>
@ -171,7 +171,7 @@ public class DrawningWarship
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityWarship == null || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
if (EntityWarship == null || !_startPosX.HasValue || !_startPosY.HasValue || !_pictureWidth.HasValue || !_pictureHeight.HasValue)
{
return false;
}
@ -180,28 +180,28 @@ public class DrawningWarship
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityWarship.Step > 0)
if (_startPosX.Value - EntityWarship.Step >= 0)
{
_startPosX -= (int)EntityWarship.Step;
}
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityWarship.Step > 0)
if (_startPosY.Value - EntityWarship.Step >= 0)
{
_startPosY -= (int)EntityWarship.Step;
}
return true;
//вправо
case DirectionType.Right:
if (_startPosX.Value + _drawningWarshipWidth + EntityWarship.Step < _pictureWidth)
if (_startPosX.Value + _drawningWarshipWidth + EntityWarship.Step <= _pictureWidth)
{
_startPosX += (int)EntityWarship.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + _drawningWarshipHeight + EntityWarship.Step < _pictureHeight)
if (_startPosY.Value + _drawningWarshipHeight + EntityWarship.Step <= _pictureHeight)
{
_startPosY += (int)EntityWarship.Step;
}

View File

@ -16,45 +16,41 @@ public class MoveToBorder : AbstractStrategy
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
return objParams.RightBorder - GetStep() <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder - GetStep() <= FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
return;
}
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
if (Math.Abs(diffX) > GetStep())
int diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
MoveLeft();
}
int diffY = objParams.ObjectMiddleVertical - FieldHeight;
if (Math.Abs(diffY) > GetStep())
else
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
MoveRight();
}
}
int diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}