Изменила форму и классы
This commit is contained in:
parent
18022795a3
commit
a0f62132e3
94
WarmlyShip/WarmlyShip/FormShipCollection.Designer.cs
generated
94
WarmlyShip/WarmlyShip/FormShipCollection.Designer.cs
generated
@ -30,35 +30,99 @@
|
|||||||
{
|
{
|
||||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||||
this.panelCollection = new System.Windows.Forms.Panel();
|
this.panelCollection = new System.Windows.Forms.Panel();
|
||||||
|
this.groupBoxSets = new System.Windows.Forms.GroupBox();
|
||||||
|
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonDelObject = new System.Windows.Forms.Button();
|
||||||
|
this.buttonnAddObject = new System.Windows.Forms.Button();
|
||||||
|
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||||
|
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||||
this.labelCollection = new System.Windows.Forms.Label();
|
this.labelCollection = new System.Windows.Forms.Label();
|
||||||
this.buttonRefreshCollection = new System.Windows.Forms.Button();
|
this.buttonRefreshCollection = new System.Windows.Forms.Button();
|
||||||
this.buttonRemoveShip = new System.Windows.Forms.Button();
|
this.buttonRemoveShip = new System.Windows.Forms.Button();
|
||||||
this.buttonAddShip = new System.Windows.Forms.Button();
|
this.buttonAddShip = new System.Windows.Forms.Button();
|
||||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||||
this.panelCollection.SuspendLayout();
|
this.panelCollection.SuspendLayout();
|
||||||
|
this.groupBoxSets.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
this.pictureBoxCollection.Size = new System.Drawing.Size(700, 453);
|
this.pictureBoxCollection.Size = new System.Drawing.Size(864, 536);
|
||||||
this.pictureBoxCollection.TabIndex = 0;
|
this.pictureBoxCollection.TabIndex = 0;
|
||||||
this.pictureBoxCollection.TabStop = false;
|
this.pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
// panelCollection
|
// panelCollection
|
||||||
//
|
//
|
||||||
|
this.panelCollection.Controls.Add(this.groupBoxSets);
|
||||||
this.panelCollection.Controls.Add(this.maskedTextBoxNumber);
|
this.panelCollection.Controls.Add(this.maskedTextBoxNumber);
|
||||||
this.panelCollection.Controls.Add(this.labelCollection);
|
this.panelCollection.Controls.Add(this.labelCollection);
|
||||||
this.panelCollection.Controls.Add(this.buttonRefreshCollection);
|
this.panelCollection.Controls.Add(this.buttonRefreshCollection);
|
||||||
this.panelCollection.Controls.Add(this.buttonRemoveShip);
|
this.panelCollection.Controls.Add(this.buttonRemoveShip);
|
||||||
this.panelCollection.Controls.Add(this.buttonAddShip);
|
this.panelCollection.Controls.Add(this.buttonAddShip);
|
||||||
this.panelCollection.Location = new System.Drawing.Point(699, 0);
|
this.panelCollection.Location = new System.Drawing.Point(870, 0);
|
||||||
this.panelCollection.Name = "panelCollection";
|
this.panelCollection.Name = "panelCollection";
|
||||||
this.panelCollection.Size = new System.Drawing.Size(218, 453);
|
this.panelCollection.Size = new System.Drawing.Size(218, 536);
|
||||||
this.panelCollection.TabIndex = 1;
|
this.panelCollection.TabIndex = 1;
|
||||||
//
|
//
|
||||||
|
// groupBoxSets
|
||||||
|
//
|
||||||
|
this.groupBoxSets.Controls.Add(this.textBoxStorageName);
|
||||||
|
this.groupBoxSets.Controls.Add(this.buttonDelObject);
|
||||||
|
this.groupBoxSets.Controls.Add(this.buttonnAddObject);
|
||||||
|
this.groupBoxSets.Controls.Add(this.listBoxStorages);
|
||||||
|
this.groupBoxSets.Location = new System.Drawing.Point(12, 42);
|
||||||
|
this.groupBoxSets.Name = "groupBoxSets";
|
||||||
|
this.groupBoxSets.Size = new System.Drawing.Size(199, 242);
|
||||||
|
this.groupBoxSets.TabIndex = 7;
|
||||||
|
this.groupBoxSets.TabStop = false;
|
||||||
|
this.groupBoxSets.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
this.textBoxStorageName.Location = new System.Drawing.Point(0, 26);
|
||||||
|
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
this.textBoxStorageName.Size = new System.Drawing.Size(193, 27);
|
||||||
|
this.textBoxStorageName.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonDelObject
|
||||||
|
//
|
||||||
|
this.buttonDelObject.Location = new System.Drawing.Point(6, 207);
|
||||||
|
this.buttonDelObject.Name = "buttonDelObject";
|
||||||
|
this.buttonDelObject.Size = new System.Drawing.Size(187, 29);
|
||||||
|
this.buttonDelObject.TabIndex = 2;
|
||||||
|
this.buttonDelObject.Text = "Удалить набор";
|
||||||
|
this.buttonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
|
||||||
|
//
|
||||||
|
// buttonnAddObject
|
||||||
|
//
|
||||||
|
this.buttonnAddObject.Location = new System.Drawing.Point(4, 71);
|
||||||
|
this.buttonnAddObject.Name = "buttonnAddObject";
|
||||||
|
this.buttonnAddObject.Size = new System.Drawing.Size(189, 29);
|
||||||
|
this.buttonnAddObject.TabIndex = 1;
|
||||||
|
this.buttonnAddObject.Text = "Добавить набор";
|
||||||
|
this.buttonnAddObject.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonnAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
this.listBoxStorages.FormattingEnabled = true;
|
||||||
|
this.listBoxStorages.ItemHeight = 20;
|
||||||
|
this.listBoxStorages.Location = new System.Drawing.Point(6, 117);
|
||||||
|
this.listBoxStorages.Name = "listBoxStorages";
|
||||||
|
this.listBoxStorages.Size = new System.Drawing.Size(187, 84);
|
||||||
|
this.listBoxStorages.TabIndex = 0;
|
||||||
|
this.listBoxStorages.Click += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
this.maskedTextBoxNumber.Location = new System.Drawing.Point(16, 375);
|
||||||
|
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
this.maskedTextBoxNumber.Size = new System.Drawing.Size(171, 27);
|
||||||
|
this.maskedTextBoxNumber.TabIndex = 6;
|
||||||
|
//
|
||||||
// labelCollection
|
// labelCollection
|
||||||
//
|
//
|
||||||
this.labelCollection.AutoSize = true;
|
this.labelCollection.AutoSize = true;
|
||||||
@ -70,7 +134,7 @@
|
|||||||
//
|
//
|
||||||
// buttonRefreshCollection
|
// buttonRefreshCollection
|
||||||
//
|
//
|
||||||
this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 239);
|
this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 482);
|
||||||
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
|
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
this.buttonRefreshCollection.Size = new System.Drawing.Size(171, 40);
|
this.buttonRefreshCollection.Size = new System.Drawing.Size(171, 40);
|
||||||
this.buttonRefreshCollection.TabIndex = 5;
|
this.buttonRefreshCollection.TabIndex = 5;
|
||||||
@ -80,7 +144,7 @@
|
|||||||
//
|
//
|
||||||
// buttonRemoveShip
|
// buttonRemoveShip
|
||||||
//
|
//
|
||||||
this.buttonRemoveShip.Location = new System.Drawing.Point(16, 166);
|
this.buttonRemoveShip.Location = new System.Drawing.Point(16, 424);
|
||||||
this.buttonRemoveShip.Name = "buttonRemoveShip";
|
this.buttonRemoveShip.Name = "buttonRemoveShip";
|
||||||
this.buttonRemoveShip.Size = new System.Drawing.Size(171, 40);
|
this.buttonRemoveShip.Size = new System.Drawing.Size(171, 40);
|
||||||
this.buttonRemoveShip.TabIndex = 4;
|
this.buttonRemoveShip.TabIndex = 4;
|
||||||
@ -90,7 +154,7 @@
|
|||||||
//
|
//
|
||||||
// buttonAddShip
|
// buttonAddShip
|
||||||
//
|
//
|
||||||
this.buttonAddShip.Location = new System.Drawing.Point(16, 38);
|
this.buttonAddShip.Location = new System.Drawing.Point(16, 309);
|
||||||
this.buttonAddShip.Name = "buttonAddShip";
|
this.buttonAddShip.Name = "buttonAddShip";
|
||||||
this.buttonAddShip.Size = new System.Drawing.Size(171, 40);
|
this.buttonAddShip.Size = new System.Drawing.Size(171, 40);
|
||||||
this.buttonAddShip.TabIndex = 2;
|
this.buttonAddShip.TabIndex = 2;
|
||||||
@ -98,18 +162,11 @@
|
|||||||
this.buttonAddShip.UseVisualStyleBackColor = true;
|
this.buttonAddShip.UseVisualStyleBackColor = true;
|
||||||
this.buttonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click);
|
this.buttonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click);
|
||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
|
||||||
//
|
|
||||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(16, 117);
|
|
||||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
|
||||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(171, 27);
|
|
||||||
this.maskedTextBoxNumber.TabIndex = 6;
|
|
||||||
//
|
|
||||||
// FormShipCollection
|
// FormShipCollection
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(918, 453);
|
this.ClientSize = new System.Drawing.Size(1093, 534);
|
||||||
this.Controls.Add(this.panelCollection);
|
this.Controls.Add(this.panelCollection);
|
||||||
this.Controls.Add(this.pictureBoxCollection);
|
this.Controls.Add(this.pictureBoxCollection);
|
||||||
this.Name = "FormShipCollection";
|
this.Name = "FormShipCollection";
|
||||||
@ -117,6 +174,8 @@
|
|||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||||
this.panelCollection.ResumeLayout(false);
|
this.panelCollection.ResumeLayout(false);
|
||||||
this.panelCollection.PerformLayout();
|
this.panelCollection.PerformLayout();
|
||||||
|
this.groupBoxSets.ResumeLayout(false);
|
||||||
|
this.groupBoxSets.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -130,5 +189,10 @@
|
|||||||
private Button buttonRefreshCollection;
|
private Button buttonRefreshCollection;
|
||||||
private Label labelCollection;
|
private Label labelCollection;
|
||||||
private MaskedTextBox maskedTextBoxNumber;
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private GroupBox groupBoxSets;
|
||||||
|
private Button buttonDelObject;
|
||||||
|
private Button buttonnAddObject;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,16 +23,82 @@ namespace WarmlyShip
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Набор объектов
|
/// Набор объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly ShipsGenericCollection<DrawingWarmlyShip,
|
private readonly ShipsGenericStorage _storage;
|
||||||
DrawingObjectShip> _ships;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormShipCollection()
|
public FormShipCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_ships = new ShipsGenericCollection<DrawingWarmlyShip, DrawingObjectShip>
|
_storage = new ShipsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение listBoxObjects
|
||||||
|
/// </summary>
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorages.SelectedIndex;
|
||||||
|
listBoxStorages.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||||
|
>= listBoxStorages.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||||||
|
index < listBoxStorages.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ListBoxObjects_SelectedIndexChanged(object sender,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image =
|
||||||
|
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowShips();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||||
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
||||||
|
?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@ -41,19 +107,30 @@ namespace WarmlyShip
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonAddShip_Click(object sender, EventArgs e)
|
private void ButtonAddShip_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
FormWarmlyShip form = new();
|
FormWarmlyShip form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_ships + form.SelectedShip != -1)
|
if (obj + form.SelectedShip)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _ships.ShowShips();
|
pictureBoxCollection.Image = obj.ShowShips();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из набора
|
/// Удаление объекта из набора
|
||||||
@ -62,16 +139,26 @@ namespace WarmlyShip
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRemoveShip_Click(object sender, EventArgs e)
|
private void ButtonRemoveShip_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
if (_ships - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _ships.ShowShips();
|
pictureBoxCollection.Image = obj.ShowShips();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -85,7 +172,17 @@ namespace WarmlyShip
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _ships.ShowShips();
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowShips();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,49 +10,49 @@ namespace WarmlyShip.Generics
|
|||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Массив объектов, которые храним
|
/// Список объектов, которые храним
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly T?[] _places;
|
private readonly List<T?> _places;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Количество объектов в массиве
|
/// Количество объектов в массиве
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Count;
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальное количество объектов в списке
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _maxCount;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="count"></param>
|
/// <param name="count"></param>
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T>(count);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="warmlyship">Добавляемый автомобиль</param>
|
/// <param name="warmlyship">Добавляемый теплоход</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T warmlyship)
|
public bool Insert(T warmlyship)
|
||||||
{
|
{
|
||||||
// TODO вставка в начало набора
|
// TODO вставка в начало набора
|
||||||
return Insert(warmlyship, 0);
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="car">Добавляемый автомобиль</param>
|
/// <param name="car">Добавляемый теплоход</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T warmlyship, int position)
|
public bool Insert(T warmlyship, int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
|
||||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
|
||||||
// TODO вставка по позиции
|
|
||||||
int nullIndex = -1;
|
int nullIndex = -1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= Count)
|
||||||
return -1;
|
return false;
|
||||||
|
|
||||||
for (i = position; i < Count; i++)
|
for (i = position; i < Count; i++)
|
||||||
{
|
{
|
||||||
@ -63,14 +63,14 @@ namespace WarmlyShip.Generics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nullIndex < 0)
|
if (nullIndex < 0)
|
||||||
return -1;
|
return false;
|
||||||
|
|
||||||
for (i = nullIndex; i > position; i--)
|
for (i = nullIndex; i > position; i--)
|
||||||
{
|
{
|
||||||
_places[i] = _places[i - 1];
|
_places[i] = _places[i - 1];
|
||||||
}
|
}
|
||||||
_places[position] = warmlyship;
|
_places[position] = warmlyship;
|
||||||
return position;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
@ -79,13 +79,11 @@ namespace WarmlyShip.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
|
||||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= Count)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_places[position] = null;
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -93,14 +91,41 @@ namespace WarmlyShip.Generics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T? Get(int position)
|
public T? this[int position]
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
get
|
||||||
if (position < 0 || position >= Count)
|
|
||||||
{
|
{
|
||||||
return null;
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_places.Insert(position, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetShips(int? maxShips = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxShips.HasValue && i == maxShips.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return _places[position];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,14 +53,14 @@ namespace WarmlyShip.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int operator +(ShipsGenericCollection<T, U> collect, T?
|
public static bool operator +(ShipsGenericCollection<T, U> collect, T?
|
||||||
obj)
|
obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
return collect._collection.Insert(obj);
|
return (bool)collect?._collection.Insert(obj);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
@ -68,15 +68,15 @@ namespace WarmlyShip.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="pos"></param>
|
/// <param name="pos"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool operator -(ShipsGenericCollection<T, U> collect, int
|
public static T? operator -(ShipsGenericCollection<T, U> collect, int
|
||||||
pos)
|
pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection.Get(pos);
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
collect._collection.Remove(pos);
|
collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
return false;
|
return obj;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта IMoveableObject
|
/// Получение объекта IMoveableObject
|
||||||
@ -85,7 +85,7 @@ namespace WarmlyShip.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вывод всего набора объектов
|
/// Вывод всего набора объектов
|
||||||
@ -125,27 +125,19 @@ namespace WarmlyShip.Generics
|
|||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
private void DrawObjects(Graphics g)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
T? ship;
|
int i = 0;
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
foreach (var ship in _collection.GetShips())
|
||||||
int diff = 1;
|
{
|
||||||
int currWidth = 0;
|
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
|
||||||
{
|
|
||||||
// TODO получение объекта
|
// TODO получение объекта
|
||||||
// TODO установка позиции
|
// TODO установка позиции
|
||||||
// TODO прорисовка объекта
|
// TODO прорисовка объекта
|
||||||
currWidth++;
|
|
||||||
if (currWidth > width)
|
|
||||||
{
|
|
||||||
diff++;
|
|
||||||
currWidth = 1;
|
|
||||||
}
|
|
||||||
ship = _collection.Get(i);
|
|
||||||
if (ship != null)
|
if (ship != null)
|
||||||
{
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
ship.SetPosition((width - 1 - (i % width)) * _placeSizeWidth, i / width * _placeSizeHeight);
|
ship.SetPosition((width - 1 - (i % width)) * _placeSizeWidth, i / width * _placeSizeHeight);
|
||||||
ship.DrawTransport(g);
|
ship.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
83
WarmlyShip/WarmlyShip/ShipsGenericStorage.cs
Normal file
83
WarmlyShip/WarmlyShip/ShipsGenericStorage.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WarmlyShip.DrawingObjects;
|
||||||
|
using WarmlyShip.MovementStrategy;
|
||||||
|
|
||||||
|
namespace WarmlyShip.Generics
|
||||||
|
{
|
||||||
|
internal class ShipsGenericStorage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, ShipsGenericCollection<DrawingWarmlyShip,
|
||||||
|
DrawingObjectShip>> _shipStorages;
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Keys => _shipStorages.Keys.ToList();
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pictureWidth"></param>
|
||||||
|
/// /// <param name="pictureHeight"></param>
|
||||||
|
public ShipsGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_shipStorages = new Dictionary<string,
|
||||||
|
ShipsGenericCollection<DrawingWarmlyShip, DrawingObjectShip>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
_shipStorages.Add(name, new ShipsGenericCollection<DrawingWarmlyShip, DrawingObjectShip>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления
|
||||||
|
if (!_shipStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_shipStorages.Remove(name);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ShipsGenericCollection<DrawingWarmlyShip, DrawingObjectShip>?
|
||||||
|
this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения набора
|
||||||
|
if (_shipStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _shipStorages[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user