diff --git a/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs b/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs index 94d28b4..6962202 100644 --- a/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs +++ b/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs @@ -5,7 +5,7 @@ using AntiAircraftGun.Drawnings; namespace AntiAircraftGun.CollectionGenereticObjects; /// -/// Абстракция компании, хранящий коллекцию автомобилей +/// Абстракция компании, хранящий коллекцию бронемашин /// public abstract class AbstractCompany { @@ -30,7 +30,7 @@ public abstract class AbstractCompany protected readonly int _pictureHeight; /// - /// Коллекция поездов + /// Коллекция броенамашин /// protected ICollectionGenericObjects? _collection = null; @@ -57,11 +57,11 @@ public abstract class AbstractCompany /// Перегрузка оператора сложения для класса /// /// Компания - /// Добавляемый объект + /// Добавляемый объект /// - public static int operator +(AbstractCompany company, DrawningArmoredCar car) + public static int operator +(AbstractCompany company, DrawningArmoredCar airplan) { - return company._collection.Insert(car); + return company._collection.Insert(airplan); } /// @@ -70,9 +70,9 @@ public abstract class AbstractCompany /// Компания /// Номер удаляемого объекта /// - public static DrawningArmoredCar? operator -(AbstractCompany company, int position) + public static DrawningArmoredCar operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position); + return company._collection.Remove(position); } /// diff --git a/AntiAircraftGun/CollectionGenericObjects/CarBase.cs b/AntiAircraftGun/CollectionGenericObjects/CarBase.cs index 019daf9..005230b 100644 --- a/AntiAircraftGun/CollectionGenericObjects/CarBase.cs +++ b/AntiAircraftGun/CollectionGenericObjects/CarBase.cs @@ -18,36 +18,47 @@ public class CarBase : AbstractCompany { } + /// + /// Отрисовка базы + /// + /// Графика protected override void DrawBackgound(Graphics g) { - Pen pen = new(Color.Black); - for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + Pen pen = new Pen(Color.Black, 4f); + for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + g.DrawLine(pen, 0, i * _placeSizeHeight * 2, _pictureWidth / _placeSizeWidth * _placeSizeWidth, i * _placeSizeHeight * 2); + for (int j = 0; j < _pictureWidth / _placeSizeWidth + 1; ++j) { - g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j)); - g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1))); + g.DrawLine(pen, j * _placeSizeWidth, i * _placeSizeHeight * 2, j * _placeSizeWidth, i * _placeSizeHeight * 2 + _placeSizeHeight); } - g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight))); } - - } - + /// + /// Установка объекта в базу + /// protected override void SetObjectsPosition() { - int n = 0; - for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + int nowWidth = 0; + int nowHeight = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + if (nowHeight > _pictureHeight / _placeSizeHeight) { - DrawningArmoredCar? drawingTrans = _collection?.Get(n); - n++; - if (drawingTrans != null) - { - drawingTrans.SetPictureSize(_pictureWidth, _pictureHeight); - drawingTrans.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5); - } + return; + } + if (_collection?.Get(i) != null) + { + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(_placeSizeWidth * nowWidth + 30, nowHeight * _placeSizeHeight * 2 + 20); + } + + if (nowWidth < _pictureWidth / _placeSizeWidth - 1) nowWidth++; + else + { + nowWidth = 0; + nowHeight++; } } } diff --git a/AntiAircraftGun/FormArmoredCarCollection.Designer.cs b/AntiAircraftGun/FormArmoredCarCollection.Designer.cs index 5412d6c..c369d4c 100644 --- a/AntiAircraftGun/FormArmoredCarCollection.Designer.cs +++ b/AntiAircraftGun/FormArmoredCarCollection.Designer.cs @@ -67,6 +67,7 @@ buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; // // buttonGoToChek // @@ -77,6 +78,7 @@ buttonGoToChek.TabIndex = 5; buttonGoToChek.Text = "Передать на тесты"; buttonGoToChek.UseVisualStyleBackColor = true; + buttonGoToChek.Click += buttonGoToChek_Click; // // buttonRemoveArmoredCar // @@ -87,6 +89,7 @@ buttonRemoveArmoredCar.TabIndex = 4; buttonRemoveArmoredCar.Text = "Удалить бронемашину"; buttonRemoveArmoredCar.UseVisualStyleBackColor = true; + buttonRemoveArmoredCar.Click += buttonRemoveArmoredCar_Click; // // maskedTextBox // @@ -106,6 +109,7 @@ buttonAddAntiAircraftGun.TabIndex = 2; buttonAddAntiAircraftGun.Text = "Добавление зениитной установки"; buttonAddAntiAircraftGun.UseVisualStyleBackColor = true; + buttonAddAntiAircraftGun.Click += buttonAddAntiAircraftGun_Click; // // buttonAddArmoredCar // @@ -116,6 +120,7 @@ buttonAddArmoredCar.TabIndex = 1; buttonAddArmoredCar.Text = "Добавление бронемашины"; buttonAddArmoredCar.UseVisualStyleBackColor = true; + buttonAddArmoredCar.Click += buttonAddArmoredCar_Click; // // comboBoxSelectorCompany // @@ -127,6 +132,7 @@ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(198, 23); comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // diff --git a/AntiAircraftGun/FormArmoredCarCollection.cs b/AntiAircraftGun/FormArmoredCarCollection.cs index 02ed2e9..5dd8927 100644 --- a/AntiAircraftGun/FormArmoredCarCollection.cs +++ b/AntiAircraftGun/FormArmoredCarCollection.cs @@ -27,7 +27,7 @@ public partial class FormArmoredCarCollection : Form /// /// /// - private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxSelectorCompany.Text) { @@ -42,15 +42,14 @@ public partial class FormArmoredCarCollection : Form /// /// /// - private void ButtonAddArmoredCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningArmoredCar)); + private void buttonAddArmoredCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningArmoredCar)); /// /// Добавление зенитной установки /// /// /// - private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAntiAircraftGun)); - + private void buttonAddAntiAircraftGun_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAntiAircraftGun)); /// /// Создание объекта класса-перемещения /// @@ -113,18 +112,16 @@ public partial class FormArmoredCarCollection : Form /// /// /// - private void ButtonRemoveArmoredCar_Click(object sender, EventArgs e) + private void buttonRemoveArmoredCar_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } - int pos = Convert.ToInt32(maskedTextBox.Text); if (_company - pos != null) { @@ -137,12 +134,27 @@ public partial class FormArmoredCarCollection : Form } } + /// + /// Перерисовка коллекции + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } + /// /// Передача объекта в другую форму /// /// /// - private void ButtonGoToCheck_Click(object sender, EventArgs e) + private void buttonGoToChek_Click(object sender, EventArgs e) { if (_company == null) { @@ -174,18 +186,5 @@ public partial class FormArmoredCarCollection : Form form.ShowDialog(); } - /// - /// Перерисовка коллекции - /// - /// - /// - private void ButtonRefresh_Click(object sender, EventArgs e) - { - if (_company == null) - { - return; - } - - pictureBox.Image = _company.Show(); - } + } diff --git a/AntiAircraftGun/Program.cs b/AntiAircraftGun/Program.cs index 5abc523..09b34fb 100644 --- a/AntiAircraftGun/Program.cs +++ b/AntiAircraftGun/Program.cs @@ -11,7 +11,7 @@ namespace AntiAircraftGun // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAntiAircraftGun()); + Application.Run(new FormArmoredCarCollection()); } } } \ No newline at end of file