From 9bee490bb3a773183e8af78a6fa706b28d95b25a Mon Sep 17 00:00:00 2001 From: marusya Date: Sun, 5 Nov 2023 21:19:40 +0400 Subject: [PATCH 1/3] lab4 --- .../DrawningUsta.cs | 7 +- .../EntityUstaBat.cs | 2 +- .../FormSelfPropelledArtilleryUnit.cs | 2 +- ...opelledArtilleryUnitCollection.Designer.cs | 96 +++++++++-- ...ormSelfPropelledArtilleryUnitCollection.cs | 158 +++++++++++++++--- .../IMoveableObject_Realise.cs | 2 +- .../SelfPropelledArtilleryUnit/SetGeneric.cs | 118 ++++++------- .../UstaGenericCollection.cs | 41 ++--- .../UstaGenericStorage.cs | 89 ++++++++++ 9 files changed, 393 insertions(+), 122 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericStorage.cs diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs index 796f752..679c4e5 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs @@ -68,8 +68,8 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects /// Основной цвет /// Ширина картинки /// Высота картинки - /// Ширина прорисовки установки - /// Высота прорисовки установки + /// Ширина прорисовки установки + /// Высота прорисовки установки protected DrawningUsta(int speed, double weight, Color bodyColor, int width, int height, int ustaWidth, int ustaHeight) { @@ -93,7 +93,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects public void SetPosition(int x, int y) { // TODO: Изменение x, y, если при установке объект выходит за границы - if (x < 0 || y < 0 || x + _ustaWidth > _pictureWidth || y + _ustaHeight > _pictureHeight) + if (x < 0 || y < 0) { x = 10; y = 10; @@ -198,6 +198,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects Brush BodyColor = new SolidBrush(EntityUsta.BodyColor); //зеленый темнее + int lineWidth = 10; Color color1 = Color.FromArgb(65, 72, 51); Brush pen1 = new SolidBrush(color1); diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntityUstaBat.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntityUstaBat.cs index 18fe7e8..3b466d9 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntityUstaBat.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntityUstaBat.cs @@ -24,7 +24,7 @@ namespace SelfPropelledArtilleryUnit.Entities /// Инициализация полей объекта-класса установки с вооружением /// /// Скорость - /// Вес установки + /// Вес автомобиля /// Основной цвет /// Дополнительный цвет /// Признак наличия пушки diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs index 27f6e50..1ae64a4 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs @@ -33,7 +33,7 @@ namespace SelfPropelledArtilleryUnit } /// - /// + /// /// private void Draw() { diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.Designer.cs index 61b48ee..a171aca 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.Designer.cs @@ -34,14 +34,21 @@ pictureBoxCollection = new PictureBox(); maskedTextBoxNumber = new MaskedTextBox(); groupBox1 = new GroupBox(); + groupBox2 = new GroupBox(); + listBoxStorage = new ListBox(); + ButtonDelObject = new Button(); + ButtonAddObject = new Button(); + textBoxStorageName = new TextBox(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); SuspendLayout(); // // ButtonAddUsta // - ButtonAddUsta.Location = new Point(665, 45); + ButtonAddUsta.Location = new Point(26, 314); ButtonAddUsta.Name = "ButtonAddUsta"; - ButtonAddUsta.Size = new Size(166, 31); + ButtonAddUsta.Size = new Size(166, 40); ButtonAddUsta.TabIndex = 0; ButtonAddUsta.Text = "Добавить арт. установку"; ButtonAddUsta.UseVisualStyleBackColor = true; @@ -49,9 +56,9 @@ // // ButtonRemoveUsta // - ButtonRemoveUsta.Location = new Point(665, 129); + ButtonRemoveUsta.Location = new Point(26, 400); ButtonRemoveUsta.Name = "ButtonRemoveUsta"; - ButtonRemoveUsta.Size = new Size(166, 31); + ButtonRemoveUsta.Size = new Size(166, 39); ButtonRemoveUsta.TabIndex = 1; ButtonRemoveUsta.Text = "Удалить арт. установку"; ButtonRemoveUsta.UseVisualStyleBackColor = true; @@ -59,9 +66,9 @@ // // ButtonRefreshCollection // - ButtonRefreshCollection.Location = new Point(665, 215); + ButtonRefreshCollection.Location = new Point(26, 478); ButtonRefreshCollection.Name = "ButtonRefreshCollection"; - ButtonRefreshCollection.Size = new Size(166, 31); + ButtonRefreshCollection.Size = new Size(166, 40); ButtonRefreshCollection.TabIndex = 2; ButtonRefreshCollection.Text = "Обновить коллекцию"; ButtonRefreshCollection.UseVisualStyleBackColor = true; @@ -71,7 +78,7 @@ // pictureBoxCollection.Location = new Point(0, 0); pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(643, 423); + pictureBoxCollection.Size = new Size(637, 583); pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom; pictureBoxCollection.TabIndex = 3; pictureBoxCollection.TabStop = false; @@ -79,7 +86,7 @@ // maskedTextBoxNumber // maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point); - maskedTextBoxNumber.Location = new Point(695, 100); + maskedTextBoxNumber.Location = new Point(56, 371); maskedTextBoxNumber.Mask = "00"; maskedTextBoxNumber.Name = "maskedTextBoxNumber"; maskedTextBoxNumber.Size = new Size(100, 22); @@ -88,29 +95,83 @@ // // groupBox1 // + groupBox1.Controls.Add(groupBox2); + groupBox1.Controls.Add(ButtonAddUsta); + groupBox1.Controls.Add(ButtonRefreshCollection); + groupBox1.Controls.Add(maskedTextBoxNumber); + groupBox1.Controls.Add(ButtonRemoveUsta); groupBox1.Location = new Point(643, 12); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(209, 411); + groupBox1.Size = new Size(209, 533); groupBox1.TabIndex = 5; groupBox1.TabStop = false; groupBox1.Text = "Инструменты"; // + // groupBox2 + // + groupBox2.Controls.Add(listBoxStorage); + groupBox2.Controls.Add(ButtonDelObject); + groupBox2.Controls.Add(ButtonAddObject); + groupBox2.Controls.Add(textBoxStorageName); + groupBox2.Location = new Point(6, 22); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(197, 274); + groupBox2.TabIndex = 6; + groupBox2.TabStop = false; + groupBox2.Text = "Наборы"; + // + // listBoxStorage + // + listBoxStorage.FormattingEnabled = true; + listBoxStorage.ItemHeight = 15; + listBoxStorage.Location = new Point(20, 106); + listBoxStorage.Name = "listBoxStorage"; + listBoxStorage.Size = new Size(158, 109); + listBoxStorage.TabIndex = 9; + listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged; + // + // ButtonDelObject + // + ButtonDelObject.Location = new Point(33, 235); + ButtonDelObject.Name = "ButtonDelObject"; + ButtonDelObject.Size = new Size(136, 33); + ButtonDelObject.TabIndex = 8; + ButtonDelObject.Text = "Удалить набор"; + ButtonDelObject.UseVisualStyleBackColor = true; + ButtonDelObject.Click += ButtonDelObject_Click; + // + // ButtonAddObject + // + ButtonAddObject.Location = new Point(33, 54); + ButtonAddObject.Name = "ButtonAddObject"; + ButtonAddObject.Size = new Size(136, 33); + ButtonAddObject.TabIndex = 7; + ButtonAddObject.Text = "Добавить набор"; + ButtonAddObject.UseVisualStyleBackColor = true; + ButtonAddObject.Click += ButtonAddObject_Click; + // + // textBoxStorageName + // + textBoxStorageName.Location = new Point(20, 22); + textBoxStorageName.Name = "textBoxStorageName"; + textBoxStorageName.Size = new Size(158, 23); + textBoxStorageName.TabIndex = 0; + // // FormSelfPropelledArtilleryUnitCollection // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(859, 435); - Controls.Add(ButtonRefreshCollection); - Controls.Add(ButtonRemoveUsta); - Controls.Add(maskedTextBoxNumber); - Controls.Add(ButtonAddUsta); + ClientSize = new Size(867, 584); Controls.Add(groupBox1); Controls.Add(pictureBoxCollection); Name = "FormSelfPropelledArtilleryUnitCollection"; Text = "Набор арт. установок"; ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + groupBox2.PerformLayout(); ResumeLayout(false); - PerformLayout(); } #endregion @@ -121,5 +182,10 @@ private PictureBox pictureBoxCollection; private MaskedTextBox maskedTextBoxNumber; private GroupBox groupBox1; + private GroupBox groupBox2; + private TextBox textBoxStorageName; + private ListBox listBoxStorage; + private Button ButtonDelObject; + private Button ButtonAddObject; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.cs index 8b6336c..624d48e 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.cs @@ -1,69 +1,183 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; + using SelfPropelledArtilleryUnit.DrawningObjects; using SelfPropelledArtilleryUnit.Drawnings; using SelfPropelledArtilleryUnit.Generics; using SelfPropelledArtilleryUnit.MovementStrategy; + namespace SelfPropelledArtilleryUnit { + /// + /// Форма для работы с набором объектов класса DrawningUsta + /// public partial class FormSelfPropelledArtilleryUnitCollection : Form { - private readonly UstaGenericCollection _usta; + /// + /// Набор объектов + /// + private readonly UstaGenericStorage _storage; + /// + /// Конструктор + /// public FormSelfPropelledArtilleryUnitCollection() { InitializeComponent(); - _usta = new UstaGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + _storage = new UstaGenericStorage(pictureBoxCollection.Width, + pictureBoxCollection.Height); } + /// + /// Заполнение listBoxObjects + /// + private void ReloadObjects() + { + int index = listBoxStorage.SelectedIndex; + listBoxStorage.Items.Clear(); + for (int i = 0; i < _storage.Keys.Count; i++) + { + listBoxStorage.Items.Add(_storage.Keys[i]); + } + if (listBoxStorage.Items.Count > 0 && (index == -1 || index + >= listBoxStorage.Items.Count)) + { + listBoxStorage.SelectedIndex = 0; + } + else if (listBoxStorage.Items.Count > 0 && index > -1 && + index < listBoxStorage.Items.Count) + { + listBoxStorage.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 listBoxStorage_SelectedIndexChanged(object sender, + EventArgs e) + { + pictureBoxCollection.Image = + _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowUsta(); + } + /// + /// Удаление набора + /// + /// + /// + private void ButtonDelObject_Click(object sender, EventArgs e) + { + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + _storage.DelSet(listBoxStorage.SelectedItem.ToString() + ?? string.Empty); + ReloadObjects(); + } + } + /// + /// Добавление объекта в набор + /// + /// + /// private void ButtonAddUsta_Click(object sender, EventArgs e) { + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } FormSelfPropelledArtilleryUnit form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_usta + form.SelectedUsta > -1) + if (obj + form.SelectedUsta > -1) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _usta.ShowUsta(); + pictureBoxCollection.Image = obj.ShowUsta(); } else { MessageBox.Show("Не удалось добавить объект"); } } - } - + /// + /// Удаление объекта из набора + /// + /// + /// private void ButtonRemoveUsta_Click(object sender, EventArgs e) { - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_usta - pos != null) + if (obj - pos != null) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = _usta.ShowUsta(); + pictureBoxCollection.Image = obj.ShowUsta(); } else { MessageBox.Show("Не удалось удалить объект"); } - } - - private void ButtonRefreshCollection_Click(object sender, EventArgs e) + /// + /// Обновление рисунка по набору + /// + /// + /// + private void ButtonRefreshCollection_Click(object sender, EventArgs + e) { - pictureBoxCollection.Image = _usta.ShowUsta(); + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + pictureBoxCollection.Image = obj.ShowUsta(); } } } + diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/IMoveableObject_Realise.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/IMoveableObject_Realise.cs index 89a26d6..ae028f3 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/IMoveableObject_Realise.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/IMoveableObject_Realise.cs @@ -10,7 +10,7 @@ using SelfPropelledArtilleryUnit.Drawnings; namespace SelfPropelledArtilleryUnit.MovementStrategy { /// - /// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter) + /// Реализация интерфейса IDrawningObject для работы с объектом DrawningUsta (паттерн Adapter) /// public class DrawningObjectUsta : IMoveableObject { diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs index 11567c2..972be12 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs @@ -1,4 +1,10 @@ -namespace SelfPropelledArtilleryUnit.Generics +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SelfPropelledArtilleryUnit.Generics { /// /// Параметризованный набор объектов @@ -6,72 +12,52 @@ /// internal class SetGeneric where T : class + { /// /// Массив объектов, которые храним /// - private readonly T?[] _places; + private readonly List _places; /// /// Количество объектов в массиве /// - public int Count => _places.Length; + public int Count => _places.Count; + /// + /// Максимальное количество объектов в списке + /// + private readonly int _maxCount; /// /// Конструктор /// /// public SetGeneric(int count) { - _places = new T?[count]; + _maxCount = count; + _places = new List(count); } /// /// Добавление объекта в набор - /// - /// Добавляемая установка - /// public int Insert(T usta) { + return Insert(usta, 0); } - /// - /// Добавление объекта в набор на конкретную позицию - /// - /// Добавляемая установка - /// Позиция + /// public int Insert(T usta, int position) { - // TODO проверка позиции - if (position < 0 && position > Count) - { + if (position < 0 || position >= _maxCount) return -1; - } - if (_places[position] != null) - { - int d = 0; - for (int j = 1; j < Count - position; j++) - { - if (_places[position + j] == null) - { - d = position + j; - break; - } - } - if (d == 0) - { - return -1; - } - for (int j = d; j > position; j--) - { - _places[j] = _places[j - 1]; - } - } - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - // TODO вставка по позиции - _places[position] = usta; + + if (Count >= _maxCount) + return -1; + + + + _places.Insert(position, usta); return position; } + /// /// Удаление объекта из набора с конкретной позиции /// @@ -79,32 +65,46 @@ /// public bool Remove(int position) { - // TODO проверка позиции - // Проверка позиции - if (position < 0 || position >= _places.Length) - { - // Позиция недопустима - return false; - } - // TODO удаление объекта из массива, присвоив элементу массива значение null - _places[position] = null; + if ((position < 0) || (position > _maxCount)) return false; + _places.RemoveAt(position); return true; } /// /// Получение объекта из набора по позиции /// /// - /// - public T? Get(int position) + /// + public T? this[int position] { - // TODO проверка позиции - if (position < 0 || position >= _places.Length) + get { - // Позиция недопустима - return null; + if (position < 0 || position > _maxCount) + return null; + return _places[position]; + } + set + { + if (position < 0 || position > _maxCount) + return; + _places[position] = value; + } + + + } + /// + /// Проход по списку + /// + /// + public IEnumerable GetUsta(int? maxUsta = null) + { + for (int i = 0; i < _places.Count; ++i) + { + yield return _places[i]; + if (maxUsta.HasValue && i == maxUsta.Value) + { + yield break; + } } - return _places[position]; } } -} - +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericCollection.cs index 1cae4af..a221de8 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericCollection.cs @@ -28,7 +28,7 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// Размер занимаемого объектом места (высота) /// - private readonly int _placeSizeHeight = 100; + private readonly int _placeSizeHeight = 110; /// /// Набор объектов /// @@ -70,7 +70,7 @@ namespace SelfPropelledArtilleryUnit.Generics public static bool operator -(UstaGenericCollection collect, int pos) { - T? obj = collect._collection.Get(pos); + T? obj = collect._collection[pos]; if (obj != null) { return collect._collection.Remove(pos); @@ -84,7 +84,7 @@ namespace SelfPropelledArtilleryUnit.Generics /// public U? GetU(int pos) { - return (U?)_collection.Get(pos)?.GetMoveableObject; + return (U?)_collection[pos]?.GetMoveableObject; } /// /// Вывод всего набора объектов @@ -111,7 +111,7 @@ namespace SelfPropelledArtilleryUnit.Generics 1; ++j) {//линия разметки места g.DrawLine(pen, i * _placeSizeWidth, j * - _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 2, j * + _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 2 , j * _placeSizeHeight); } g.DrawLine(pen, i * _placeSizeWidth, 0, i * @@ -124,28 +124,29 @@ namespace SelfPropelledArtilleryUnit.Generics /// private void DrawObjects(Graphics g) { - int c = 11; - - for (int i = 0; i < _collection.Count; i++) + int c = 14; + foreach (var usta in _collection.GetUsta()) { - if (i % 3 == 0 && i != 0) + if (usta != null) { - c = c - 3; - } - T? obj = _collection.Get(i); - if (obj != null) - { - // Получение объекта - IMoveableObject moveableObject = obj.GetMoveableObject; - // Установка позиции + int index = _collection.GetUsta().ToList().IndexOf(usta); + if (index % 3 == 0 && index != 0) + { + c = c - 3; - int x = i % (_pictureWidth / _placeSizeWidth) * _placeSizeWidth + 3; - int y = c / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight + 10; - moveableObject.SetPosition(x, y); + } + // TODO получение объекта + // TODO установка позиции + // TODO прорисовка объекта + // Установка позиции объекта + + int posX = index % (_pictureWidth / _placeSizeWidth) * _placeSizeWidth + 3; + int posY = c / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight + 15; // Прорисовка объекта - moveableObject.Draw(g); + usta.SetPosition(posX, posY); + usta.DrawTransport(g); } } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericStorage.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericStorage.cs new file mode 100644 index 0000000..3c3fac3 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericStorage.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using SelfPropelledArtilleryUnit.Drawnings; +using SelfPropelledArtilleryUnit.MovementStrategy; +using SelfPropelledArtilleryUnit.DrawningObjects; +namespace SelfPropelledArtilleryUnit.Generics + +{ + internal class UstaGenericStorage + { + /// + /// Словарь (хранилище) + /// + readonly Dictionary> _ustaStorages; + /// + /// Возвращение списка названий наборов + /// + public List Keys => _ustaStorages.Keys.ToList(); + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Конструктор + /// + /// + /// + public UstaGenericStorage(int pictureWidth, int pictureHeight) + { + _ustaStorages = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// + /// Добавление набора + /// + /// Название набора + public void AddSet(string name) + { + // TODO Прописать логику для добавления + if (!_ustaStorages.ContainsKey(name)) + { + var ustaCollection = new UstaGenericCollection(_pictureWidth, _pictureHeight); + _ustaStorages.Add(name, ustaCollection); + } + } + /// + /// Удаление набора + /// + /// Название набора + public void DelSet(string name) + { + // TODO Прописать логику для удаления + if (_ustaStorages.ContainsKey(name)) + { + _ustaStorages.Remove(name); + } + } + /// + /// Доступ к набору + /// + /// + /// + public UstaGenericCollection? this[string ind] + { + get + { + // TODO Продумать логику получения набора + if (_ustaStorages.ContainsKey(ind)) + { + return _ustaStorages[ind]; + } + return null; + + } + } + } +} + -- 2.25.1 From 4f5c84eccdad27ca0fcd1b3ddd29a8438530fc88 Mon Sep 17 00:00:00 2001 From: marusya Date: Sun, 5 Nov 2023 21:27:24 +0400 Subject: [PATCH 2/3] oo --- .../SelfPropelledArtilleryUnit/DrawningUsta.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs index 679c4e5..c390668 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs @@ -68,8 +68,8 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects /// Основной цвет /// Ширина картинки /// Высота картинки - /// Ширина прорисовки установки - /// Высота прорисовки установки + /// Ширина прорисовки установки + /// Высота прорисовки установки protected DrawningUsta(int speed, double weight, Color bodyColor, int width, int height, int ustaWidth, int ustaHeight) { @@ -93,7 +93,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects public void SetPosition(int x, int y) { // TODO: Изменение x, y, если при установке объект выходит за границы - if (x < 0 || y < 0) + if (x < 0 || y < 0 || x + _ustaWidth > _pictureWidth || y + _ustaHeight > _pictureHeight) { x = 10; y = 10; -- 2.25.1 From 2c78fa0fbc29e1b458f5520047dc706c7426c755 Mon Sep 17 00:00:00 2001 From: marusya Date: Sun, 5 Nov 2023 21:29:06 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=B0=D1=83=D1=83=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelfPropelledArtilleryUnit/EntityUstaBat.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntityUstaBat.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntityUstaBat.cs index 3b466d9..18fe7e8 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntityUstaBat.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntityUstaBat.cs @@ -24,7 +24,7 @@ namespace SelfPropelledArtilleryUnit.Entities /// Инициализация полей объекта-класса установки с вооружением /// /// Скорость - /// Вес автомобиля + /// Вес установки /// Основной цвет /// Дополнительный цвет /// Признак наличия пушки -- 2.25.1