Лёвушкина Анаа, ПИбд-21, лаб4 простая #7
@ -29,10 +29,14 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.panel1 = new System.Windows.Forms.Panel();
|
this.panel1 = new System.Windows.Forms.Panel();
|
||||||
this.ButtonAddCar = new System.Windows.Forms.Button();
|
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||||
this.ButtonRemoveCar = new System.Windows.Forms.Button();
|
this.ButtonAddObject = new System.Windows.Forms.Button();
|
||||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||||
|
this.ButtonDelObject = new System.Windows.Forms.Button();
|
||||||
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||||
|
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonRemoveCar = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonAddCar = new System.Windows.Forms.Button();
|
||||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||||
this.panel1.SuspendLayout();
|
this.panel1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||||
@ -40,6 +44,10 @@
|
|||||||
//
|
//
|
||||||
// panel1
|
// panel1
|
||||||
//
|
//
|
||||||
|
this.panel1.Controls.Add(this.textBoxStorageName);
|
||||||
|
this.panel1.Controls.Add(this.ButtonAddObject);
|
||||||
|
this.panel1.Controls.Add(this.listBoxStorages);
|
||||||
|
this.panel1.Controls.Add(this.ButtonDelObject);
|
||||||
this.panel1.Controls.Add(this.maskedTextBoxNumber);
|
this.panel1.Controls.Add(this.maskedTextBoxNumber);
|
||||||
this.panel1.Controls.Add(this.ButtonRefreshCollection);
|
this.panel1.Controls.Add(this.ButtonRefreshCollection);
|
||||||
this.panel1.Controls.Add(this.ButtonRemoveCar);
|
this.panel1.Controls.Add(this.ButtonRemoveCar);
|
||||||
@ -49,42 +57,78 @@
|
|||||||
this.panel1.Size = new System.Drawing.Size(157, 449);
|
this.panel1.Size = new System.Drawing.Size(157, 449);
|
||||||
this.panel1.TabIndex = 1;
|
this.panel1.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// ButtonAddCar
|
// textBoxStorageName
|
||||||
//
|
//
|
||||||
this.ButtonAddCar.Location = new System.Drawing.Point(16, 29);
|
this.textBoxStorageName.Location = new System.Drawing.Point(18, 25);
|
||||||
this.ButtonAddCar.Name = "ButtonAddCar";
|
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||||
this.ButtonAddCar.Size = new System.Drawing.Size(118, 53);
|
this.textBoxStorageName.Size = new System.Drawing.Size(118, 20);
|
||||||
this.ButtonAddCar.TabIndex = 0;
|
this.textBoxStorageName.TabIndex = 5;
|
||||||
this.ButtonAddCar.Text = "добавить";
|
|
||||||
this.ButtonAddCar.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonAddCar.Click += new System.EventHandler(this.ButtonAddCar_Click);
|
|
||||||
//
|
//
|
||||||
// ButtonRemoveCar
|
// ButtonAddObject
|
||||||
//
|
//
|
||||||
this.ButtonRemoveCar.Location = new System.Drawing.Point(16, 209);
|
this.ButtonAddObject.Location = new System.Drawing.Point(18, 51);
|
||||||
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
|
this.ButtonAddObject.Name = "ButtonAddObject";
|
||||||
this.ButtonRemoveCar.Size = new System.Drawing.Size(118, 50);
|
this.ButtonAddObject.Size = new System.Drawing.Size(118, 29);
|
||||||
this.ButtonRemoveCar.TabIndex = 1;
|
this.ButtonAddObject.TabIndex = 2;
|
||||||
this.ButtonRemoveCar.Text = "удалить";
|
this.ButtonAddObject.Text = "добавить набор";
|
||||||
this.ButtonRemoveCar.UseVisualStyleBackColor = true;
|
this.ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
this.ButtonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
|
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
this.listBoxStorages.FormattingEnabled = true;
|
||||||
|
this.listBoxStorages.Location = new System.Drawing.Point(18, 86);
|
||||||
|
this.listBoxStorages.Name = "listBoxStorages";
|
||||||
|
this.listBoxStorages.Size = new System.Drawing.Size(120, 95);
|
||||||
|
this.listBoxStorages.TabIndex = 4;
|
||||||
|
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// ButtonDelObject
|
||||||
|
//
|
||||||
|
this.ButtonDelObject.Location = new System.Drawing.Point(18, 187);
|
||||||
|
this.ButtonDelObject.Name = "ButtonDelObject";
|
||||||
|
this.ButtonDelObject.Size = new System.Drawing.Size(118, 30);
|
||||||
|
this.ButtonDelObject.TabIndex = 2;
|
||||||
|
this.ButtonDelObject.Text = "удалить набор";
|
||||||
|
this.ButtonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
this.maskedTextBoxNumber.Location = new System.Drawing.Point(16, 330);
|
||||||
|
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 20);
|
||||||
|
this.maskedTextBoxNumber.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// ButtonRefreshCollection
|
// ButtonRefreshCollection
|
||||||
//
|
//
|
||||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(16, 341);
|
this.ButtonRefreshCollection.Location = new System.Drawing.Point(16, 401);
|
||||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(118, 50);
|
this.ButtonRefreshCollection.Size = new System.Drawing.Size(118, 37);
|
||||||
this.ButtonRefreshCollection.TabIndex = 2;
|
this.ButtonRefreshCollection.TabIndex = 2;
|
||||||
this.ButtonRefreshCollection.Text = "обновить коллекцию";
|
this.ButtonRefreshCollection.Text = "обновить коллекцию";
|
||||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// ButtonRemoveCar
|
||||||
//
|
//
|
||||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(25, 183);
|
this.ButtonRemoveCar.Location = new System.Drawing.Point(16, 356);
|
||||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
this.ButtonRemoveCar.Name = "ButtonRemoveCar";
|
||||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 20);
|
this.ButtonRemoveCar.Size = new System.Drawing.Size(118, 39);
|
||||||
this.maskedTextBoxNumber.TabIndex = 3;
|
this.ButtonRemoveCar.TabIndex = 1;
|
||||||
|
this.ButtonRemoveCar.Text = "удалить контейнеровоз";
|
||||||
|
this.ButtonRemoveCar.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
|
||||||
|
//
|
||||||
|
// ButtonAddCar
|
||||||
|
//
|
||||||
|
this.ButtonAddCar.Location = new System.Drawing.Point(16, 286);
|
||||||
|
this.ButtonAddCar.Name = "ButtonAddCar";
|
||||||
|
this.ButtonAddCar.Size = new System.Drawing.Size(118, 38);
|
||||||
|
this.ButtonAddCar.TabIndex = 0;
|
||||||
|
this.ButtonAddCar.Text = "добавить контейнеровоз";
|
||||||
|
this.ButtonAddCar.UseVisualStyleBackColor = true;
|
||||||
|
this.ButtonAddCar.Click += new System.EventHandler(this.ButtonAddCar_Click);
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
@ -119,5 +163,9 @@
|
|||||||
private System.Windows.Forms.Button ButtonRefreshCollection;
|
private System.Windows.Forms.Button ButtonRefreshCollection;
|
||||||
private System.Windows.Forms.Button ButtonRemoveCar;
|
private System.Windows.Forms.Button ButtonRemoveCar;
|
||||||
private System.Windows.Forms.Button ButtonAddCar;
|
private System.Windows.Forms.Button ButtonAddCar;
|
||||||
|
private System.Windows.Forms.TextBox textBoxStorageName;
|
||||||
|
private System.Windows.Forms.Button ButtonAddObject;
|
||||||
|
private System.Windows.Forms.ListBox listBoxStorages;
|
||||||
|
private System.Windows.Forms.Button ButtonDelObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,28 +14,73 @@ namespace Lab1ContainersShip
|
|||||||
{
|
{
|
||||||
public partial class FormShipCollection : Form
|
public partial class FormShipCollection : Form
|
||||||
{
|
{
|
||||||
private readonly ShipGenericCollection<DrawingShip, DrawningObjectShip> _ships;
|
private readonly ShipGenericStorage _storage;
|
||||||
public FormShipCollection()
|
public FormShipCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_ships = new ShipGenericCollection<DrawingShip,
|
_storage = new ShipGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
DrawningObjectShip>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormShipCollection_Load(object sender, EventArgs e)
|
private void FormShipCollection_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
private void ListBoxObjects_SelectedIndexChanged(object sender,EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowShips();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void ButtonAddCar_Click(object sender, EventArgs e)
|
private void ButtonAddCar_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
FormContainerShip form = new FormContainerShip();
|
FormContainerShip form = new FormContainerShip();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_ships + form.SelectedShip != -1)
|
if ((obj + form.SelectedShip) != 1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _ships.ShowShips();
|
pictureBoxCollection.Image = obj.ShowShips();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -43,20 +88,31 @@ DrawningObjectShip>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
private void ButtonRemoveCar_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))
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _ships.ShowShips();
|
pictureBoxCollection.Image = obj.ShowShips();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -67,7 +123,32 @@ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|||||||
|
|
||||||
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,7 @@
|
|||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="SetGeneric.cs" />
|
<Compile Include="SetGeneric.cs" />
|
||||||
|
<Compile Include="ShipGenericStorage.cs" />
|
||||||
<Compile Include="Status.cs" />
|
<Compile Include="Status.cs" />
|
||||||
<EmbeddedResource Include="FormContainerShip.resx">
|
<EmbeddedResource Include="FormContainerShip.resx">
|
||||||
<DependentUpon>FormContainerShip.cs</DependentUpon>
|
<DependentUpon>FormContainerShip.cs</DependentUpon>
|
||||||
|
@ -14,18 +14,20 @@ namespace Lab1ContainersShip
|
|||||||
// <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;
|
||||||
|
public 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>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@ -35,35 +37,13 @@ namespace Lab1ContainersShip
|
|||||||
public int Insert(T ship)
|
public int Insert(T ship)
|
||||||
{
|
{
|
||||||
// TODO вставка в начало набора
|
// TODO вставка в начало набора
|
||||||
int temp = 0;
|
if(_places.Count >= _maxCount)
|
||||||
int k = 0;
|
|
||||||
for(int j = 0; j < _places.Length; j++) {
|
|
||||||
if (_places[j] != null)
|
|
||||||
{
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (k == _places.Length)
|
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _places.Length; i++)
|
_places.Insert(0, ship);
|
||||||
{
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
temp = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
for (int i = temp; i > 0; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i -1];
|
|
||||||
|
|
||||||
}
|
|
||||||
_places[0] = ship;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,40 +63,23 @@ namespace Lab1ContainersShip
|
|||||||
// сдвиг всех объектов, находящихся справа от
|
// сдвиг всех объектов, находящихся справа от
|
||||||
//позиции до первого пустого элемента
|
//позиции до первого пустого элемента
|
||||||
// TODO вставка по позиции
|
// TODO вставка по позиции
|
||||||
int temp = 0;
|
if(_places.Count >= _maxCount)
|
||||||
int k = 0;
|
|
||||||
for (int j = position; j < _places.Length; j++)
|
|
||||||
{
|
|
||||||
if (_places[j] != null)
|
|
||||||
{
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (position < _places.Length && k < _places.Length-position)
|
|
||||||
{
|
|
||||||
for (int i = position; i < _places.Length; i++)
|
|
||||||
{
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
temp = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
for (int i = temp; i > position; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
_places[position] = ship;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(position < 0 || position > _places.Count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(position == _places.Count)
|
||||||
|
{
|
||||||
|
_places.Add(ship);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_places.Insert(position, ship);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
@ -128,7 +91,7 @@ namespace Lab1ContainersShip
|
|||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
// TODO удаление объекта из массива, присвоив элементу массива
|
// TODO удаление объекта из массива, присвоив элементу массива
|
||||||
//значение null
|
//значение null
|
||||||
if(position < _places.Length)
|
if(position < _places.Count && _places.Count < _maxCount)
|
||||||
{
|
{
|
||||||
_places[position] = null;
|
_places[position] = null;
|
||||||
return true;
|
return true;
|
||||||
@ -146,8 +109,7 @@ namespace Lab1ContainersShip
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T Get(int position)
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if(position < _places.Count && position >= 0)
|
||||||
if(position < _places.Length)
|
|
||||||
{
|
{
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
@ -156,6 +118,39 @@ namespace Lab1ContainersShip
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public T this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position < _places.Count && position >= 0)
|
||||||
|
{
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
|
||||||
|
Insert(value, position);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IEnumerable<T> GetShips(int? maxCars = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxCars.HasValue && i == maxCars.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ namespace Lab1ContainersShip
|
|||||||
public static bool operator -(ShipGenericCollection<T, U> collect, int
|
public static bool operator -(ShipGenericCollection<T, U> collect, int
|
||||||
pos)
|
pos)
|
||||||
{
|
{
|
||||||
T obj = collect._collection.Get(pos);
|
T obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
return collect._collection.Remove(pos);
|
return collect._collection.Remove(pos);
|
||||||
@ -84,7 +84,7 @@ namespace Lab1ContainersShip
|
|||||||
/// <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>
|
||||||
/// Вывод всего набора объектов
|
/// Вывод всего набора объектов
|
||||||
@ -124,15 +124,17 @@ namespace Lab1ContainersShip
|
|||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
private void DrawObjects(Graphics g)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
int i = 0;
|
||||||
|
foreach (var ship in _collection.GetShips())
|
||||||
{
|
{
|
||||||
|
|
||||||
T t = _collection.Get(i);
|
|
||||||
if (t != null)
|
if (ship != null)
|
||||||
{
|
{
|
||||||
t.SetPosition(((_collection.Count -i - 1) % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (_collection.Count - i-1) / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight);
|
ship.SetPosition(((_collection._maxCount -i - 1) % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (_collection._maxCount - i-1) / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight);
|
||||||
t.DrawShip(g);
|
ship.DrawShip(g);
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
// TODO получение объекта
|
// TODO получение объекта
|
||||||
// TODO установка позиции
|
// TODO установка позиции
|
||||||
// TODO прорисовка объекта
|
// TODO прорисовка объекта
|
||||||
|
96
Lab1ContainersShip/Lab1ContainersShip/ShipGenericStorage.cs
Normal file
96
Lab1ContainersShip/Lab1ContainersShip/ShipGenericStorage.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Lab1ContainersShip.DrawingObjects;
|
||||||
|
using Lab1ContainersShip.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Lab1ContainersShip
|
||||||
|
{
|
||||||
|
internal class ShipGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, ShipGenericCollection<DrawingShip,
|
||||||
|
DrawningObjectShip>> _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 ShipGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_shipStorages = new Dictionary<string, ShipGenericCollection<DrawingShip,
|
||||||
|
DrawningObjectShip>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для добавления
|
||||||
|
if (_shipStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_shipStorages[name] = new ShipGenericCollection<DrawingShip, DrawningObjectShip>(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (!_shipStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_shipStorages.Remove(name);
|
||||||
|
}
|
||||||
|
// TODO Прописать логику для удаления
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ShipGenericCollection<DrawingShip, DrawningObjectShip>
|
||||||
|
this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения набора
|
||||||
|
if (_shipStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _shipStorages[ind];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user