Закончил Лабу

This commit is contained in:
ivans 2024-03-13 14:11:20 +04:00
parent a8847944db
commit 987cd86208
6 changed files with 63 additions and 35 deletions

View File

@ -26,7 +26,7 @@ public class EntityBasicSeaplane
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param> /// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
Random random = new();
public EntityBasicSeaplane(int speed, double weight, Color bodyColor) public EntityBasicSeaplane(int speed, double weight, Color bodyColor)
{ {
Speed = speed; Speed = speed;

View File

@ -25,14 +25,13 @@ public class EntitySeaplane : EntityBasicSeaplane
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="landingGear">Тип "шасси"</param> /// <param name="landingGear">Тип "шасси"</param>
/// <param name="radar">При</param> /// <param name="radar">При</param>
Random random = new();
public EntitySeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar) : base(0, 0, Color.Brown) public EntitySeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar) : base(speed, weight, bodyColor)
{ {
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
LandingGear = landingGear; LandingGear = landingGear;
Radar = radar; Radar = radar;
} }
} }

View File

@ -19,7 +19,7 @@ namespace ProjectSeaplane
/// <summary> /// <summary>
/// Поле-объект для прорисовки объекта /// Поле-объект для прорисовки объекта
/// </summary> /// </summary>
private DrawingBasicSeaplane? _drawingBasicSeaplane; private DrawingBasicSeaplane? _drawingSeaplane;
/// <summary> /// <summary>
/// Стратегия перемещения /// Стратегия перемещения
/// </summary> /// </summary>
@ -29,14 +29,14 @@ namespace ProjectSeaplane
/// </summary> /// </summary>
private void Draw() private void Draw()
{ {
if (_drawingBasicSeaplane == null) if (_drawingSeaplane == null)
{ {
return; return;
} }
Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); Bitmap bmp = new(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawingBasicSeaplane.DrawTransport(gr); _drawingSeaplane.DrawTransport(gr);
pictureBoxSeaplane.Image = bmp; pictureBoxSeaplane.Image = bmp;
} }
/// <summary> /// <summary>
@ -51,20 +51,20 @@ namespace ProjectSeaplane
switch (type) switch (type)
{ {
case nameof(DrawingBasicSeaplane): case nameof(DrawingBasicSeaplane):
_drawingBasicSeaplane = new DrawingBasicSeaplane(random.Next(100, 300), random.Next(1000, 3000), _drawingSeaplane = new DrawingBasicSeaplane(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
break; break;
case nameof(DrawingSeaplane): case nameof(DrawingSeaplane):
_drawingBasicSeaplane = new DrawingSeaplane(random.Next(100, 300), random.Next(1000, 3000), _drawingSeaplane = new DrawingSeaplane(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2))); Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break; break;
default: default:
return; return;
} }
_drawingBasicSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); _drawingSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
_drawingBasicSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawingSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null; _strategy = null;
comboBoxStrategy.Enabled = true; comboBoxStrategy.Enabled = true;
Draw(); Draw();
@ -94,7 +94,7 @@ namespace ProjectSeaplane
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_drawingBasicSeaplane == null) if (_drawingSeaplane == null)
{ {
return; return;
} }
@ -104,16 +104,16 @@ namespace ProjectSeaplane
switch (name) switch (name)
{ {
case "buttonUp": case "buttonUp":
result = _drawingBasicSeaplane.MoveTransport(DirectionType.Up); result = _drawingSeaplane.MoveTransport(DirectionType.Up);
break; break;
case "buttonDown": case "buttonDown":
result = _drawingBasicSeaplane.MoveTransport(DirectionType.Down); result = _drawingSeaplane.MoveTransport(DirectionType.Down);
break; break;
case "buttonLeft": case "buttonLeft":
result = _drawingBasicSeaplane.MoveTransport(DirectionType.Left); result = _drawingSeaplane.MoveTransport(DirectionType.Left);
break; break;
case "buttonRight": case "buttonRight":
result = _drawingBasicSeaplane.MoveTransport(DirectionType.Right); result = _drawingSeaplane.MoveTransport(DirectionType.Right);
break; break;
} }
@ -129,7 +129,7 @@ namespace ProjectSeaplane
/// <param name="e"></param> /// <param name="e"></param>
private void buttonStrategyStep_Click(object sender, EventArgs e) private void buttonStrategyStep_Click(object sender, EventArgs e)
{ {
if (_drawingBasicSeaplane == null) if (_drawingSeaplane == null)
{ {
return; return;
} }
@ -146,7 +146,7 @@ namespace ProjectSeaplane
{ {
return; return;
} }
_strategy.SetData(new MoveableSeaplane(_drawingBasicSeaplane), pictureBoxSeaplane.Width, pictureBoxSeaplane.Height); _strategy.SetData(new MoveableSeaplane(_drawingSeaplane), pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
} }
if (_strategy == null) if (_strategy == null)

View File

@ -1,6 +1,4 @@
 namespace ProjectSeaplane.MovementStrategy;
namespace ProjectSeaplane.MovementStrategy;
/// <summary> /// <summary>
/// Интерфейс для работы с перемещаемым объектом /// Интерфейс для работы с перемещаемым объектом

View File

@ -4,11 +4,49 @@ public class MoveToBorder : AbstractStrategy
{ {
protected override bool IsTargetDestinaion() protected override bool IsTargetDestinaion()
{ {
throw new NotImplementedException(); ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
} }
protected override void MoveToTarget() protected override void MoveToTarget()
{ {
throw new NotImplementedException(); ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
int diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
if (diffX < 0)
{
MoveRight();
}
}
int diffY = objParams.DownBorder - FieldWidth;
if (Math.Abs(diffY) > GetStep())
{
if (diffX > 0)
{
MoveUp();
}
if (diffY < 0)
{
MoveDown();
}
}
} }
} }

View File

@ -12,24 +12,17 @@ public class MoveableSeaplane : IMoveableObject
/// <summary> /// <summary>
/// Поле-объект класса Seaplane или его наследника /// Поле-объект класса Seaplane или его наследника
/// </summary> /// </summary>
private readonly DrawingSeaplane? _seaplane = null; private readonly DrawingBasicSeaplane? _seaplane = null;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="seaplane">Объект класса Seaplane</param> /// <param name="seaplane">Объект класса Seaplane</param>
public MoveableSeaplane(DrawingSeaplane seaplane) public MoveableSeaplane(DrawingBasicSeaplane Seaplane)
{ {
_seaplane = seaplane; _seaplane = Seaplane;
} }
/// <summary>
/// АВТОКОРРЕКЦИЯ
/// </summary>
/// <param name="drawingBasicSeaplane"></param>
public MoveableSeaplane(DrawingBasicSeaplane drawingBasicSeaplane)
{
}
public ObjectParameters? GetObjectPosition public ObjectParameters? GetObjectPosition
{ {
get get