Compare commits
8 Commits
LabWork_01
...
LabWork_03
| Author | SHA1 | Date | |
|---|---|---|---|
| 238c21da97 | |||
| f9da881a3c | |||
| 239d88ff26 | |||
| 41ab07e21a | |||
| b19ff39870 | |||
| 4ccd1c4123 | |||
| 4ca5cd73fa | |||
| 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.MovementStrategy;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
87
base/Catamaran/Catamaran/Catamaran.Designer.cs
generated
87
base/Catamaran/Catamaran/Catamaran.Designer.cs
generated
@@ -1,6 +1,6 @@
|
|||||||
namespace Catamaran
|
namespace Catamaran
|
||||||
{
|
{
|
||||||
partial class Catamaran
|
partial class FormCatamaran
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@@ -29,11 +29,15 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.pictureBoxCatamaran = new System.Windows.Forms.PictureBox();
|
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.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
|
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonStrategyStep = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateSailCatamaran = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSelectCatamaran = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@@ -47,16 +51,16 @@
|
|||||||
this.pictureBoxCatamaran.TabIndex = 0;
|
this.pictureBoxCatamaran.TabIndex = 0;
|
||||||
this.pictureBoxCatamaran.TabStop = false;
|
this.pictureBoxCatamaran.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreateCatamaran
|
||||||
//
|
//
|
||||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
this.buttonCreateCatamaran.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.buttonCreateCatamaran.Location = new System.Drawing.Point(140, 398);
|
||||||
this.buttonCreate.Name = "buttonCreate";
|
this.buttonCreateCatamaran.Name = "buttonCreateCatamaran";
|
||||||
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
|
this.buttonCreateCatamaran.Size = new System.Drawing.Size(122, 51);
|
||||||
this.buttonCreate.TabIndex = 1;
|
this.buttonCreateCatamaran.TabIndex = 1;
|
||||||
this.buttonCreate.Text = "Создать";
|
this.buttonCreateCatamaran.Text = "Создать катамаран";
|
||||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
this.buttonCreateCatamaran.UseVisualStyleBackColor = true;
|
||||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
this.buttonCreateCatamaran.Click += new System.EventHandler(this.buttonCreateCatamaran_Click);
|
||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
@@ -106,16 +110,64 @@
|
|||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
|
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(711, 12);
|
||||||
|
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
this.comboBoxStrategy.Size = new System.Drawing.Size(151, 23);
|
||||||
|
this.comboBoxStrategy.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonStrategyStep
|
||||||
|
//
|
||||||
|
this.buttonStrategyStep.Location = new System.Drawing.Point(787, 41);
|
||||||
|
this.buttonStrategyStep.Name = "buttonStrategyStep";
|
||||||
|
this.buttonStrategyStep.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonStrategyStep.TabIndex = 7;
|
||||||
|
this.buttonStrategyStep.Text = "Шаг";
|
||||||
|
this.buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonStrategyStep.Click += new System.EventHandler(this.buttonStrategyStep_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);
|
||||||
|
//
|
||||||
|
// buttonSelectCatamaran
|
||||||
|
//
|
||||||
|
this.buttonSelectCatamaran.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
|
this.buttonSelectCatamaran.Location = new System.Drawing.Point(268, 398);
|
||||||
|
this.buttonSelectCatamaran.Name = "buttonSelectCatamaran";
|
||||||
|
this.buttonSelectCatamaran.Size = new System.Drawing.Size(167, 51);
|
||||||
|
this.buttonSelectCatamaran.TabIndex = 11;
|
||||||
|
this.buttonSelectCatamaran.Text = "Выбрать катамаран";
|
||||||
|
this.buttonSelectCatamaran.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSelectCatamaran.Click += new System.EventHandler(this.buttonSelectCatamaran_Click);
|
||||||
|
//
|
||||||
|
// FormCatamaran
|
||||||
//
|
//
|
||||||
this.ClientSize = new System.Drawing.Size(884, 461);
|
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||||
|
this.Controls.Add(this.buttonSelectCatamaran);
|
||||||
|
this.Controls.Add(this.buttonCreateSailCatamaran);
|
||||||
|
this.Controls.Add(this.buttonStrategyStep);
|
||||||
|
this.Controls.Add(this.comboBoxStrategy);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonUp);
|
this.Controls.Add(this.buttonUp);
|
||||||
this.Controls.Add(this.buttonCreate);
|
this.Controls.Add(this.buttonCreateCatamaran);
|
||||||
this.Controls.Add(this.pictureBoxCatamaran);
|
this.Controls.Add(this.pictureBoxCatamaran);
|
||||||
this.Name = "Catamaran";
|
this.Name = "FormCatamaran";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "Катамаран";
|
this.Text = "Катамаран";
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).EndInit();
|
||||||
@@ -126,12 +178,15 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonCreateCatamaran;
|
||||||
private Button buttonCreate;
|
|
||||||
private PictureBox pictureBoxCatamaran;
|
private PictureBox pictureBoxCatamaran;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonStrategyStep;
|
||||||
|
private Button buttonCreateSailCatamaran;
|
||||||
|
private Button buttonSelectCatamaran;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,38 @@
|
|||||||
|
using Catamaran.DrawningObjects;
|
||||||
|
using Catamaran.MovementStrategy;
|
||||||
|
|
||||||
namespace Catamaran
|
namespace Catamaran
|
||||||
{
|
{
|
||||||
public partial class Catamaran : Form
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormCatamaran : Form
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningCatamaran? _drawningCatamaran;
|
private DrawningCatamaran? _drawningCatamaran;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public DrawningCatamaran? SelectedCatamaran { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
public FormCatamaran()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
|
SelectedCatamaran = null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -22,16 +48,68 @@ namespace Catamaran
|
|||||||
_drawningCatamaran.DrawTransport(gr);
|
_drawningCatamaran.DrawTransport(gr);
|
||||||
pictureBoxCatamaran.Image = bmp;
|
pictureBoxCatamaran.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
public Catamaran()
|
private void buttonCreateSailCatamaran_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
Random random = new();
|
||||||
|
//TODO <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialogColor = new();
|
||||||
|
if (dialogColor.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialogColor.Color;
|
||||||
|
}
|
||||||
|
//TODO <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialogDopColor = new();
|
||||||
|
if (dialogDopColor.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDopColor.Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_drawningCatamaran = new DrawningSailCatamaran(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000), color, dopColor, 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>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateCatamaran_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawningCatamaran = new DrawningCatamaran(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000), color,
|
||||||
|
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||||
|
_drawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10,
|
||||||
|
100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void buttonMove_Click(object sender, EventArgs e)
|
private void buttonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningCatamaran == null)
|
if (_drawningCatamaran == null)
|
||||||
@@ -42,41 +120,69 @@ namespace Catamaran
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
_drawningCatamaran.MoveTransport(Direction.Up);
|
_drawningCatamaran.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
_drawningCatamaran.MoveTransport(Direction.Down);
|
_drawningCatamaran.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
_drawningCatamaran.MoveTransport(Direction.Left);
|
_drawningCatamaran.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
_drawningCatamaran.MoveTransport(Direction.Right);
|
_drawningCatamaran.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
if (_drawningCatamaran == null)
|
||||||
_drawningCatamaran = new DrawningCatamaran();
|
{
|
||||||
_drawningCatamaran.Init(random.Next(100, 300),
|
return;
|
||||||
random.Next(1000, 3000),
|
}
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
if (comboBoxStrategy.Enabled)
|
||||||
random.Next(0, 256)),
|
{
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||||
random.Next(0, 256)),
|
{
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
0 => new MoveToCenter(),
|
||||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
1 => new MoveToBorder(),
|
||||||
_drawningCatamaran.SetPosition(random.Next(10, 100),
|
_ => null,
|
||||||
random.Next(10, 100));
|
};
|
||||||
Draw();
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(_drawningCatamaran.GetMoveableObject,
|
||||||
|
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||||
|
}
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_strategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSelectCatamaran_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedCatamaran = _drawningCatamaran;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
154
base/Catamaran/Catamaran/CatamaransGenericCollection.cs
Normal file
154
base/Catamaran/Catamaran/CatamaransGenericCollection.cs
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Catamaran.DrawningObjects;
|
||||||
|
using Catamaran.MovementStrategy;
|
||||||
|
namespace Catamaran.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный класс для набора объектов DrawningCatamaran
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
internal class CatamaransGenericCollection<T, U>
|
||||||
|
where T : DrawningCatamaran
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 200;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 150;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public CatamaransGenericCollection(int picWidth, int picHeight)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(width * height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int operator +(CatamaransGenericCollection<T, U> collect, T? obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator -(CatamaransGenericCollection<T, U> collect, int pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection.Get(pos);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
return collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowCatamarans()
|
||||||
|
{
|
||||||
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
DrawBackground(gr);
|
||||||
|
DrawObjects(gr);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод отрисовки фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawBackground(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||||
|
1; ++j)
|
||||||
|
{//линия разметки места
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||||
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||||
|
_placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||||
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
// TODO получение объекта
|
||||||
|
// TODO установка позиции
|
||||||
|
// TODO прорисовка объекта
|
||||||
|
T? obj;
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
int diff = 1, currWidth = 0;
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
currWidth++;
|
||||||
|
if (currWidth > width)
|
||||||
|
{
|
||||||
|
diff++;
|
||||||
|
currWidth = 1;
|
||||||
|
}
|
||||||
|
obj = _collection.Get(i);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
obj.SetPosition(i % width * _placeSizeWidth + _placeSizeWidth / 40,
|
||||||
|
(height - diff) * _placeSizeHeight + _placeSizeHeight / 15);
|
||||||
|
obj.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ namespace Catamaran
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum Direction
|
public enum DirectionType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вверх
|
/// Вверх
|
||||||
|
|||||||
@@ -3,18 +3,20 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Catamaran.Entities;
|
||||||
|
using Catamaran.MovementStrategy;
|
||||||
|
|
||||||
namespace Catamaran
|
namespace Catamaran.DrawningObjects
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class DrawningCatamaran
|
public class DrawningCatamaran
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityCatamaran? EntityCatamaran { get; private set; }
|
public EntityCatamaran? EntityCatamaran { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -26,11 +28,11 @@ namespace Catamaran
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки катамарана
|
/// Левая координата прорисовки катамарана
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int _startPosX;
|
protected int _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки катамарана
|
/// Верхняя координата прорисовки катамарана
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int _startPosY;
|
protected int _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки катамарана
|
/// Ширина прорисовки катамарана
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -40,34 +42,75 @@ namespace Catamaran
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _CatamaranHeight = 120;
|
private readonly int _CatamaranHeight = 120;
|
||||||
/// <summary>
|
/// <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>
|
||||||
|
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||||
|
/// </summary>
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectCatamaran(this);
|
||||||
|
/// <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>
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="sail">Признак наличия паруса</param>
|
|
||||||
/// <param name="floatDetail">Признак наличия поплавков</param>
|
|
||||||
/// <param name="width">Ширина картинки</param>
|
/// <param name="width">Ширина картинки</param>
|
||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||||
public bool Init(int speed, double weight, Color bodyColor, Color
|
public DrawningCatamaran(int speed, double weight, Color bodyColor, int width, int height)
|
||||||
additionalColor, bool sail, bool floatDetail, int width, int height)
|
|
||||||
{
|
{
|
||||||
if (width >= _CatamaranWidth && height >= _CatamaranHeight)
|
if (width >= _CatamaranWidth && height >= _CatamaranHeight)
|
||||||
{
|
{
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
|
|
||||||
EntityCatamaran = new EntityCatamaran();
|
EntityCatamaran = new EntityCatamaran(speed, weight, bodyColor);
|
||||||
EntityCatamaran.Init(speed, weight, bodyColor, additionalColor, sail, floatDetail);
|
return;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
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>
|
/// <summary>
|
||||||
/// Установка позиции
|
/// Установка позиции
|
||||||
@@ -76,48 +119,73 @@ namespace Catamaran
|
|||||||
/// <param name="y">Координата Y</param>
|
/// <param name="y">Координата Y</param>
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
if (x >= 0 && x + _CatamaranWidth <= _pictureWidth && y >= 0 && y + _CatamaranHeight <= _pictureHeight)
|
if (x < 0 || x + _CatamaranWidth > _pictureWidth)
|
||||||
{
|
{
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
if (y < 0 || y + _CatamaranHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_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>
|
||||||
/// Изменение направления перемещения
|
/// Изменение направления перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="direction">Направление</param>
|
/// <param name="direction">Направление</param>
|
||||||
public void MoveTransport(Direction direction)
|
public void MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityCatamaran == null)
|
if (!CanMove(direction) || EntityCatamaran == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
//влево
|
case DirectionType.Left:
|
||||||
case Direction.Left:
|
|
||||||
if (_startPosX - EntityCatamaran.Step > 0)
|
if (_startPosX - EntityCatamaran.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityCatamaran.Step;
|
_startPosX -= (int)EntityCatamaran.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вверх
|
case DirectionType.Up:
|
||||||
case Direction.Up:
|
|
||||||
if (_startPosY - EntityCatamaran.Step > 0)
|
if (_startPosY - EntityCatamaran.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityCatamaran.Step;
|
_startPosY -= (int)EntityCatamaran.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// вправо
|
case DirectionType.Right:
|
||||||
case Direction.Right:
|
if (_startPosX + EntityCatamaran.Step + _CatamaranWidth < _pictureWidth)
|
||||||
if (_startPosX + _CatamaranWidth + EntityCatamaran.Step < _pictureWidth )
|
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityCatamaran.Step;
|
_startPosX += (int)EntityCatamaran.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вниз
|
case DirectionType.Down:
|
||||||
case Direction.Down:
|
if (_startPosY + EntityCatamaran.Step + _CatamaranHeight < _pictureHeight)
|
||||||
if (_startPosY + _CatamaranHeight + EntityCatamaran.Step < _pictureHeight)
|
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityCatamaran.Step;
|
_startPosY += (int)EntityCatamaran.Step;
|
||||||
}
|
}
|
||||||
@@ -128,43 +196,15 @@ namespace Catamaran
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityCatamaran == null)
|
if (EntityCatamaran == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black, 3);
|
Pen pen = new(Color.Black, 3);
|
||||||
Brush additionalBrush = new
|
|
||||||
SolidBrush(EntityCatamaran.AdditionalColor);
|
|
||||||
Brush bodyBrush = new
|
Brush bodyBrush = new
|
||||||
SolidBrush(EntityCatamaran.BodyColor);
|
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);
|
|
||||||
}
|
|
||||||
//основание катамарана
|
//основание катамарана
|
||||||
Point[] hull = new Point[]
|
Point[] hull = new Point[]
|
||||||
{
|
{
|
||||||
@@ -179,22 +219,6 @@ namespace Catamaran
|
|||||||
g.DrawPolygon(pen, hull);
|
g.DrawPolygon(pen, hull);
|
||||||
SolidBrush brushBrown = new SolidBrush(Color.Brown);
|
SolidBrush brushBrown = new SolidBrush(Color.Brown);
|
||||||
g.FillEllipse(brushBrown, _startPosX + 30, _startPosY + 60, 100, 40);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
39
base/Catamaran/Catamaran/DrawningObjectCatamaran.cs
Normal file
39
base/Catamaran/Catamaran/DrawningObjectCatamaran.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
89
base/Catamaran/Catamaran/DrawningSailCatamaran.cs
Normal file
89
base/Catamaran/Catamaran/DrawningSailCatamaran.cs
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
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.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Catamaran
|
namespace Catamaran.Entities
|
||||||
{
|
{
|
||||||
internal class EntityCatamaran
|
/// <summary>
|
||||||
|
/// Класс-сущность "Катамаран"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityCatamaran
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Скорость
|
/// Скорость
|
||||||
@@ -21,39 +24,21 @@ namespace Catamaran
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; private set; }
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
public double Step => (double)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>
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
public EntityCatamaran(int speed, double weight, Color bodyColor)
|
||||||
/// <param name="sail">Признак наличия паруса</param>
|
|
||||||
/// <param name="floatDetail">Признак наличия поплавков</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color
|
|
||||||
additionalColor, bool sail, bool floatDetail)
|
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
124
base/Catamaran/Catamaran/FormCatamaranCollection.Designer.cs
generated
Normal file
124
base/Catamaran/Catamaran/FormCatamaranCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
namespace Catamaran
|
||||||
|
{
|
||||||
|
partial class FormCatamaranCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||||
|
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||||
|
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||||
|
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonRemoveCatamaran = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonAddCatamaran = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||||
|
this.groupBoxTools.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 1);
|
||||||
|
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
this.pictureBoxCollection.Size = new System.Drawing.Size(741, 459);
|
||||||
|
this.pictureBoxCollection.TabIndex = 0;
|
||||||
|
this.pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
this.groupBoxTools.Controls.Add(this.maskedTextBoxNumber);
|
||||||
|
this.groupBoxTools.Controls.Add(this.ButtonRefreshCollection);
|
||||||
|
this.groupBoxTools.Controls.Add(this.ButtonRemoveCatamaran);
|
||||||
|
this.groupBoxTools.Controls.Add(this.ButtonAddCatamaran);
|
||||||
|
this.groupBoxTools.Location = new System.Drawing.Point(739, 1);
|
||||||
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
|
this.groupBoxTools.Size = new System.Drawing.Size(147, 460);
|
||||||
|
this.groupBoxTools.TabIndex = 1;
|
||||||
|
this.groupBoxTools.TabStop = false;
|
||||||
|
this.groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
this.maskedTextBoxNumber.Location = new System.Drawing.Point(0, 108);
|
||||||
|
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
this.maskedTextBoxNumber.Size = new System.Drawing.Size(141, 23);
|
||||||
|
this.maskedTextBoxNumber.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
this.ButtonRefreshCollection.Location = new System.Drawing.Point(0, 211);
|
||||||
|
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
this.ButtonRefreshCollection.Size = new System.Drawing.Size(141, 34);
|
||||||
|
this.ButtonRefreshCollection.TabIndex = 2;
|
||||||
|
this.ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||||
|
//
|
||||||
|
// ButtonRemoveCatamaran
|
||||||
|
//
|
||||||
|
this.ButtonRemoveCatamaran.Location = new System.Drawing.Point(0, 157);
|
||||||
|
this.ButtonRemoveCatamaran.Name = "ButtonRemoveCatamaran";
|
||||||
|
this.ButtonRemoveCatamaran.Size = new System.Drawing.Size(141, 34);
|
||||||
|
this.ButtonRemoveCatamaran.TabIndex = 1;
|
||||||
|
this.ButtonRemoveCatamaran.Text = "Удалить катамаран";
|
||||||
|
this.ButtonRemoveCatamaran.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonRemoveCatamaran.Click += new System.EventHandler(this.ButtonRemoveCatamaran_Click);
|
||||||
|
//
|
||||||
|
// ButtonAddCatamaran
|
||||||
|
//
|
||||||
|
this.ButtonAddCatamaran.Location = new System.Drawing.Point(0, 22);
|
||||||
|
this.ButtonAddCatamaran.Name = "ButtonAddCatamaran";
|
||||||
|
this.ButtonAddCatamaran.Size = new System.Drawing.Size(141, 34);
|
||||||
|
this.ButtonAddCatamaran.TabIndex = 0;
|
||||||
|
this.ButtonAddCatamaran.Text = "Добавить катамаран";
|
||||||
|
this.ButtonAddCatamaran.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonAddCatamaran.Click += new System.EventHandler(this.ButtonAddCatamaran_Click);
|
||||||
|
//
|
||||||
|
// FormCatamaranCollection
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(884, 461);
|
||||||
|
this.Controls.Add(this.groupBoxTools);
|
||||||
|
this.Controls.Add(this.pictureBoxCollection);
|
||||||
|
this.Name = "FormCatamaranCollection";
|
||||||
|
this.Text = "FormCatamaranCollection";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||||
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
|
this.groupBoxTools.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private Button ButtonAddCatamaran;
|
||||||
|
private Button ButtonRefreshCollection;
|
||||||
|
private Button ButtonRemoveCatamaran;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
81
base/Catamaran/Catamaran/FormCatamaranCollection.cs
Normal file
81
base/Catamaran/Catamaran/FormCatamaranCollection.cs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
using Catamaran.DrawningObjects;
|
||||||
|
using Catamaran.Generics;
|
||||||
|
using Catamaran.MovementStrategy;
|
||||||
|
|
||||||
|
namespace Catamaran
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма для работы с набором объектов класса DrawningCatamaran
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormCatamaranCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly CatamaransGenericCollection<DrawningCatamaran,
|
||||||
|
DrawningObjectCatamaran> _catamarans;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormCatamaranCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_catamarans = new CatamaransGenericCollection<DrawningCatamaran,
|
||||||
|
DrawningObjectCatamaran>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddCatamaran_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormCatamaran form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_catamarans + form.SelectedCatamaran != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _catamarans.ShowCatamarans();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRemoveCatamaran_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (_catamarans - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = _catamarans.ShowCatamarans();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обновление рисунка по набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs
|
||||||
|
e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _catamarans.ShowCatamarans();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
60
base/Catamaran/Catamaran/FormCatamaranCollection.resx
Normal file
60
base/Catamaran/Catamaran/FormCatamaranCollection.resx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
||||||
34
base/Catamaran/Catamaran/IMoveableObject.cs
Normal file
34
base/Catamaran/Catamaran/IMoveableObject.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
57
base/Catamaran/Catamaran/MoveToBorder.cs
Normal file
57
base/Catamaran/Catamaran/MoveToBorder.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
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,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Catamaran());
|
Application.Run(new FormCatamaranCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
106
base/Catamaran/Catamaran/SetGeneric.cs
Normal file
106
base/Catamaran/Catamaran/SetGeneric.cs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Catamaran.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly T?[] _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Length;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T?[count];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="car">Добавляемый катамаран</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T catamaran)
|
||||||
|
{
|
||||||
|
// TODO вставка в начало набора
|
||||||
|
return Insert(catamaran, 0);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="catamaran">Добавляемый катамаран</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T catamaran, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO проверка, что элемент массива по этой позиции пустой,
|
||||||
|
//если нет, то проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||||
|
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||||
|
// TODO вставка по позиции
|
||||||
|
int nullIndex = -1, i;
|
||||||
|
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (i = position; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
nullIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nullIndex < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (i = nullIndex; i > position; i--)
|
||||||
|
{
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
_places[position] = catamaran;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
if (position < 0 || position >= Count) {
|
||||||
|
return false; }
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
base/Catamaran/Catamaran/Status.cs
Normal file
18
base/Catamaran/Catamaran/Status.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user