rename base classes
This commit is contained in:
parent
336c2e7d1c
commit
19fd6bc82d
@ -6,13 +6,13 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCatamaran.Drawnings;
|
||||
public class DrawningCatamaranBase
|
||||
public class DrawningBoat
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// класс-сущность
|
||||
/// </summary>
|
||||
public EntityCatamaranBase? EntityCatamaranBase { get; protected set; }
|
||||
public EntityBoat? EntityBoat { get; protected set; }
|
||||
/// <summary>
|
||||
/// ширина окна
|
||||
/// </summary>
|
||||
@ -57,7 +57,7 @@ public class DrawningCatamaranBase
|
||||
/// <summary>
|
||||
/// пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningCatamaranBase()
|
||||
private DrawningBoat()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
@ -70,9 +70,9 @@ public class DrawningCatamaranBase
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес катера</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningCatamaranBase(int speed, double weight, Color bodyColor) : this()
|
||||
public DrawningBoat(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityCatamaranBase = new EntityCatamaranBase(speed, weight, bodyColor);
|
||||
EntityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
@ -80,7 +80,7 @@ public class DrawningCatamaranBase
|
||||
/// </summary>
|
||||
/// <param name="drawningCatamaranWidth">Ширина катера</param>
|
||||
/// <param name="drawningCatamaranHeight">высота катера</param>
|
||||
public DrawningCatamaranBase(int drawningCatamaranWidth, int drawningCatamaranHeight) : this()
|
||||
public DrawningBoat(int drawningCatamaranWidth, int drawningCatamaranHeight) : this()
|
||||
{
|
||||
_drawningCatamaranWidth = drawningCatamaranWidth;
|
||||
_drawningCatamaranHeight = drawningCatamaranHeight;
|
||||
@ -129,34 +129,34 @@ public class DrawningCatamaranBase
|
||||
/// <returns>true - перемещение выполнено , false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityCatamaranBase == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityCatamaranBase.Step > 0)
|
||||
if (_startPosX.Value - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityCatamaranBase.Step;
|
||||
_startPosX -= (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityCatamaranBase.Step > 0)
|
||||
if (_startPosY.Value - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityCatamaranBase.Step;
|
||||
_startPosY -= (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + (int)EntityCatamaranBase.Step + _drawningCatamaranWidth <= _pictureWidth)
|
||||
if (_startPosX.Value + (int)EntityBoat.Step + _drawningCatamaranWidth <= _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityCatamaranBase.Step;
|
||||
_startPosX += (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + (int)EntityCatamaranBase.Step + _drawningCatamaranHeight <= _pictureHeight)
|
||||
if (_startPosY.Value + (int)EntityBoat.Step + _drawningCatamaranHeight <= _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityCatamaranBase.Step;
|
||||
_startPosY += (int)EntityBoat.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -169,11 +169,11 @@ public class DrawningCatamaranBase
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCatamaranBase == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Brush brBody = new SolidBrush(EntityCatamaranBase.BodyColor);
|
||||
Brush brBody = new SolidBrush(EntityBoat.BodyColor);
|
||||
|
||||
g.FillRectangle(brBody, _startPosX.Value, _startPosY.Value, 40, 20);
|
||||
Point[] triangle =
|
@ -9,7 +9,7 @@ namespace ProjectCatamaran.Drawnings;
|
||||
/// <summary>
|
||||
/// класс отвечающиай за перемещение и отрисовку
|
||||
/// </summary>
|
||||
public class DrawningCatamaran : DrawningCatamaranBase
|
||||
public class DrawningCatamaran : DrawningBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -23,12 +23,12 @@ public class DrawningCatamaran : DrawningCatamaranBase
|
||||
public DrawningCatamaran(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool sail) :
|
||||
base(65,40)
|
||||
{
|
||||
EntityCatamaranBase = new EntityCatamaran(speed, weight, bodyColor, additionalColor, floats, sail);
|
||||
EntityBoat = new EntityCatamaran(speed, weight, bodyColor, additionalColor, floats, sail);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCatamaranBase == null || EntityCatamaranBase is not EntityCatamaran catamaran || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBoat == null || EntityBoat is not EntityCatamaran catamaran || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectCatamaran.Entities;
|
||||
/// <summary>
|
||||
/// класс-сущность "обычный катамаран"
|
||||
/// класс-сущность "лодка"
|
||||
/// </summary>
|
||||
public class EntityCatamaranBase
|
||||
public class EntityBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -34,7 +34,7 @@ public class EntityCatamaranBase
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес авто</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityCatamaranBase(int speed, double weight, Color bodyColor)
|
||||
public EntityBoat(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
@ -2,7 +2,7 @@
|
||||
/// <summary>
|
||||
/// Класс-сущность "Катамарана"
|
||||
/// </summary>
|
||||
public class EntityCatamaran : EntityCatamaranBase
|
||||
public class EntityCatamaran : EntityBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет(для опциональных элементов)
|
||||
|
@ -34,7 +34,7 @@
|
||||
buttonRight = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateCatamaranBase = new Button();
|
||||
buttonCreateBoat = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCatamaran).BeginInit();
|
||||
@ -45,7 +45,7 @@
|
||||
pictureBoxCatamaran.Dock = DockStyle.Fill;
|
||||
pictureBoxCatamaran.Location = new Point(0, 0);
|
||||
pictureBoxCatamaran.Name = "pictureBoxCatamaran";
|
||||
pictureBoxCatamaran.Size = new Size(800, 450);
|
||||
pictureBoxCatamaran.Size = new Size(801, 450);
|
||||
pictureBoxCatamaran.TabIndex = 0;
|
||||
pictureBoxCatamaran.TabStop = false;
|
||||
//
|
||||
@ -108,16 +108,16 @@
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateCatamaranBase
|
||||
// buttonCreateBoat
|
||||
//
|
||||
buttonCreateCatamaranBase.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCreateCatamaranBase.Location = new Point(184, 402);
|
||||
buttonCreateCatamaranBase.Name = "buttonCreateCatamaranBase";
|
||||
buttonCreateCatamaranBase.Size = new Size(166, 40);
|
||||
buttonCreateCatamaranBase.TabIndex = 6;
|
||||
buttonCreateCatamaranBase.Text = "Создать базовый катамаран";
|
||||
buttonCreateCatamaranBase.UseVisualStyleBackColor = true;
|
||||
buttonCreateCatamaranBase.Click += ButtonCreateCatamaranBase_Click;
|
||||
buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCreateBoat.Location = new Point(184, 402);
|
||||
buttonCreateBoat.Name = "buttonCreateBoat";
|
||||
buttonCreateBoat.Size = new Size(166, 40);
|
||||
buttonCreateBoat.TabIndex = 6;
|
||||
buttonCreateBoat.Text = "Создать лодку";
|
||||
buttonCreateBoat.UseVisualStyleBackColor = true;
|
||||
buttonCreateBoat.Click += ButtonCreateBoat_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
@ -147,7 +147,7 @@
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateCatamaranBase);
|
||||
Controls.Add(buttonCreateBoat);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonRight);
|
||||
@ -168,7 +168,7 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateCatamaranBase;
|
||||
private Button buttonCreateBoat;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace ProjectCatamaran
|
||||
{
|
||||
public partial class FormCatamaran : Form
|
||||
{
|
||||
private DrawningCatamaranBase? _drawningCatamaranBase;
|
||||
private DrawningBoat? _drawningBoat;
|
||||
private AbstractStrategy? _strategy;
|
||||
public FormCatamaran()
|
||||
{
|
||||
@ -25,19 +25,19 @@ namespace ProjectCatamaran
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningCatamaranBase == null)
|
||||
if (_drawningBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningCatamaranBase.DrawTransport(gr);
|
||||
_drawningBoat.DrawTransport(gr);
|
||||
pictureBoxCatamaran.Image = bmp;
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCatamaranBase == null)
|
||||
if (_drawningBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -46,16 +46,16 @@ namespace ProjectCatamaran
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningCatamaranBase.MoveTransport(DirectionType.Up);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningCatamaranBase.MoveTransport(DirectionType.Down);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningCatamaranBase.MoveTransport(DirectionType.Left);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningCatamaranBase.MoveTransport(DirectionType.Right);
|
||||
result = _drawningBoat.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
@ -69,12 +69,12 @@ namespace ProjectCatamaran
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningCatamaranBase):
|
||||
_drawningCatamaranBase = new DrawningCatamaranBase(random.Next(100, 300), random.Next(1000, 3000),
|
||||
case nameof(DrawningBoat):
|
||||
_drawningBoat = new DrawningBoat(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(DrawningCatamaran):
|
||||
_drawningCatamaranBase = new DrawningCatamaran(random.Next(100, 300), random.Next(1000, 3000),
|
||||
_drawningBoat = new DrawningCatamaran(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)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
@ -82,8 +82,8 @@ namespace ProjectCatamaran
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawningCatamaranBase.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
_drawningCatamaranBase.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_drawningBoat.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
@ -93,9 +93,9 @@ namespace ProjectCatamaran
|
||||
CreateObject(nameof(DrawningCatamaran));
|
||||
}
|
||||
|
||||
private void ButtonCreateCatamaranBase_Click(object sender, EventArgs e)
|
||||
private void ButtonCreateBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningCatamaranBase));
|
||||
CreateObject(nameof(DrawningBoat));
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Шаг"
|
||||
@ -104,7 +104,7 @@ namespace ProjectCatamaran
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCatamaranBase == null)
|
||||
if (_drawningBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -120,7 +120,7 @@ namespace ProjectCatamaran
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableCatamaranBase(_drawningCatamaranBase),
|
||||
_strategy.SetData(new MoveableBoat(_drawningBoat),
|
||||
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
}
|
||||
if (_strategy == null)
|
||||
|
@ -7,45 +7,45 @@ using ProjectCatamaran.Drawnings;
|
||||
|
||||
namespace ProjectCatamaran.MovementStrategy
|
||||
{
|
||||
internal class MoveableCatamaranBase : IMoveableObject
|
||||
internal class MoveableBoat : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningCatamaranBase или его наследника
|
||||
/// Поле-объект класса DrawningBoat или его наследника
|
||||
/// </summary>
|
||||
private DrawningCatamaranBase _catamaranBase = null;
|
||||
private DrawningBoat _boat = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="car">Объект класса DrawningCatamaranBase</param>
|
||||
public MoveableCatamaranBase(DrawningCatamaranBase catamaranBase)
|
||||
/// <param name="car">Объект класса DrawningBoat</param>
|
||||
public MoveableBoat(DrawningBoat boat)
|
||||
{
|
||||
_catamaranBase = catamaranBase;
|
||||
_boat = boat;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_catamaranBase == null || _catamaranBase.EntityCatamaranBase == null || !_catamaranBase.GetPosX.HasValue
|
||||
|| !_catamaranBase.GetPosY.HasValue)
|
||||
if (_boat == null || _boat.EntityBoat == null || !_boat.GetPosX.HasValue
|
||||
|| !_boat.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ObjectParameters(_catamaranBase.GetPosX.Value, _catamaranBase.GetPosY.Value,
|
||||
_catamaranBase.GetWidth, _catamaranBase.GetHeight);
|
||||
return new ObjectParameters(_boat.GetPosX.Value, _boat.GetPosY.Value,
|
||||
_boat.GetWidth, _boat.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_catamaranBase?.EntityCatamaranBase?.Step ?? 0);
|
||||
public int GetStep => (int)(_boat?.EntityBoat?.Step ?? 0);
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_catamaranBase == null || _catamaranBase.EntityCatamaranBase == null)
|
||||
if (_boat == null || _boat.EntityBoat == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _catamaranBase.MoveTransport(GetDirectionType(direction));
|
||||
return _boat.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
Loading…
x
Reference in New Issue
Block a user