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

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>
public class DrawningLiner : DrawningSmallLiner
public class DrawningLiner : DrawningShip
{
/// <summary>
/// Конструктор
@ -18,12 +18,12 @@ public class DrawningLiner : DrawningSmallLiner
/// <param name="pool">Наличие басейна</param>
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)
{
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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