PIbd-22. Safiulova K.N. LabWork_03 #3
39
base/Catamaran/Catamaran/Catamaran.Designer.cs
generated
39
base/Catamaran/Catamaran/Catamaran.Designer.cs
generated
@ -35,8 +35,9 @@
|
||||
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.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();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -116,20 +117,20 @@
|
||||
this.comboBoxStrategy.Items.AddRange(new object[] {
|
||||
"До центра",
|
||||
"До края"});
|
||||
this.comboBoxStrategy.Location = new System.Drawing.Point(688, 12);
|
||||
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;
|
||||
//
|
||||
// buttonStep
|
||||
// buttonStrategyStep
|
||||
//
|
||||
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);
|
||||
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
|
||||
//
|
||||
@ -142,11 +143,23 @@
|
||||
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.Controls.Add(this.buttonSelectCatamaran);
|
||||
this.Controls.Add(this.buttonCreateSailCatamaran);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.buttonStrategyStep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
@ -165,7 +178,6 @@
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private Button buttonCreateCatamaran;
|
||||
private PictureBox pictureBoxCatamaran;
|
||||
private Button buttonUp;
|
||||
@ -173,7 +185,8 @@
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonStrategyStep;
|
||||
private Button buttonCreateSailCatamaran;
|
||||
private Button buttonSelectCatamaran;
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
using Catamaran.Entities;
|
||||
using Catamaran.DrawningObjects;
|
||||
using Catamaran.MovementStrategy;
|
||||
|
||||
@ -7,7 +6,6 @@ namespace Catamaran
|
||||
/// <summary>
|
||||
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Êàòàìàðàí"
|
||||
/// </summary>
|
||||
|
||||
public partial class FormCatamaran : Form
|
||||
{
|
||||
/// <summary>
|
||||
@ -18,7 +16,12 @@ namespace Catamaran
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Âűáđŕííűé ŕâňîěîáčëü
|
||||
/// </summary>
|
||||
public DrawningCatamaran? SelectedCatamaran { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
@ -26,8 +29,10 @@ namespace Catamaran
|
||||
public FormCatamaran()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
SelectedCatamaran = null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè êàòàìàðàíà
|
||||
/// </summary>
|
||||
@ -52,25 +57,48 @@ namespace Catamaran
|
||||
private void buttonCreateSailCatamaran_Click(object sender, EventArgs e)
|
||||
{
|
||||
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)),
|
||||
//TODO âűáîđ îńíîâíîăî öâĺňŕ
|
||||
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 âűáîđ äîďîëíčňĺëüíîăî öâĺňŕ
|
||||
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)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
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();
|
||||
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.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
random.Next(1000, 3000), color,
|
||||
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
_drawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
@ -108,11 +136,11 @@ namespace Catamaran
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
||||
/// Řŕă ńňđŕňĺăčč ďĺđĺěĺůĺíč˙
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCatamaran == null)
|
||||
{
|
||||
@ -120,32 +148,41 @@ namespace Catamaran
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawningObjectCatamaran(_drawningCatamaran), pictureBoxCatamaran.Width,
|
||||
pictureBoxCatamaran.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.SetData(_drawningCatamaran.GetMoveableObject,
|
||||
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
if (_strategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Âűáîđ ŕâňîěîáčë˙
|
||||
/// </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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Catamaran.Entities;
|
||||
using Catamaran.MovementStrategy;
|
||||
|
||||
namespace Catamaran.DrawningObjects
|
||||
{
|
||||
@ -57,6 +58,10 @@ namespace Catamaran.DrawningObjects
|
||||
/// </summary>
|
||||
public int GetHeight => _CatamaranHeight;
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectCatamaran(this);
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
|
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>
|
@ -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 FormCatamaran());
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user