Корректировка названий

This commit is contained in:
Aidar 2024-04-19 22:05:46 +04:00
parent 8bf517785b
commit 4cf0ced6ca
7 changed files with 74 additions and 89 deletions

View File

@ -5,7 +5,7 @@ namespace ProjectLiner.Drawnings;
/// <summary> /// <summary>
/// Класс-прорисовка сущности "Лайнер" /// Класс-прорисовка сущности "Лайнер"
/// </summary> /// </summary>
public class DrawningLiner : DrawningSmallLiner public class DrawningLiner : DrawningShip
{ {
/// <summary> /// <summary>
/// Конструктор /// Конструктор
@ -18,12 +18,12 @@ public class DrawningLiner : DrawningSmallLiner
/// <param name="pool">Наличие басейна</param> /// <param name="pool">Наличие басейна</param>
public DrawningLiner(int speed, double weight, Color bodyColor, Color additionalColor, bool secondDeck, bool pool) : base(150, 65) public DrawningLiner(int speed, double weight, Color bodyColor, Color additionalColor, bool secondDeck, bool pool) : base(150, 65)
{ {
EntitySmallLiner = new EntityLiner(speed, weight, bodyColor, additionalColor, secondDeck, pool); EntityShip = new EntityLiner(speed, weight, bodyColor, additionalColor, secondDeck, pool);
} }
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
if (EntitySmallLiner == null || EntitySmallLiner is not EntityLiner Liner || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityShip == null || EntityShip is not EntityLiner Liner || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return; return;
} }

View File

@ -5,12 +5,12 @@ namespace ProjectLiner.Drawnings;
/// <summary> /// <summary>
/// Класс, отвечающий за прорисовку и перемещение базового объкта-сущности /// Класс, отвечающий за прорисовку и перемещение базового объкта-сущности
/// </summary> /// </summary>
public class DrawningSmallLiner public class DrawningShip
{ {
/// <summary> /// <summary>
/// Класс-сущность "Маленький Лайнер" /// Класс-сущность "Корабль"
/// </summary> /// </summary>
public EntitySmallLiner? EntitySmallLiner { get; protected set; } public EntityShip? EntityShip { get; protected set; }
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
@ -23,22 +23,22 @@ public class DrawningSmallLiner
private int? _pictureHeight; private int? _pictureHeight;
/// <summary> /// <summary>
/// Левая координата прорисовки сущности "Лайнер" /// Левая координата прорисовки сущности
/// </summary> /// </summary>
protected int? _startPosX; protected int? _startPosX;
/// <summary> /// <summary>
/// Верхнаяя координата прорисовки сущности "Лайнер" /// Верхнаяя координата прорисовки сущности
/// </summary> /// </summary>
protected int? _startPosY; protected int? _startPosY;
/// <summary> /// <summary>
/// Ширина прорисовки сущности "Лайнер" /// Ширина прорисовки сущности
/// </summary> /// </summary>
private readonly int _drawningLinerWidth = 150; private readonly int _drawningLinerWidth = 150;
/// <summary> /// <summary>
/// Высота прорисовки сущности "Лайнер" /// Высота прорисовки сущности
/// </summary> /// </summary>
private readonly int _drawningLinerHeight = 50; private readonly int _drawningLinerHeight = 50;
@ -65,9 +65,8 @@ public class DrawningSmallLiner
/// <summary> /// <summary>
/// Пустой конструктор /// Пустой конструктор
/// </summary> /// </summary>
private DrawningSmallLiner() private DrawningShip()
{ {
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
_startPosX = null; _startPosX = null;
@ -80,17 +79,17 @@ public class DrawningSmallLiner
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param> /// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
public DrawningSmallLiner(int speed, double weight, Color bodyColor) : this() public DrawningShip(int speed, double weight, Color bodyColor) : this()
{ {
EntitySmallLiner = new EntitySmallLiner(speed, weight, bodyColor); EntityShip = new EntityShip(speed, weight, bodyColor);
} }
/// <summary> /// <summary>
/// Конструктор для наследников /// Конструктор для наследников
/// </summary> /// </summary>
/// <param name="drawningLinerWidth">Ширина прорисовки сущности "Маленький Лайнер"</param> /// <param name="drawningLinerWidth">Ширина прорисовки сущности "Корабль"</param>
/// <param name="drawningLinerHeight">Высота прорисовки сущности "Маленький Лайнер"</param> /// <param name="drawningLinerHeight">Высота прорисовки сущности "Корабль"</param>
protected DrawningSmallLiner(int drawningLinerWidth, int drawningLinerHeight) : this() protected DrawningShip(int drawningLinerWidth, int drawningLinerHeight) : this()
{ {
_drawningLinerWidth = drawningLinerWidth; _drawningLinerWidth = drawningLinerWidth;
_drawningLinerHeight = drawningLinerHeight; _drawningLinerHeight = drawningLinerHeight;
@ -151,7 +150,7 @@ public class DrawningSmallLiner
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns> /// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction) public bool MoveTransport(DirectionType direction)
{ {
if (EntitySmallLiner == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return false; return false;
} }
@ -159,31 +158,31 @@ public class DrawningSmallLiner
{ {
// Влево // Влево
case DirectionType.Left: case DirectionType.Left:
if (_startPosX.Value - EntitySmallLiner.Step > 0) if (_startPosX.Value - EntityShip.Step > 0)
{ {
_startPosX -= (int)EntitySmallLiner.Step; _startPosX -= (int)EntityShip.Step;
} }
return true; return true;
// Вверх // Вверх
case DirectionType.Up: case DirectionType.Up:
if (_startPosY.Value - EntitySmallLiner.Step > 0) if (_startPosY.Value - EntityShip.Step > 0)
{ {
_startPosY -= (int)EntitySmallLiner.Step; _startPosY -= (int)EntityShip.Step;
} }
return true; return true;
// Вправо // Вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX.Value + _drawningLinerWidth + EntitySmallLiner.Step < _pictureWidth.Value) if (_startPosX.Value + _drawningLinerWidth + EntityShip.Step < _pictureWidth.Value)
{ {
_startPosX += (int)EntitySmallLiner.Step; _startPosX += (int)EntityShip.Step;
} }
return true; return true;
// Вниз // Вниз
case DirectionType.Down: case DirectionType.Down:
if (_startPosY.Value + _drawningLinerHeight + EntitySmallLiner.Step < _pictureHeight.Value) if (_startPosY.Value + _drawningLinerHeight + EntityShip.Step < _pictureHeight.Value)
{ {
_startPosY += (int)EntitySmallLiner.Step; _startPosY += (int)EntityShip.Step;
} }
return true; return true;
default: default:
@ -197,12 +196,12 @@ public class DrawningSmallLiner
/// <param name="g"></param> /// <param name="g"></param>
public virtual void DrawTransport(Graphics g) public virtual void DrawTransport(Graphics g)
{ {
if (EntitySmallLiner == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityShip == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return; return;
} }
Pen pen = new(Color.Black, 2); Pen pen = new(Color.Black, 2);
Brush br = new SolidBrush(EntitySmallLiner.BodyColor); Brush br = new SolidBrush(EntityShip.BodyColor);
// Корпус и палуба Лайнера // Корпус и палуба Лайнера
g.FillPolygon(br, new[] g.FillPolygon(br, new[]

View File

@ -3,7 +3,7 @@
/// <summary> /// <summary>
/// Класс-сущность "Лайнер" /// Класс-сущность "Лайнер"
/// </summary> /// </summary>
public class EntityLiner : EntitySmallLiner public class EntityLiner : EntityShip
{ {
/// <summary> /// <summary>
/// Дополнительный цвет /// Дополнительный цвет

View File

@ -1,9 +1,9 @@
namespace ProjectLiner.Entities; namespace ProjectLiner.Entities;
/// <summary> /// <summary>
/// Класс-сущность "Маленький Лайнер" /// Класс-сущность "Корабль"
/// </summary> /// </summary>
public class EntitySmallLiner public class EntityShip
{ {
/// <summary> /// <summary>
/// Скорость /// Скорость
@ -26,12 +26,12 @@ public class EntitySmallLiner
public double Step => Speed * 100 / Weight; public double Step => Speed * 100 / Weight;
/// <summary> /// <summary>
/// Конструктор сущности "Маленький Лайнер" /// Конструктор сущности "Корабль"
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param> /// <param name="weight">Вес</param>
/// <param name="bodyColor">Основой цвет</param> /// <param name="bodyColor">Основой цвет</param>
public EntitySmallLiner(int speed, double weight, Color bodyColor) public EntityShip(int speed, double weight, Color bodyColor)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;

View File

@ -29,7 +29,7 @@
private void InitializeComponent() private void InitializeComponent()
{ {
pictureBoxLiner = new PictureBox(); pictureBoxLiner = new PictureBox();
buttonCreateSmallLiner = new Button(); buttonCreateShip = new Button();
buttonRight = new Button(); buttonRight = new Button();
buttonDown = new Button(); buttonDown = new Button();
buttonLeft = new Button(); buttonLeft = new Button();
@ -49,16 +49,16 @@
pictureBoxLiner.TabIndex = 0; pictureBoxLiner.TabIndex = 0;
pictureBoxLiner.TabStop = false; pictureBoxLiner.TabStop = false;
// //
// buttonCreateSmallLiner // buttonCreateShip
// //
buttonCreateSmallLiner.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateSmallLiner.Location = new Point(12, 426); buttonCreateShip.Location = new Point(12, 426);
buttonCreateSmallLiner.Name = "buttonCreateSmallLiner"; buttonCreateShip.Name = "buttonCreateShip";
buttonCreateSmallLiner.Size = new Size(154, 23); buttonCreateShip.Size = new Size(154, 23);
buttonCreateSmallLiner.TabIndex = 1; buttonCreateShip.TabIndex = 1;
buttonCreateSmallLiner.Text = "Создать малый лайнер"; buttonCreateShip.Text = "Создать корабль";
buttonCreateSmallLiner.UseVisualStyleBackColor = true; buttonCreateShip.UseVisualStyleBackColor = true;
buttonCreateSmallLiner.Click += ButtonCreateSmallLiner_Click; buttonCreateShip.Click += ButtonCreateShip_Click;
// //
// buttonRight // buttonRight
// //
@ -151,7 +151,7 @@
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonCreateSmallLiner); Controls.Add(buttonCreateShip);
Controls.Add(pictureBoxLiner); Controls.Add(pictureBoxLiner);
Name = "FormLiner"; Name = "FormLiner";
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
@ -163,7 +163,7 @@
#endregion #endregion
private PictureBox pictureBoxLiner; private PictureBox pictureBoxLiner;
private Button buttonCreateSmallLiner; private Button buttonCreateShip;
private Button buttonRight; private Button buttonRight;
private Button buttonDown; private Button buttonDown;
private Button buttonLeft; private Button buttonLeft;

View File

@ -11,7 +11,7 @@ public partial class FormLiner : Form
/// <summary> /// <summary>
/// Поле-объект для прорисовки объекта /// Поле-объект для прорисовки объекта
/// </summary> /// </summary>
private DrawningSmallLiner? _drawningSmallLiner; private DrawningShip? _drawningShip;
/// <summary> /// <summary>
/// Стратегия перемещения /// Стратегия перемещения
@ -32,14 +32,14 @@ public partial class FormLiner : Form
/// </summary> /// </summary>
private void Draw() private void Draw()
{ {
if (_drawningSmallLiner == null) if (_drawningShip == null)
{ {
return; return;
} }
Bitmap bmp = new(pictureBoxLiner.Width, Bitmap bmp = new(pictureBoxLiner.Width,
pictureBoxLiner.Height); pictureBoxLiner.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawningSmallLiner.DrawTransport(gr); _drawningShip.DrawTransport(gr);
pictureBoxLiner.Image = bmp; pictureBoxLiner.Image = bmp;
} }
@ -52,13 +52,13 @@ public partial class FormLiner : Form
Random random = new(); Random random = new();
switch (type) switch (type)
{ {
case nameof(DrawningSmallLiner): case nameof(DrawningShip):
_drawningSmallLiner = new DrawningSmallLiner( _drawningShip = new DrawningShip(
random.Next(100, 300), random.Next(1000, 3000), 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(DrawningLiner): case nameof(DrawningLiner):
_drawningSmallLiner = new DrawningLiner( _drawningShip = new DrawningLiner(
random.Next(100, 300), random.Next(1000, 3000), 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)),
@ -68,8 +68,8 @@ public partial class FormLiner : Form
default: default:
return; return;
} }
_drawningSmallLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height); _drawningShip.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
_drawningSmallLiner.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null; _strategy = null;
comboBoxStrategy.Enabled = true; comboBoxStrategy.Enabled = true;
Draw(); Draw();
@ -83,11 +83,11 @@ public partial class FormLiner : Form
private void ButtonCreateLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner)); private void ButtonCreateLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner));
/// <summary> /// <summary>
/// Обработка нажатия кнопки "Создать малый лайнер" /// Обработка нажатия кнопки "Создать корабль"
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonCreateSmallLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSmallLiner)); private void ButtonCreateShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningShip));
/// <summary> /// <summary>
/// Обработка нажатия кнопок навигации движения /// Обработка нажатия кнопок навигации движения
@ -96,7 +96,7 @@ public partial class FormLiner : Form
/// <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 (_drawningSmallLiner == null) if (_drawningShip == null)
{ {
return; return;
} }
@ -105,16 +105,16 @@ public partial class FormLiner : Form
switch (name) switch (name)
{ {
case "buttonUp": case "buttonUp":
result = _drawningSmallLiner.MoveTransport(DirectionType.Up); result = _drawningShip.MoveTransport(DirectionType.Up);
break; break;
case "buttonDown": case "buttonDown":
result = _drawningSmallLiner.MoveTransport(DirectionType.Down); result = _drawningShip.MoveTransport(DirectionType.Down);
break; break;
case "buttonLeft": case "buttonLeft":
result = _drawningSmallLiner.MoveTransport(DirectionType.Left); result = _drawningShip.MoveTransport(DirectionType.Left);
break; break;
case "buttonRight": case "buttonRight":
result = _drawningSmallLiner.MoveTransport(DirectionType.Right); result = _drawningShip.MoveTransport(DirectionType.Right);
break; break;
} }
if (result) if (result)
@ -130,7 +130,7 @@ public partial class FormLiner : Form
/// <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 (_drawningSmallLiner == null) if (_drawningShip == null)
{ {
return; return;
} }
@ -149,7 +149,7 @@ public partial class FormLiner : Form
return; return;
} }
_strategy.SetData(new MoveableLiner(_drawningSmallLiner), _strategy.SetData(new MoveableLiner(_drawningShip),
pictureBoxLiner.Width, pictureBoxLiner.Height); pictureBoxLiner.Width, pictureBoxLiner.Height);
} }

View File

@ -3,47 +3,47 @@
namespace ProjectLiner.MovementStrategy; namespace ProjectLiner.MovementStrategy;
/// <summary> /// <summary>
/// Класс-реализация IMoveableObject с использованием drawningSmallLiner /// Класс-реализация IMoveableObject с использованием drawningShip
/// </summary> /// </summary>
public class MoveableLiner : IMoveableObject public class MoveableLiner : IMoveableObject
{ {
/// <summary> /// <summary>
/// Поле-объект класса DrawningSmallLiner или его наследника /// Поле-объект класса DrawningShip или его наследника
/// </summary> /// </summary>
private readonly DrawningSmallLiner? _liner = null; private readonly DrawningShip? _ship = null;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="car">Объект класса DrawningSmallLiner</param> /// <param name="ship">Объект класса DrawningShip</param>
public MoveableLiner(DrawningSmallLiner liner) public MoveableLiner(DrawningShip ship)
{ {
_liner = liner; _ship = ship;
} }
public ObjectParameters? GetObjectPosition public ObjectParameters? GetObjectPosition
{ {
get get
{ {
if (_liner == null || _liner.EntitySmallLiner == null || if (_ship == null || _ship.EntityShip == null ||
!_liner.GetPosX.HasValue || !_liner.GetPosY.HasValue) !_ship.GetPosX.HasValue || !_ship.GetPosY.HasValue)
{ {
return null; return null;
} }
return new ObjectParameters(_liner.GetPosX.Value, return new ObjectParameters(_ship.GetPosX.Value, _ship.GetPosY.Value,
_liner.GetPosY.Value, _liner.GetWidth, _liner.GetHeight); _ship.GetWidth, _ship.GetHeight);
} }
} }
public int GetStep => (int)(_liner?.EntitySmallLiner?.Step ?? 0); public int GetStep => (int)(_ship?.EntityShip?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction) public bool TryMoveObject(MovementDirection direction)
{ {
if (_liner == null || _liner.EntitySmallLiner == null) if (_ship == null || _ship.EntityShip == null)
{ {
return false; return false;
} }
return _liner.MoveTransport(GetDirectionType(direction)); return _ship.MoveTransport(GetDirectionType(direction));
} }
/// <summary> /// <summary>
@ -62,18 +62,4 @@ public class MoveableLiner : IMoveableObject
_ => DirectionType.Unknow, _ => DirectionType.Unknow,
}; };
} }
/*public MoveableLiner(DrawningSmallLiner drawningSmallLiner)
{
_drawningSmallLiner = drawningSmallLiner;
}
public ObjectParameters? GetObjectPosition => throw new NotImplementedException();
public int GetStep => throw new NotImplementedException();
public bool TryMoveObject(MovementDirection direction)
{
throw new NotImplementedException();
}*/
} }