Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8893e998d1 |
69
ProjectTank/FormTankCollection.Designer.cs
generated
69
ProjectTank/FormTankCollection.Designer.cs
generated
@@ -34,6 +34,11 @@
|
|||||||
button2 = new Button();
|
button2 = new Button();
|
||||||
button4 = new Button();
|
button4 = new Button();
|
||||||
maskedTextBoxNumber = new TextBox();
|
maskedTextBoxNumber = new TextBox();
|
||||||
|
label2 = new Label();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
button1 = new Button();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
button5 = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@@ -56,7 +61,7 @@
|
|||||||
//
|
//
|
||||||
// button3
|
// button3
|
||||||
//
|
//
|
||||||
button3.Location = new Point(775, 247);
|
button3.Location = new Point(775, 448);
|
||||||
button3.Name = "button3";
|
button3.Name = "button3";
|
||||||
button3.Size = new Size(139, 29);
|
button3.Size = new Size(139, 29);
|
||||||
button3.TabIndex = 4;
|
button3.TabIndex = 4;
|
||||||
@@ -66,7 +71,7 @@
|
|||||||
//
|
//
|
||||||
// button2
|
// button2
|
||||||
//
|
//
|
||||||
button2.Location = new Point(775, 166);
|
button2.Location = new Point(775, 393);
|
||||||
button2.Name = "button2";
|
button2.Name = "button2";
|
||||||
button2.Size = new Size(139, 29);
|
button2.Size = new Size(139, 29);
|
||||||
button2.TabIndex = 5;
|
button2.TabIndex = 5;
|
||||||
@@ -76,7 +81,7 @@
|
|||||||
//
|
//
|
||||||
// button4
|
// button4
|
||||||
//
|
//
|
||||||
button4.Location = new Point(775, 32);
|
button4.Location = new Point(775, 306);
|
||||||
button4.Name = "button4";
|
button4.Name = "button4";
|
||||||
button4.Size = new Size(139, 29);
|
button4.Size = new Size(139, 29);
|
||||||
button4.TabIndex = 6;
|
button4.TabIndex = 6;
|
||||||
@@ -86,16 +91,67 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(775, 133);
|
maskedTextBoxNumber.Location = new Point(775, 360);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(139, 27);
|
maskedTextBoxNumber.Size = new Size(139, 27);
|
||||||
maskedTextBoxNumber.TabIndex = 7;
|
maskedTextBoxNumber.TabIndex = 7;
|
||||||
//
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(775, 51);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(66, 20);
|
||||||
|
label2.TabIndex = 8;
|
||||||
|
label2.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(775, 74);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(139, 27);
|
||||||
|
textBoxStorageName.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
button1.Location = new Point(775, 107);
|
||||||
|
button1.Name = "button1";
|
||||||
|
button1.Size = new Size(139, 29);
|
||||||
|
button1.TabIndex = 10;
|
||||||
|
button1.Text = "Добавить набор";
|
||||||
|
button1.UseVisualStyleBackColor = true;
|
||||||
|
button1.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 20;
|
||||||
|
listBoxStorages.Location = new Point(775, 142);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(139, 84);
|
||||||
|
listBoxStorages.TabIndex = 11;
|
||||||
|
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// button5
|
||||||
|
//
|
||||||
|
button5.Location = new Point(775, 232);
|
||||||
|
button5.Name = "button5";
|
||||||
|
button5.Size = new Size(139, 29);
|
||||||
|
button5.TabIndex = 12;
|
||||||
|
button5.Text = "Удалить набор";
|
||||||
|
button5.UseVisualStyleBackColor = true;
|
||||||
|
button5.Click += ButtonDelObject_Click;
|
||||||
|
//
|
||||||
// FormTankCollection
|
// FormTankCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(926, 486);
|
ClientSize = new Size(926, 486);
|
||||||
|
Controls.Add(button5);
|
||||||
|
Controls.Add(listBoxStorages);
|
||||||
|
Controls.Add(button1);
|
||||||
|
Controls.Add(textBoxStorageName);
|
||||||
|
Controls.Add(label2);
|
||||||
Controls.Add(maskedTextBoxNumber);
|
Controls.Add(maskedTextBoxNumber);
|
||||||
Controls.Add(button4);
|
Controls.Add(button4);
|
||||||
Controls.Add(button2);
|
Controls.Add(button2);
|
||||||
@@ -117,5 +173,10 @@
|
|||||||
private Button button2;
|
private Button button2;
|
||||||
private Button button4;
|
private Button button4;
|
||||||
private TextBox maskedTextBoxNumber;
|
private TextBox maskedTextBoxNumber;
|
||||||
|
private Label label2;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private Button button1;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button button5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,19 +6,73 @@ namespace ProjectTank
|
|||||||
{
|
{
|
||||||
public partial class FormTankCollection : Form
|
public partial class FormTankCollection : Form
|
||||||
{
|
{
|
||||||
/// <summary>
|
private readonly TanksGenericStorage _storage;
|
||||||
/// Набор объектов
|
|
||||||
/// </summary>
|
|
||||||
private readonly TanksGenericCollection<DrawningTankBase, DrawningObjectTank> _tanks;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormTankCollection()
|
public FormTankCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_tanks = new TanksGenericCollection<DrawningTankBase, DrawningObjectTank>(pictureBoxCollection.Width,
|
_storage = new TanksGenericStorage(pictureBoxCollection.Width,
|
||||||
pictureBoxCollection.Height);
|
pictureBoxCollection.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
string objName = textBoxStorageName.Text;
|
||||||
|
if (string.IsNullOrEmpty(objName))
|
||||||
|
{
|
||||||
|
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]?.ShowTanks();
|
||||||
|
}
|
||||||
|
/// <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>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -26,18 +80,20 @@ namespace ProjectTank
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonAddTank_Click(object sender, EventArgs e)
|
private void ButtonAddTank_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1) return;
|
||||||
|
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null) return;
|
||||||
|
|
||||||
FormTank form = new();
|
FormTank form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_tanks + form.SelectedTank != null)
|
if (obj + form.SelectedTank)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _tanks.ShowTanks();
|
pictureBoxCollection.Image = obj.ShowTanks();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
|
||||||
}
|
}
|
||||||
|
else MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -47,32 +103,41 @@ namespace ProjectTank
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRemoveTank_Click(object sender, EventArgs e)
|
private void ButtonRemoveTank_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 (_tanks - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _tanks.ShowTanks();
|
pictureBoxCollection.Image = obj.ShowTanks();
|
||||||
maskedTextBoxNumber.Text = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
|
||||||
}
|
}
|
||||||
|
else MessageBox.Show("Не удалось удалить объект");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновление рисунка по набору
|
/// Обновление рисунка по набору
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <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 = _tanks.ShowTanks();
|
if (listBoxStorages.SelectedIndex == -1) return;
|
||||||
|
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null) return;
|
||||||
|
|
||||||
|
pictureBoxCollection.Image = obj.ShowTanks();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,28 +9,31 @@ namespace ProjectTank.Generics
|
|||||||
/// <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>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="count"></param>
|
/// <param name="count"></param>
|
||||||
|
private readonly int _maxCount;
|
||||||
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="tank">Добавляемый автомобиль</param>
|
/// <param name="tank">Добавляемый автомобиль</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T tank)
|
public bool Insert(T tank)
|
||||||
{
|
{
|
||||||
if (_places[Count-1] != null)
|
if (_places.Count == _maxCount)
|
||||||
return -1;
|
return false;
|
||||||
return Insert(tank, 0);
|
return Insert(tank, 0);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,22 +42,12 @@ namespace ProjectTank.Generics
|
|||||||
/// <param name="tank">Добавляемый автомобиль</param>
|
/// <param name="tank">Добавляемый автомобиль</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T tank, int position)
|
public bool Insert(T tank, int position)
|
||||||
{
|
{
|
||||||
if (!(position >= 0 && position < Count)) return -1;
|
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||||
|
return false;
|
||||||
if (_places[position] != null)
|
_places.Insert(position, tank);
|
||||||
{
|
return true;
|
||||||
int ind = position;
|
|
||||||
while (ind < Count && _places[ind] != null)
|
|
||||||
ind++;
|
|
||||||
if (ind == Count)
|
|
||||||
return -1;
|
|
||||||
for (int i = ind - 1; i >= position; i--)
|
|
||||||
_places[i + 1] = _places[i];
|
|
||||||
}
|
|
||||||
_places[position] = tank;
|
|
||||||
return position;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
@@ -63,20 +56,40 @@ namespace ProjectTank.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
if (!(position >= 0 && position < Count) || _places[position] == null)
|
if (!(position >= 0 && position < Count))
|
||||||
return false;
|
return false;
|
||||||
_places[position] = null;
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get {
|
||||||
|
if (!(position >= 0 && position < Count))
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||||
|
return;
|
||||||
|
_places.Insert(position, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта из набора по позиции
|
/// Получение объекта из набора по позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T? Get(int position)
|
public IEnumerable<T?> GetTanks(int? maxTanks = null)
|
||||||
{
|
{
|
||||||
if (!(position >= 0 && position < Count)) return null;
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
return _places[position];
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxTanks.HasValue && i == maxTanks.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,10 +49,12 @@ namespace ProjectTank.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 +(TanksGenericCollection<T,U> collect, T? obj)
|
public static bool operator +(TanksGenericCollection<T,U> collect, T? obj)
|
||||||
{
|
{
|
||||||
if (obj == null) return -1;
|
if (obj == null)
|
||||||
return collect?._collection.Insert(obj) ?? -1;
|
return false;
|
||||||
|
|
||||||
|
return collect?._collection.Insert(obj) ?? false;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
@@ -60,13 +62,17 @@ namespace ProjectTank.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 -(TanksGenericCollection<T, U> collect, int pos)
|
public static T? operator -(TanksGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection.Get(pos);
|
T? obj = collect._collection[pos];
|
||||||
|
if (obj != null)
|
||||||
if (obj != null) return collect._collection.Remove(pos);
|
{
|
||||||
return false;
|
collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта IMoveableObject
|
/// Получение объекта IMoveableObject
|
||||||
@@ -75,7 +81,7 @@ namespace ProjectTank.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>
|
||||||
/// Вывод всего набора объектов
|
/// Вывод всего набора объектов
|
||||||
@@ -113,9 +119,9 @@ namespace ProjectTank.Generics
|
|||||||
/// <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 tank in _collection.GetTanks())
|
||||||
{
|
{
|
||||||
DrawningTankBase tank = _collection.Get(i);
|
|
||||||
if (tank != null)
|
if (tank != null)
|
||||||
{
|
{
|
||||||
int columnsCount = _pictureHeight / _placeSizeHeight + 1;
|
int columnsCount = _pictureHeight / _placeSizeHeight + 1;
|
||||||
@@ -125,6 +131,8 @@ namespace ProjectTank.Generics
|
|||||||
|
|
||||||
tank.SetPosition(colIndex * _placeSizeWidth + 2, rowIndex * _placeSizeHeight + 2);
|
tank.SetPosition(colIndex * _placeSizeWidth + 2, rowIndex * _placeSizeHeight + 2);
|
||||||
tank.DrawTransport(g);
|
tank.DrawTransport(g);
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
75
ProjectTank/Generics/TanksGenericStorage.cs
Normal file
75
ProjectTank/Generics/TanksGenericStorage.cs
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
using ProjectTank.DrawningObjects;
|
||||||
|
using ProjectTank.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectTank.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс для хранения коллекции
|
||||||
|
/// </summary>
|
||||||
|
internal class TanksGenericStorage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, TanksGenericCollection<DrawningTankBase,
|
||||||
|
DrawningObjectTank>> _tankStorages;
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Keys => _tankStorages.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 TanksGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_tankStorages = new Dictionary<string,
|
||||||
|
TanksGenericCollection<DrawningTankBase, DrawningObjectTank>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
_tankStorages.Add(name, new TanksGenericCollection<DrawningTankBase, DrawningObjectTank> (_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (!_tankStorages.ContainsKey(name))
|
||||||
|
return;
|
||||||
|
_tankStorages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public TanksGenericCollection<DrawningTankBase, DrawningObjectTank>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_tankStorages.ContainsKey(ind))
|
||||||
|
return _tankStorages[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user