лаба 2 готовая
This commit is contained in:
parent
66eb4b5d9d
commit
559be80c38
136
base/Catamaran/Catamaran/AbstractStrategy.cs
Normal file
136
base/Catamaran/Catamaran/AbstractStrategy.cs
Normal file
@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Catamaran.DrawningObjects;
|
||||
|
||||
namespace Catamaran.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private Status _state = Status.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public Status GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int
|
||||
height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="directionType">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false -неудача)</returns>
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
72
base/Catamaran/Catamaran/Catamaran.Designer.cs
generated
72
base/Catamaran/Catamaran/Catamaran.Designer.cs
generated
@ -1,6 +1,6 @@
|
||||
namespace Catamaran
|
||||
{
|
||||
partial class Catamaran
|
||||
partial class FormCatamaran
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -29,11 +29,14 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxCatamaran = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreate = new System.Windows.Forms.Button();
|
||||
this.buttonCreateCatamaran = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.buttonCreateSailCatamaran = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -47,16 +50,16 @@
|
||||
this.pictureBoxCatamaran.TabIndex = 0;
|
||||
this.pictureBoxCatamaran.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonCreateCatamaran
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(12, 426);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonCreate.TabIndex = 1;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
this.buttonCreateCatamaran.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateCatamaran.Location = new System.Drawing.Point(140, 398);
|
||||
this.buttonCreateCatamaran.Name = "buttonCreateCatamaran";
|
||||
this.buttonCreateCatamaran.Size = new System.Drawing.Size(122, 51);
|
||||
this.buttonCreateCatamaran.TabIndex = 1;
|
||||
this.buttonCreateCatamaran.Text = "Создать катамаран";
|
||||
this.buttonCreateCatamaran.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateCatamaran.Click += new System.EventHandler(this.buttonCreateCatamaran_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
@ -106,16 +109,52 @@
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// Catamaran
|
||||
// comboBoxStrategy
|
||||
//
|
||||
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxStrategy.FormattingEnabled = true;
|
||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||
"До центра",
|
||||
"До края"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(688, 12);
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(151, 23);
|
||||
this.comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
this.buttonStep.Location = new System.Drawing.Point(770, 41);
|
||||
this.buttonStep.Name = "buttonStep";
|
||||
this.buttonStep.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonStep.TabIndex = 7;
|
||||
this.buttonStep.Text = "Шаг";
|
||||
this.buttonStep.UseVisualStyleBackColor = true;
|
||||
this.buttonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||
//
|
||||
// buttonCreateSailCatamaran
|
||||
//
|
||||
this.buttonCreateSailCatamaran.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateSailCatamaran.Location = new System.Drawing.Point(12, 398);
|
||||
this.buttonCreateSailCatamaran.Name = "buttonCreateSailCatamaran";
|
||||
this.buttonCreateSailCatamaran.Size = new System.Drawing.Size(122, 51);
|
||||
this.buttonCreateSailCatamaran.TabIndex = 8;
|
||||
this.buttonCreateSailCatamaran.Text = "Создать катамаран с парусом";
|
||||
this.buttonCreateSailCatamaran.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateSailCatamaran.Click += new System.EventHandler(this.buttonCreateSailCatamaran_Click);
|
||||
//
|
||||
// FormCatamaran
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||
this.Controls.Add(this.buttonCreateSailCatamaran);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.buttonCreateCatamaran);
|
||||
this.Controls.Add(this.pictureBoxCatamaran);
|
||||
this.Name = "Catamaran";
|
||||
this.Name = "FormCatamaran";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Катамаран";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).EndInit();
|
||||
@ -127,11 +166,14 @@
|
||||
#endregion
|
||||
|
||||
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreateCatamaran;
|
||||
private PictureBox pictureBoxCatamaran;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonCreateSailCatamaran;
|
||||
}
|
||||
}
|
@ -1,12 +1,33 @@
|
||||
using Catamaran.Entities;
|
||||
using Catamaran.DrawningObjects;
|
||||
using Catamaran.MovementStrategy;
|
||||
|
||||
namespace Catamaran
|
||||
{
|
||||
public partial class Catamaran : Form
|
||||
/// <summary>
|
||||
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Êàòàìàðàí"
|
||||
/// </summary>
|
||||
|
||||
public partial class FormCatamaran : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïğîğèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawningCatamaran? _drawningCatamaran;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
public FormCatamaran()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä ïğîğèñîâêè êàòàìàğàíà
|
||||
/// </summary>
|
||||
@ -22,16 +43,45 @@ namespace Catamaran
|
||||
_drawningCatamaran.DrawTransport(gr);
|
||||
pictureBoxCatamaran.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü êàòàìàðàí ñ ïîïëàâêàìè"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
public Catamaran()
|
||||
private void buttonCreateSailCatamaran_Click(object sender, EventArgs e)
|
||||
{
|
||||
InitializeComponent();
|
||||
Random random = new();
|
||||
_drawningCatamaran = new DrawningSailCatamaran(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)), pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
_drawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü êàòàìàðàí"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateCatamaran_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningCatamaran = new DrawningCatamaran(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
_drawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Èçìåíåíèå ïîëîæåíèÿ àâòîìîáèëÿ
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCatamaran == null)
|
||||
@ -42,41 +92,60 @@ namespace Catamaran
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawningCatamaran.MoveTransport(Direction.Up);
|
||||
_drawningCatamaran.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawningCatamaran.MoveTransport(Direction.Down);
|
||||
_drawningCatamaran.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawningCatamaran.MoveTransport(Direction.Left);
|
||||
_drawningCatamaran.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawningCatamaran.MoveTransport(Direction.Right);
|
||||
_drawningCatamaran.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningCatamaran = new DrawningCatamaran();
|
||||
_drawningCatamaran.Init(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)), pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
_drawningCatamaran.SetPosition(random.Next(10, 100),
|
||||
random.Next(10, 100));
|
||||
if (_drawningCatamaran == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawningObjectCatamaran(_drawningCatamaran), pictureBoxCatamaran.Width,
|
||||
pictureBoxCatamaran.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace Catamaran
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum Direction
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
|
@ -3,18 +3,19 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Catamaran.Entities;
|
||||
|
||||
namespace Catamaran
|
||||
namespace Catamaran.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
internal class DrawningCatamaran
|
||||
public class DrawningCatamaran
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityCatamaran? EntityCatamaran { get; private set; }
|
||||
public EntityCatamaran? EntityCatamaran { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -26,11 +27,11 @@ namespace Catamaran
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки катамарана
|
||||
/// </summary>
|
||||
private int _startPosX;
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки катамарана
|
||||
/// Верхняя координата прорисовки катамарана
|
||||
/// </summary>
|
||||
private int _startPosY;
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки катамарана
|
||||
/// </summary>
|
||||
@ -39,35 +40,75 @@ namespace Catamaran
|
||||
/// Высота прорисовки катамарана
|
||||
/// </summary>
|
||||
private readonly int _CatamaranHeight = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _CatamaranWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _CatamaranHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="sail">Признак наличия паруса</param>
|
||||
/// <param name="floatDetail">Признак наличия поплавков</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool sail, bool floatDetail, int width, int height)
|
||||
public DrawningCatamaran(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if (width >= _CatamaranWidth && height >= _CatamaranHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
|
||||
EntityCatamaran = new EntityCatamaran();
|
||||
EntityCatamaran.Init(speed, weight, bodyColor, additionalColor, sail, floatDetail);
|
||||
return true;
|
||||
EntityCatamaran = new EntityCatamaran(speed, weight, bodyColor);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // Возвращаем false, если размеры формы недостаточны
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <param name="catamaranWidth">Ширина прорисовки катамарана</param>
|
||||
/// <param name="catamaranHeight">Высота прорисовки катамарана</param>
|
||||
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
protected DrawningCatamaran(int speed, double weight, Color bodyColor, int width, int height, int catamaranWidth, int catamaranHeight)
|
||||
{
|
||||
if (width >= _CatamaranWidth && height >= _CatamaranHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_CatamaranWidth = catamaranWidth;
|
||||
_CatamaranHeight = catamaranHeight;
|
||||
EntityCatamaran = new EntityCatamaran(speed, weight, bodyColor);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
@ -76,48 +117,73 @@ namespace Catamaran
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x >= 0 && x + _CatamaranWidth <= _pictureWidth && y >= 0 && y + _CatamaranHeight <= _pictureHeight)
|
||||
if (x < 0 || x + _CatamaranWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0 || y + _CatamaranHeight > _pictureHeight)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Проверка, что объект может переместится по указанному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityCatamaran == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityCatamaran.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityCatamaran.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + EntityCatamaran.Step < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + EntityCatamaran.Step < _pictureHeight,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (EntityCatamaran == null)
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityCatamaran == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case Direction.Left:
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityCatamaran.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityCatamaran.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityCatamaran.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityCatamaran.Step;
|
||||
}
|
||||
break;
|
||||
// вправо
|
||||
case Direction.Right:
|
||||
if (_startPosX + _CatamaranWidth + EntityCatamaran.Step < _pictureWidth )
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntityCatamaran.Step + _CatamaranWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityCatamaran.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case Direction.Down:
|
||||
if (_startPosY + _CatamaranHeight + EntityCatamaran.Step < _pictureHeight)
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntityCatamaran.Step + _CatamaranHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityCatamaran.Step;
|
||||
}
|
||||
@ -128,43 +194,15 @@ namespace Catamaran
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCatamaran == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntityCatamaran.AdditionalColor);
|
||||
Brush bodyBrush = new
|
||||
SolidBrush(EntityCatamaran.BodyColor);
|
||||
|
||||
//поплавки
|
||||
if (EntityCatamaran.Float)
|
||||
{
|
||||
|
||||
Point[] floatDetail1 = new Point[]
|
||||
{
|
||||
new Point(_startPosX, _startPosY + 40),
|
||||
new Point(_startPosX + 170, _startPosY + 40),
|
||||
new Point(_startPosX + 190, _startPosY + 55),
|
||||
new Point(_startPosX + 170, _startPosY + 70),
|
||||
new Point(_startPosX, _startPosY + 70),
|
||||
};
|
||||
Point[] floatDetail2 = new Point[]
|
||||
{
|
||||
new Point(_startPosX, _startPosY + 90),
|
||||
new Point(_startPosX + 170, _startPosY + 90),
|
||||
new Point(_startPosX + 190, _startPosY + 105),
|
||||
new Point(_startPosX + 170, _startPosY + 120),
|
||||
new Point(_startPosX, _startPosY + 120),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, floatDetail1);
|
||||
g.FillPolygon(additionalBrush, floatDetail2);
|
||||
g.DrawPolygon(pen, floatDetail1);
|
||||
g.DrawPolygon(pen, floatDetail2);
|
||||
}
|
||||
SolidBrush(EntityCatamaran.BodyColor);
|
||||
//основание катамарана
|
||||
Point[] hull = new Point[]
|
||||
{
|
||||
@ -180,21 +218,7 @@ namespace Catamaran
|
||||
SolidBrush brushBrown = new SolidBrush(Color.Brown);
|
||||
g.FillEllipse(brushBrown, _startPosX + 30, _startPosY + 60, 100, 40);
|
||||
|
||||
//парус
|
||||
if (EntityCatamaran.Sail)
|
||||
{
|
||||
Point[] sail = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 30, _startPosY + 80),
|
||||
new Point(_startPosX + 70, _startPosY+10),
|
||||
new Point(_startPosX + 145, _startPosY + 80),
|
||||
|
||||
};
|
||||
g.DrawPolygon(pen, sail);
|
||||
g.FillPolygon(additionalBrush, sail);
|
||||
g.DrawPolygon(pen, sail);
|
||||
g.DrawRectangle(pen, _startPosX + 70, _startPosY, 3, 85);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
base/Catamaran/Catamaran/DrawningObjectCatamaran.cs
Normal file
40
base/Catamaran/Catamaran/DrawningObjectCatamaran.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Catamaran.DrawningObjects;
|
||||
|
||||
namespace Catamaran.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCatamaran (паттерн Adapter)
|
||||
/// </summary>
|
||||
public class DrawningObjectCatamaran : IMoveableObject
|
||||
{
|
||||
private readonly DrawningCatamaran? _drawningCatamaran = null;
|
||||
public DrawningObjectCatamaran(DrawningCatamaran drawningCatamaran)
|
||||
{
|
||||
_drawningCatamaran = drawningCatamaran;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningCatamaran == null || _drawningCatamaran.EntityCatamaran ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningCatamaran.GetPosX,
|
||||
_drawningCatamaran.GetPosY, _drawningCatamaran.GetWidth, _drawningCatamaran.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningCatamaran?.EntityCatamaran?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawningCatamaran?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawningCatamaran?.MoveTransport(direction);
|
||||
|
||||
}
|
||||
}
|
92
base/Catamaran/Catamaran/DrawningSailCatamaran.cs
Normal file
92
base/Catamaran/Catamaran/DrawningSailCatamaran.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Catamaran.Entities;
|
||||
|
||||
namespace Catamaran.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningSailCatamaran : DrawningCatamaran
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="sail">Признак наличия паруса</param>
|
||||
/// <param name="floatDetail">Признак наличия поплавков</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
|
||||
public DrawningSailCatamaran(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool sail, bool floatDetail, int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height, 190, 120)
|
||||
{
|
||||
if (EntityCatamaran != null)
|
||||
{
|
||||
EntityCatamaran = new EntitySailCatamaran(speed, weight, bodyColor,
|
||||
additionalColor, sail, floatDetail);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCatamaran is not EntitySailCatamaran sailCatamaran)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(sailCatamaran.AdditionalColor);
|
||||
|
||||
|
||||
//поплавки
|
||||
if (sailCatamaran.FloatDetail)
|
||||
{
|
||||
Point[] floatDetail1 = new Point[]
|
||||
{
|
||||
new Point(_startPosX, _startPosY + 40),
|
||||
new Point(_startPosX + 170, _startPosY + 40),
|
||||
new Point(_startPosX + 190, _startPosY + 55),
|
||||
new Point(_startPosX + 170, _startPosY + 70),
|
||||
new Point(_startPosX, _startPosY + 70),
|
||||
};
|
||||
Point[] floatDetail2 = new Point[]
|
||||
{
|
||||
new Point(_startPosX, _startPosY + 90),
|
||||
new Point(_startPosX + 170, _startPosY + 90),
|
||||
new Point(_startPosX + 190, _startPosY + 105),
|
||||
new Point(_startPosX + 170, _startPosY + 120),
|
||||
new Point(_startPosX, _startPosY + 120),
|
||||
};
|
||||
g.FillPolygon(additionalBrush, floatDetail1);
|
||||
g.FillPolygon(additionalBrush, floatDetail2);
|
||||
g.DrawPolygon(pen, floatDetail1);
|
||||
g.DrawPolygon(pen, floatDetail2);
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
//парус
|
||||
if (sailCatamaran.Sail)
|
||||
{
|
||||
Point[] sail = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 30, _startPosY + 80),
|
||||
new Point(_startPosX + 70, _startPosY+10),
|
||||
new Point(_startPosX + 145, _startPosY + 80),
|
||||
|
||||
};
|
||||
g.DrawPolygon(pen, sail);
|
||||
g.FillPolygon(additionalBrush, sail);
|
||||
g.DrawPolygon(pen, sail);
|
||||
g.DrawRectangle(pen, _startPosX + 70, _startPosY, 3, 85);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran
|
||||
namespace Catamaran.Entities
|
||||
{
|
||||
internal class EntityCatamaran
|
||||
/// <summary>
|
||||
/// Класс-сущность "Катамаран"
|
||||
/// </summary>
|
||||
public class EntityCatamaran
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -21,39 +24,21 @@ namespace Catamaran
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия паруса
|
||||
/// </summary>
|
||||
public bool Sail { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия поплавков
|
||||
/// </summary>
|
||||
public bool Float { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения катамарана
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса катамарана
|
||||
/// Конструктор с параметрами
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="sail">Признак наличия паруса</param>
|
||||
/// <param name="floatDetail">Признак наличия поплавков</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool sail, bool floatDetail)
|
||||
public EntityCatamaran(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Sail = sail;
|
||||
Float = floatDetail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
43
base/Catamaran/Catamaran/EntitySailCatamaran.cs
Normal file
43
base/Catamaran/Catamaran/EntitySailCatamaran.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Катамаран с парусом"
|
||||
/// </summary>
|
||||
public class EntitySailCatamaran : EntityCatamaran
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия паруса
|
||||
/// </summary>
|
||||
public bool Sail { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия поплавков
|
||||
/// </summary>
|
||||
public bool FloatDetail { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса катамарана с парусом
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес катамарана</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="sail">Признак наличия паруса</param>
|
||||
/// <param name="floatDetail">Признак наличия поплавков</param>
|
||||
public EntitySailCatamaran(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool sail, bool floatDetail) : base (speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Sail = sail;
|
||||
FloatDetail = floatDetail;
|
||||
}
|
||||
}
|
||||
}
|
36
base/Catamaran/Catamaran/IMoveableObject.cs
Normal file
36
base/Catamaran/Catamaran/IMoveableObject.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Catamaran.DrawningObjects;
|
||||
namespace Catamaran.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты X объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Проверка, можно ли переместиться по нужному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(DirectionType direction);
|
||||
|
||||
}
|
||||
}
|
58
base/Catamaran/Catamaran/MoveToBorder.cs
Normal file
58
base/Catamaran/Catamaran/MoveToBorder.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using Catamaran.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran.MovementStrategy
|
||||
{
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var 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()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
59
base/Catamaran/Catamaran/MoveToCenter.cs
Normal file
59
base/Catamaran/Catamaran/MoveToCenter.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
/// </summary>
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
base/Catamaran/Catamaran/ObjectParameters.cs
Normal file
57
base/Catamaran/Catamaran/ObjectParameters.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Catamaran
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Catamaran());
|
||||
Application.Run(new FormCatamaran());
|
||||
}
|
||||
}
|
||||
}
|
19
base/Catamaran/Catamaran/Status.cs
Normal file
19
base/Catamaran/Catamaran/Status.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user