From fade11cda8b54d8d8887c00a793579857b8d0a1a Mon Sep 17 00:00:00 2001 From: Garifullin-Farid <95081032+Garifullin-Farid@users.noreply.github.com> Date: Sun, 19 May 2024 18:36:55 +0400 Subject: [PATCH 1/5] LabWork_2 # Conflicts: # ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs # ProjectTank/ProjectTank/Entities/EntityTank.cs # ProjectTank/ProjectTank/MovementStrategy/MoveableTank.cs --- ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs | 4 ++-- ProjectTank/ProjectTank/Entities/EntityTank.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs b/ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs index 8c7a0ac..289bdec 100644 --- a/ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs +++ b/ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs @@ -1,4 +1,4 @@ -namespace ProjectTank.Drawning; +namespace ProjectTank.Drawning; /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// @@ -8,7 +8,7 @@ public class DrawningBattleTank :DrawningTank /// Конструктор /// /// Скорость - /// Вес автомобиля + /// Вес /// Основной цвет /// Дополнительный цвет /// Признак наличия пушки diff --git a/ProjectTank/ProjectTank/Entities/EntityTank.cs b/ProjectTank/ProjectTank/Entities/EntityTank.cs index 3ec8cc3..e7d86c5 100644 --- a/ProjectTank/ProjectTank/Entities/EntityTank.cs +++ b/ProjectTank/ProjectTank/Entities/EntityTank.cs @@ -1,4 +1,4 @@ -namespace ProjectTank.Entities +namespace ProjectTank.Entities { public class EntityTank { -- 2.25.1 From ad9095167319fb076e064aafef8485401f4b0955 Mon Sep 17 00:00:00 2001 From: Garifullin-Farid <95081032+Garifullin-Farid@users.noreply.github.com> Date: Sun, 17 Mar 2024 16:11:32 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICollectionGenericObjects.cs | 49 ++++++++ .../MassiveGenericObjects.cs | 113 ++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..812597b --- /dev/null +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,49 @@ +namespace ProjectTank.CollectionGenericObjects +{ + /// + /// Интерфейс описания действий для набора хранимых данных + /// + /// + public interface ICollectionGenericObjects + where T : class + { + /// + /// Количество объектов в коллекции + /// + int Count { get; } + + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj); + + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj, int position); + + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно, false - удаление не удалось + T? Remove(int position); + + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); + } +} diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..4326cf4 --- /dev/null +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,113 @@ +using ProjectTank.CollectionGenericObjects; +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class MassiveGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// Массив объектов, которые храним + /// + private T?[] _collection; + + public int Count => _collection.Length; + + public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + + /// + /// Конструктор + /// + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + + public T? Get(int position) + { + if (position >= 0 && position < Count) + { + return _collection[position]; + } + + return null; + } + + public int Insert(T obj) + { + // вставка в свободное место набора + for (int i = 0; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + + return -1; + } + + public int Insert(T obj, int position) + { + // проверка позиции + if (position < 0 || position >= Count) + { + return -1; + } + + // проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до + if (_collection[position] != null) + { + bool pushed = false; + for (int index = position + 1; index < Count; index++) + { + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } + } + + if (!pushed) + { + for (int index = position - 1; index >= 0; index--) + { + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } + } + } + + if (!pushed) + { + return position; + } + } + + // вставка + _collection[position] = obj; + return position; + } + + public T? Remove(int position) + { + // проверка позиции + if (position < 0 || position >= Count) + { + return null; + } + + if (_collection[position] == null) return null; + + T? temp = _collection[position]; + _collection[position] = null; + return temp; + } +} \ No newline at end of file -- 2.25.1 From 4ed2c0de3cb6b0de7196d52701ec7d4e9b86a6be Mon Sep 17 00:00:00 2001 From: Garifullin-Farid <95081032+Garifullin-Farid@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:23:32 +0400 Subject: [PATCH 3/5] LabWork_3 --- .../AbstractCompany.cs | 115 ++++++++++++ .../TankSharingServise.cs | 62 +++++++ ProjectTank/ProjectTank/FormBattleTank.cs | 12 ++ .../FormBattleTankCollection.Designer.cs | 173 ++++++++++++++++++ .../ProjectTank/FormBattleTankCollection.cs | 150 +++++++++++++++ .../ProjectTank/FormBattleTankCollection.resx | 120 ++++++++++++ ProjectTank/ProjectTank/Program.cs | 2 +- 7 files changed, 633 insertions(+), 1 deletion(-) create mode 100644 ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectTank/ProjectTank/CollectionGenericObjects/TankSharingServise.cs create mode 100644 ProjectTank/ProjectTank/FormBattleTankCollection.Designer.cs create mode 100644 ProjectTank/ProjectTank/FormBattleTankCollection.cs create mode 100644 ProjectTank/ProjectTank/FormBattleTankCollection.resx diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..3592ba2 --- /dev/null +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,115 @@ +using ProjectTank.Drawning; +using ProjectTank.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию автомобилей +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 100; + + /// + /// Ширина окна + /// + protected readonly int _pictureWidth; + + /// + /// Высота окна + /// + protected readonly int _pictureHeight; + + /// + /// Коллекция автомобилей + /// + protected ICollectionGenericObjects? _collection = null; + + /// + /// Вычисление максимального количества элементов, который можно разместить в окне + /// + private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + + /// + /// Конструктор + /// + /// Ширина окна + /// Высота окна + /// Коллекция автомобилей + public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + /// + /// Перегрузка оператора сложения для класса + /// + /// Компания + /// Добавляемый объект + /// + public static int operator +(AbstractCompany company, DrawningTank car) + { + return company?._collection.Insert(car)??-1; + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningTank? operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position)??null; + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningTank? GetRandomObject() + { + Random rnd = new(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + + /// + /// Вывод всей коллекции + /// + /// + public Bitmap? Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackgound(graphics); + + SetObjectsPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { + DrawningTank? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/TankSharingServise.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/TankSharingServise.cs new file mode 100644 index 0000000..548176d --- /dev/null +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/TankSharingServise.cs @@ -0,0 +1,62 @@ + + + +using ProjectTank.Drawning; + +namespace ProjectTank.CollectionGenericObjects +{ + public class TankSharingServise : AbstractCompany + { + private int maxCountX; + private int maxCountY; + private int offsetX = 30; + public TankSharingServise(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight,collection) + { + + } + protected override void DrawBackgound(Graphics g) + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + Pen pen = new(Color.Black, 2); + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5 + _placeSizeWidth - 45, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5, j * _placeSizeHeight - _placeSizeHeight); + } + } + } + + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int TankWidth = 0; + int TankHeight = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (_collection?.Get(i) != null) + { + _collection.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i)?.SetPosition(_placeSizeWidth * TankWidth + 20, TankHeight * _placeSizeHeight+5); + } + + if (TankWidth < width - 1) + TankWidth++; + else + { + TankWidth = 0; + TankHeight++; + } + if (TankHeight > height) + { + return; + } + } + } + } +} diff --git a/ProjectTank/ProjectTank/FormBattleTank.cs b/ProjectTank/ProjectTank/FormBattleTank.cs index be2a6aa..75e9402 100644 --- a/ProjectTank/ProjectTank/FormBattleTank.cs +++ b/ProjectTank/ProjectTank/FormBattleTank.cs @@ -18,6 +18,18 @@ namespace ProjectTank /// Стратегия перемещения /// private AbstractStrategy? _strategy; + + public DrawningTank SetTank + { + set + { + _drawningTank = value; + _drawningTank.SetPictureSize(pictureBoxBattleTank.Width, pictureBoxBattleTank.Height); + СomboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } /// /// Конструктор формы /// diff --git a/ProjectTank/ProjectTank/FormBattleTankCollection.Designer.cs b/ProjectTank/ProjectTank/FormBattleTankCollection.Designer.cs new file mode 100644 index 0000000..72e3bdf --- /dev/null +++ b/ProjectTank/ProjectTank/FormBattleTankCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace ProjectTank +{ + partial class FormBattleTankCollection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBoxTools = new GroupBox(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemoveTank = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddBattleTank = new Button(); + buttonAddTank = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemoveTank); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddBattleTank); + groupBoxTools.Controls.Add(buttonAddTank); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(613, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(187, 450); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 379); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(175, 35); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 302); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(175, 35); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveTank + // + buttonRemoveTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveTank.Location = new Point(6, 241); + buttonRemoveTank.Name = "buttonRemoveTank"; + buttonRemoveTank.Size = new Size(175, 35); + buttonRemoveTank.TabIndex = 4; + buttonRemoveTank.Text = "Удаление танка"; + buttonRemoveTank.UseVisualStyleBackColor = true; + buttonRemoveTank.Click += buttonRemoveTank_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(6, 212); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(169, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddBattleTank + // + buttonAddBattleTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBattleTank.Location = new Point(6, 133); + buttonAddBattleTank.Name = "buttonAddBattleTank"; + buttonAddBattleTank.Size = new Size(175, 35); + buttonAddBattleTank.TabIndex = 2; + buttonAddBattleTank.Text = "Добавление боевого танка"; + buttonAddBattleTank.UseVisualStyleBackColor = true; + buttonAddBattleTank.Click += ButtonAddBattleTank_Click; + // + // buttonAddTank + // + buttonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddTank.Location = new Point(6, 92); + buttonAddTank.Name = "buttonAddTank"; + buttonAddTank.Size = new Size(175, 35); + buttonAddTank.TabIndex = 1; + buttonAddTank.Text = "Добавление танка"; + buttonAddTank.UseVisualStyleBackColor = true; + buttonAddTank.Click += ButtonAddTank_Click; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(6, 25); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(175, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(613, 450); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormBattleTankCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormBattleTankCollection"; + Text = "Коллекция танков"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddBattleTank; + private Button buttonAddTank; + private MaskedTextBox maskedTextBox; + private PictureBox pictureBox; + private Button buttonRemoveTank; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/ProjectTank/ProjectTank/FormBattleTankCollection.cs b/ProjectTank/ProjectTank/FormBattleTankCollection.cs new file mode 100644 index 0000000..658dc66 --- /dev/null +++ b/ProjectTank/ProjectTank/FormBattleTankCollection.cs @@ -0,0 +1,150 @@ +using ProjectTank.CollectionGenericObjects; +using ProjectTank.Drawning; + +namespace ProjectTank +{ + /// + /// + /// + public partial class FormBattleTankCollection : Form + { + /// + /// + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormBattleTankCollection() + { + InitializeComponent(); + } + + /// + /// + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new TankSharingServise(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создоваемого объекта + private void CreateObject(string type) + { + if (_company == null) return; + + Random random = new(); + DrawningTank drawningTank; + switch (type) + { + case nameof(DrawningTank): + drawningTank = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random)); + break; + case nameof(DrawningBattleTank): + bool randomTrack = Convert.ToBoolean(random.Next(0, 2)); + drawningTank = new DrawningBattleTank(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), randomTrack, (randomTrack ? Convert.ToBoolean(random.Next(0, 2)) : true)); + break; + default: + return; + } + + if (_company + drawningTank != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + /// + /// Получение цвета + /// + /// Генератор случайных чесел + /// + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new ColorDialog(); + + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + return color; + } + + private void ButtonAddTank_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningTank)); + } + + private void ButtonAddBattleTank_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningBattleTank)); + } + + private void buttonRemoveTank_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return; + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; + + int position = Convert.ToInt32(maskedTextBox.Text); + + if (_company - position != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) return; + + DrawningTank? tank = null; + int coutner = 100; + + while (tank == null) + { + tank = _company.GetRandomObject(); + coutner--; + if (coutner <= 0) break; + } + + if (tank == null) return; + + FormBattleTank form = new() + { + SetTank = tank + }; + form.ShowDialog(); + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) return; + pictureBox.Image = _company.Show(); + } + } +} diff --git a/ProjectTank/ProjectTank/FormBattleTankCollection.resx b/ProjectTank/ProjectTank/FormBattleTankCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectTank/ProjectTank/FormBattleTankCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectTank/ProjectTank/Program.cs b/ProjectTank/ProjectTank/Program.cs index fc0d74f..4b02a00 100644 --- a/ProjectTank/ProjectTank/Program.cs +++ b/ProjectTank/ProjectTank/Program.cs @@ -11,7 +11,7 @@ namespace ProjectTank // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormBattleTank()); + Application.Run(new FormBattleTankCollection()); } } } \ No newline at end of file -- 2.25.1 From 9c40d1a8e219a5e730695f8eb88cc2000ad4c1be Mon Sep 17 00:00:00 2001 From: Garifullin-Farid <95081032+Garifullin-Farid@users.noreply.github.com> Date: Fri, 5 Apr 2024 23:33:13 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionGenericObjects/AbstractCompany.cs | 4 ++-- .../{TankSharingServise.cs => TankBase.cs} | 16 +++++----------- ProjectTank/ProjectTank/FormBattleTank.cs | 1 - .../ProjectTank/FormBattleTankCollection.cs | 4 ++-- 4 files changed, 9 insertions(+), 16 deletions(-) rename ProjectTank/ProjectTank/CollectionGenericObjects/{TankSharingServise.cs => TankBase.cs} (79%) diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs index 3592ba2..09e1d06 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs @@ -56,9 +56,9 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static int operator +(AbstractCompany company, DrawningTank car) + public static int operator +(AbstractCompany company, DrawningTank tank) { - return company?._collection.Insert(car)??-1; + return company?._collection.Insert(tank)??-1; } /// diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/TankSharingServise.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/TankBase.cs similarity index 79% rename from ProjectTank/ProjectTank/CollectionGenericObjects/TankSharingServise.cs rename to ProjectTank/ProjectTank/CollectionGenericObjects/TankBase.cs index 548176d..33919ad 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/TankSharingServise.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/TankBase.cs @@ -1,16 +1,10 @@ - - - -using ProjectTank.Drawning; +using ProjectTank.Drawning; namespace ProjectTank.CollectionGenericObjects { - public class TankSharingServise : AbstractCompany + public class TankBase : AbstractCompany { - private int maxCountX; - private int maxCountY; - private int offsetX = 30; - public TankSharingServise(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight,collection) + public TankBase(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) { } @@ -42,7 +36,7 @@ namespace ProjectTank.CollectionGenericObjects if (_collection?.Get(i) != null) { _collection.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); - _collection.Get(i)?.SetPosition(_placeSizeWidth * TankWidth + 20, TankHeight * _placeSizeHeight+5); + _collection.Get(i)?.SetPosition(_placeSizeWidth * TankWidth + 20, TankHeight * _placeSizeHeight + 5); } if (TankWidth < width - 1) @@ -52,7 +46,7 @@ namespace ProjectTank.CollectionGenericObjects TankWidth = 0; TankHeight++; } - if (TankHeight > height) + if (TankHeight > height -1) { return; } diff --git a/ProjectTank/ProjectTank/FormBattleTank.cs b/ProjectTank/ProjectTank/FormBattleTank.cs index 75e9402..2338bd4 100644 --- a/ProjectTank/ProjectTank/FormBattleTank.cs +++ b/ProjectTank/ProjectTank/FormBattleTank.cs @@ -1,5 +1,4 @@ using ProjectTank.Drawning; -using ProjectTank.Entities; using ProjectTank.MovementStrategy; namespace ProjectTank diff --git a/ProjectTank/ProjectTank/FormBattleTankCollection.cs b/ProjectTank/ProjectTank/FormBattleTankCollection.cs index 658dc66..96e3df3 100644 --- a/ProjectTank/ProjectTank/FormBattleTankCollection.cs +++ b/ProjectTank/ProjectTank/FormBattleTankCollection.cs @@ -31,7 +31,7 @@ namespace ProjectTank switch (comboBoxSelectorCompany.Text) { case "Хранилище": - _company = new TankSharingServise(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + _company = new TankBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); break; } } @@ -123,7 +123,7 @@ namespace ProjectTank if (_company == null) return; DrawningTank? tank = null; - int coutner = 100; + int coutner = 1; while (tank == null) { -- 2.25.1 From d59414bed400d3f7465a647033560525895c3d09 Mon Sep 17 00:00:00 2001 From: Garifullin-Farid <95081032+Garifullin-Farid@users.noreply.github.com> Date: Sat, 6 Apr 2024 14:14:10 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionGenericObjects/AbstractCompany.cs | 6 +++--- .../MassiveGenericObjects.cs | 13 ++----------- .../CollectionGenericObjects/TankBase.cs | 4 ++-- .../ProjectTank/Drawning/DrawningBattleTank.cs | 2 +- ProjectTank/ProjectTank/FormBattleTankCollection.cs | 8 ++++---- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs index 09e1d06..b8b8f2f 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs @@ -2,7 +2,7 @@ using ProjectTank.CollectionGenericObjects; /// -/// Абстракция компании, хранящий коллекцию автомобилей +/// Абстракция компании, хранящий Танковую базу /// public abstract class AbstractCompany { @@ -27,7 +27,7 @@ public abstract class AbstractCompany protected readonly int _pictureHeight; /// - /// Коллекция автомобилей + /// Танковая база /// protected ICollectionGenericObjects? _collection = null; @@ -41,7 +41,7 @@ public abstract class AbstractCompany /// /// Ширина окна /// Высота окна - /// Коллекция автомобилей + /// Танковая база public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) { _pictureWidth = picWidth; diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs index 4326cf4..f4fef06 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs @@ -35,17 +35,8 @@ public class MassiveGenericObjects : ICollectionGenericObjects public int Insert(T obj) { - // вставка в свободное место набора - for (int i = 0; i < Count; i++) - { - if (_collection[i] == null) - { - _collection[i] = obj; - return i; - } - } - - return -1; + // вставка в свободное место набора + return Insert(obj, 0); } public int Insert(T obj, int position) diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/TankBase.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/TankBase.cs index 33919ad..3840c02 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/TankBase.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/TankBase.cs @@ -13,7 +13,7 @@ namespace ProjectTank.CollectionGenericObjects int width = _pictureWidth / _placeSizeWidth; int height = _pictureHeight / _placeSizeHeight; Pen pen = new(Color.Black, 2); - for (int i = 0; i < width; i++) + for (int i = 0; i < width+1; i++) { for (int j = 0; j < height + 1; ++j) { @@ -39,7 +39,7 @@ namespace ProjectTank.CollectionGenericObjects _collection.Get(i)?.SetPosition(_placeSizeWidth * TankWidth + 20, TankHeight * _placeSizeHeight + 5); } - if (TankWidth < width - 1) + if (TankWidth < width) TankWidth++; else { diff --git a/ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs b/ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs index 289bdec..f090df9 100644 --- a/ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs +++ b/ProjectTank/ProjectTank/Drawning/DrawningBattleTank.cs @@ -1,4 +1,4 @@ -namespace ProjectTank.Drawning; +namespace ProjectTank.Drawning; /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// diff --git a/ProjectTank/ProjectTank/FormBattleTankCollection.cs b/ProjectTank/ProjectTank/FormBattleTankCollection.cs index 96e3df3..0457743 100644 --- a/ProjectTank/ProjectTank/FormBattleTankCollection.cs +++ b/ProjectTank/ProjectTank/FormBattleTankCollection.cs @@ -4,12 +4,12 @@ using ProjectTank.Drawning; namespace ProjectTank { /// - /// + /// Форма работы с компанией и её коллекцией /// public partial class FormBattleTankCollection : Form { /// - /// + /// Компания /// private AbstractCompany? _company = null; @@ -22,7 +22,7 @@ namespace ProjectTank } /// - /// + /// Выбор компании /// /// /// @@ -123,7 +123,7 @@ namespace ProjectTank if (_company == null) return; DrawningTank? tank = null; - int coutner = 1; + int coutner = 100; while (tank == null) { -- 2.25.1