From 438f6a4ef0f78148e822e1577f10a3e36d235837 Mon Sep 17 00:00:00 2001 From: "yu.shlyapin" Date: Mon, 10 Feb 2025 22:23:38 +0400 Subject: [PATCH] lab3 release --- .../AbstractCompany.cs | 52 ++++++ .../CollectionGenericObjects/DocksService.cs | 53 ++++++ .../ICollectionGenericObjects.cs | 12 ++ .../MassiveGenericObjects.cs | 64 +++++++ .../FormAircraftCarrier.Designer.cs | 45 +---- .../AircraftCarrier/FormAircraftCarrier.cs | 46 ++--- .../FormShipCollection.Designer.cs | 167 ++++++++++++++++++ .../AircraftCarrier/FormShipCollection.cs | 125 +++++++++++++ .../AircraftCarrier/FormShipCollection.resx | 120 +++++++++++++ .../MovementStategy/IMoveableObject.cs | 2 +- .../MovementStategy/ObjectParameters.cs | 2 +- AircraftCarrier/AircraftCarrier/Program.cs | 5 +- 12 files changed, 623 insertions(+), 70 deletions(-) create mode 100644 AircraftCarrier/AircraftCarrier/CollectionGenericObjects/AbstractCompany.cs create mode 100644 AircraftCarrier/AircraftCarrier/CollectionGenericObjects/DocksService.cs create mode 100644 AircraftCarrier/AircraftCarrier/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 AircraftCarrier/AircraftCarrier/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormShipCollection.Designer.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormShipCollection.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormShipCollection.resx diff --git a/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/AbstractCompany.cs b/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..e37c981 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,52 @@ +using AircraftCarrier.Drawing; + +namespace AircraftCarrier.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + protected const int _placeSizeWidth = 300; + protected const int _placeSizeHeight = 150; + protected readonly int _pictureWidth; + protected readonly int _pictureHeight; + private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight); + protected ICollectionGenericObjects? _collection = null; + public AbstractCompany(int pictureWidth, int pictureHeight, ICollectionGenericObjects collection) { + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + public static bool operator +(AbstractCompany company, DrawingSimpleAircraftCarrier aircraftCarrier) + { + return company._collection?.Insert(aircraftCarrier) ?? false; + } + + public static bool operator -(AbstractCompany company, int pos) + { + return company._collection?.Remove(pos) ?? false; + } + + public DrawingSimpleAircraftCarrier? GetRandom() + { + Random random = new Random(); + return _collection?.Get(random.Next(GetMaxCount)); + } + + public Bitmap? Show() + { + Bitmap bitmap = new Bitmap(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackground(graphics); + SetObjectPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + DrawingSimpleAircraftCarrier? obj = _collection?.Get(i); + obj?.DrawAircraftCarrier(graphics); + } + return bitmap; + } + + protected abstract void DrawBackground(Graphics g); + protected abstract void SetObjectPosition(); +} diff --git a/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/DocksService.cs b/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/DocksService.cs new file mode 100644 index 0000000..e0cb85a --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/DocksService.cs @@ -0,0 +1,53 @@ + +using AircraftCarrier.Drawing; + +namespace AircraftCarrier.CollectionGenericObjects; + +public class DocksService : AbstractCompany +{ + public DocksService( + int pictureWidth, + int pictureHeight, + ICollectionGenericObjects collection + ) : + base(pictureWidth, pictureHeight, collection) + { + } + + protected override void DrawBackground(Graphics g) + { + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + { + Point[] p = { + new Point(i*_placeSizeWidth+250,j*_placeSizeHeight), + new Point(i*_placeSizeWidth,j*_placeSizeHeight), + new Point(i*_placeSizeWidth,j*_placeSizeHeight+_placeSizeHeight), + new Point(i*_placeSizeWidth+250,j*_placeSizeHeight+_placeSizeHeight), + }; + Pen pen = new Pen(Color.Black,5); + g.DrawLines(pen, p); + } + } + } + + protected override void SetObjectPosition() + { + int maxXPositionCount = _pictureWidth / _placeSizeWidth; + int maxYPositionCount = _pictureHeight / _placeSizeHeight; + int xpos = 0; + int ypos = maxYPositionCount; + for (int i = 0; i < _collection?.Count; i++) + { + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(xpos * _placeSizeWidth + 10, (ypos-1) * _placeSizeHeight + 10); + xpos++; + if (xpos >= maxXPositionCount) + { + xpos = 0; + ypos--; + } + } + } +} diff --git a/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/ICollectionGenericObjects.cs b/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..0e835ba --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,12 @@ +namespace AircraftCarrier.CollectionGenericObjects; + +public interface ICollectionGenericObjects + where T : class +{ + int Count { get; } + int SetMaxCount { set; } + bool Insert(T obj); + bool Insert(T obj, int position); + bool Remove(int position); + T? Get(int position); +} diff --git a/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/MassiveGenericObjects.cs b/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..7fdeecf --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,64 @@ +namespace AircraftCarrier.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(); + } + + private bool _checkAndInsert(T obj, int pos) + { + if (_collection[pos] == null) + { + _collection[pos] = obj; + return true; + } + return false; + } + + private bool _checkRange(int pos) => pos >= 0 && pos < Count; + + public T? Get(int position) + { + if (!_checkRange(position)) return null; + return _collection[position]; + } + + public bool Insert(T obj) + { + for (int i = 0; i < Count; i++) + { + if (_checkAndInsert(obj,i)) return true; + } + return false; + } + + public bool Insert(T obj, int position) + { + if (!_checkRange(position)) return false; + if (_checkAndInsert(obj, position)) return true; + for (int i = position + 1; i < Count; i++) + { + if (_checkAndInsert(obj, i)) return true; + } + for (int i = 0; i < position; i++) + { + if (_checkAndInsert(obj, i)) return true; + } + return false; + } + + public bool Remove(int position) + { + if (!_checkRange(position) || _collection[position] == null) return false; + _collection[position] = null; + return true; + } +} diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs index f426a2b..aa23e6e 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxAircraftCarrier = new PictureBox(); - buttonCreate = new Button(); buttonLeft = new Button(); buttonDown = new Button(); buttonRight = new Button(); buttonUp = new Button(); - buttonCreateSimple = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategy = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).BeginInit(); @@ -46,27 +44,16 @@ pictureBoxAircraftCarrier.Dock = DockStyle.Fill; pictureBoxAircraftCarrier.Location = new Point(0, 0); pictureBoxAircraftCarrier.Name = "pictureBoxAircraftCarrier"; - pictureBoxAircraftCarrier.Size = new Size(800, 438); + pictureBoxAircraftCarrier.Size = new Size(1128, 617); pictureBoxAircraftCarrier.TabIndex = 0; pictureBoxAircraftCarrier.TabStop = false; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(20, 389); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(94, 29); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.left_arrow; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; - buttonLeft.Location = new Point(677, 386); + buttonLeft.Location = new Point(1005, 565); buttonLeft.Margin = new Padding(0); buttonLeft.Name = "buttonLeft"; buttonLeft.Size = new Size(35, 35); @@ -79,7 +66,7 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.down_arrow; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; - buttonDown.Location = new Point(710, 386); + buttonDown.Location = new Point(1038, 565); buttonDown.Margin = new Padding(0); buttonDown.Name = "buttonDown"; buttonDown.Size = new Size(35, 35); @@ -92,7 +79,7 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.right_arrow; buttonRight.BackgroundImageLayout = ImageLayout.Stretch; - buttonRight.Location = new Point(743, 386); + buttonRight.Location = new Point(1071, 565); buttonRight.Margin = new Padding(0); buttonRight.Name = "buttonRight"; buttonRight.Size = new Size(35, 35); @@ -105,7 +92,7 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.up_arrow; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; - buttonUp.Location = new Point(710, 353); + buttonUp.Location = new Point(1038, 532); buttonUp.Margin = new Padding(0); buttonUp.Name = "buttonUp"; buttonUp.Size = new Size(35, 35); @@ -113,24 +100,14 @@ buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // - // buttonCreateSimple - // - buttonCreateSimple.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateSimple.Location = new Point(120, 389); - buttonCreateSimple.Name = "buttonCreateSimple"; - buttonCreateSimple.Size = new Size(128, 29); - buttonCreateSimple.TabIndex = 6; - buttonCreateSimple.Text = "Создать контур"; - buttonCreateSimple.UseVisualStyleBackColor = true; - buttonCreateSimple.Click += buttonCreateSimple_Click; - // // comboBoxStrategy // comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; + comboBoxStrategy.Cursor = Cursors.SizeNESW; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к углу" }); - comboBoxStrategy.Location = new Point(637, 12); + comboBoxStrategy.Location = new Point(965, 12); comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(151, 28); comboBoxStrategy.TabIndex = 7; @@ -138,7 +115,7 @@ // buttonStrategy // buttonStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonStrategy.Location = new Point(694, 46); + buttonStrategy.Location = new Point(1022, 46); buttonStrategy.Name = "buttonStrategy"; buttonStrategy.Size = new Size(94, 29); buttonStrategy.TabIndex = 8; @@ -150,15 +127,13 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 438); + ClientSize = new Size(1128, 617); Controls.Add(buttonStrategy); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateSimple); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxAircraftCarrier); KeyPreview = true; Name = "FormAircraftCarrier"; @@ -171,12 +146,10 @@ #endregion private PictureBox pictureBoxAircraftCarrier; - private Button buttonCreate; private Button buttonLeft; private Button buttonDown; private Button buttonRight; private Button buttonUp; - private Button buttonCreateSimple; private ComboBox comboBoxStrategy; private Button buttonStrategy; } diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs index 9991b5b..4f8e2af 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs @@ -10,6 +10,21 @@ public partial class FormAircraftCarrier : Form private DrawingSimpleAircraftCarrier? _drawingAircraftCarrier; private AbstractStrategy? _strategy; + public DrawingSimpleAircraftCarrier setCar + { + set + { + _drawingAircraftCarrier = value; + _drawingAircraftCarrier.SetPictureSize( + pictureBoxAircraftCarrier.Width, + pictureBoxAircraftCarrier.Height + ); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + public FormAircraftCarrier() { InitializeComponent(); @@ -25,37 +40,6 @@ public partial class FormAircraftCarrier : Form pictureBoxAircraftCarrier.Image = bmp; } - private void CreateDrawingAircraftCarrier(string name) - { - Random random = new(); - switch (name) - { - case nameof(DrawingAircraftCarrier): - _drawingAircraftCarrier = new DrawingAircraftCarrier(random.Next(100, 200), random.Next(1000, 2000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - case nameof(DrawingSimpleAircraftCarrier): - _drawingAircraftCarrier = new DrawingSimpleAircraftCarrier(random.Next(100, 200), random.Next(1000, 2000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - break; - default: - return; - } - - _drawingAircraftCarrier.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height); - _drawingAircraftCarrier.SetPosition(random.Next(10, 50), random.Next(10, 50)); - - Draw(); - - _strategy = null; - comboBoxStrategy.Enabled = true; - } - - private void ButtonCreate_Click(object sender, EventArgs e) => CreateDrawingAircraftCarrier(nameof(DrawingAircraftCarrier)); - - private void buttonCreateSimple_Click(object sender, EventArgs e) => CreateDrawingAircraftCarrier(nameof(DrawingSimpleAircraftCarrier)); - private void ButtonMove_Click(object sender, EventArgs e) { if (_drawingAircraftCarrier == null) return; diff --git a/AircraftCarrier/AircraftCarrier/FormShipCollection.Designer.cs b/AircraftCarrier/AircraftCarrier/FormShipCollection.Designer.cs new file mode 100644 index 0000000..2aca0b2 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormShipCollection.Designer.cs @@ -0,0 +1,167 @@ +namespace AircraftCarrier.CollectionGenericObjects +{ + partial class FormShipCollection + { + /// + /// 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() + { + groupBox1 = new GroupBox(); + TextBoxIdAircraft = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonTest = new Button(); + buttonDeleteAircraft = new Button(); + buttonCreateAircraft = new Button(); + buttonCreateSimpleAircraft = new Button(); + comboBoxStorage = new ComboBox(); + pictureBox = new PictureBox(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(TextBoxIdAircraft); + groupBox1.Controls.Add(buttonRefresh); + groupBox1.Controls.Add(buttonTest); + groupBox1.Controls.Add(buttonDeleteAircraft); + groupBox1.Controls.Add(buttonCreateAircraft); + groupBox1.Controls.Add(buttonCreateSimpleAircraft); + groupBox1.Controls.Add(comboBoxStorage); + groupBox1.Dock = DockStyle.Right; + groupBox1.Location = new Point(835, 0); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(250, 638); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Инструменты"; + // + // TextBoxIdAircraft + // + TextBoxIdAircraft.Location = new Point(15, 221); + TextBoxIdAircraft.Mask = "00"; + TextBoxIdAircraft.Name = "TextBoxIdAircraft"; + TextBoxIdAircraft.Size = new Size(224, 27); + TextBoxIdAircraft.TabIndex = 6; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(14, 397); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(224, 48); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonTest + // + buttonTest.Location = new Point(15, 343); + buttonTest.Name = "buttonTest"; + buttonTest.Size = new Size(224, 48); + buttonTest.TabIndex = 4; + buttonTest.Text = "Тесты"; + buttonTest.UseVisualStyleBackColor = true; + buttonTest.Click += buttonTest_Click; + // + // buttonDeleteAircraft + // + buttonDeleteAircraft.Location = new Point(15, 258); + buttonDeleteAircraft.Name = "buttonDeleteAircraft"; + buttonDeleteAircraft.Size = new Size(224, 48); + buttonDeleteAircraft.TabIndex = 3; + buttonDeleteAircraft.Text = "Удалить Авианосец"; + buttonDeleteAircraft.UseVisualStyleBackColor = true; + buttonDeleteAircraft.Click += buttonDeleteAircraft_Click; + // + // buttonCreateAircraft + // + buttonCreateAircraft.Location = new Point(14, 139); + buttonCreateAircraft.Name = "buttonCreateAircraft"; + buttonCreateAircraft.Size = new Size(224, 48); + buttonCreateAircraft.TabIndex = 2; + buttonCreateAircraft.Text = "Создать супер Авианосец"; + buttonCreateAircraft.UseVisualStyleBackColor = true; + buttonCreateAircraft.Click += buttonCreateAircraft_Click; + // + // buttonCreateSimpleAircraft + // + buttonCreateSimpleAircraft.Location = new Point(15, 85); + buttonCreateSimpleAircraft.Name = "buttonCreateSimpleAircraft"; + buttonCreateSimpleAircraft.Size = new Size(224, 48); + buttonCreateSimpleAircraft.TabIndex = 1; + buttonCreateSimpleAircraft.Text = "Создать Авианосец"; + buttonCreateSimpleAircraft.UseVisualStyleBackColor = true; + buttonCreateSimpleAircraft.Click += buttonCreateSimpleAircraft_Click; + // + // comboBoxStorage + // + comboBoxStorage.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxStorage.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStorage.FormattingEnabled = true; + comboBoxStorage.Items.AddRange(new object[] { "Хранилище" }); + comboBoxStorage.Location = new Point(15, 30); + comboBoxStorage.Name = "comboBoxStorage"; + comboBoxStorage.Size = new Size(224, 28); + comboBoxStorage.TabIndex = 0; + comboBoxStorage.SelectedIndexChanged += comboBoxStorage_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(835, 638); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormShipCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1085, 638); + Controls.Add(pictureBox); + Controls.Add(groupBox1); + Name = "FormShipCollection"; + Text = "FormShipCollection"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private PictureBox pictureBox; + private ComboBox comboBoxStorage; + private MaskedTextBox TextBoxIdAircraft; + private Button buttonRefresh; + private Button buttonTest; + private Button buttonDeleteAircraft; + private Button buttonCreateAircraft; + private Button buttonCreateSimpleAircraft; + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormShipCollection.cs b/AircraftCarrier/AircraftCarrier/FormShipCollection.cs new file mode 100644 index 0000000..93ca486 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormShipCollection.cs @@ -0,0 +1,125 @@ +using AircraftCarrier.Drawing; + +namespace AircraftCarrier.CollectionGenericObjects; + +public partial class FormShipCollection : Form +{ + private AbstractCompany? _company = null; + + public FormShipCollection() + { + InitializeComponent(); + } + + private void comboBoxStorage_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxStorage.Text) + { + case "Хранилище": + _company = new DocksService( + pictureBox.Width, + pictureBox.Height, + new MassiveGenericObjects() + ); + break; + } + _company.Show(); + } + + private static Color GetColor(Random random) + { + Color c = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new ColorDialog(); + if (dialog.ShowDialog() == DialogResult.OK) + { + c = dialog.Color; + } + return c; + } + + private void CreateAircraftCarrier(string name) + { + if (_company == null) return; + Random random = new(); + DrawingSimpleAircraftCarrier _drawingAircraftCarrier; + switch (name) + { + case nameof(DrawingAircraftCarrier): + _drawingAircraftCarrier = new DrawingAircraftCarrier(random.Next(100, 200), random.Next(1000, 2000), + GetColor(random), + GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + case nameof(DrawingSimpleAircraftCarrier): + _drawingAircraftCarrier = new DrawingSimpleAircraftCarrier( + random.Next(100, 200), + random.Next(1000, 2000), + GetColor(random)); + break; + default: + return; + } + if (_company + _drawingAircraftCarrier) + { + MessageBox.Show("элемент добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("элемент не добавлен"); + } + } + + private void buttonCreateSimpleAircraft_Click(object sender, EventArgs e) => CreateAircraftCarrier(nameof(DrawingSimpleAircraftCarrier)); + + private void buttonCreateAircraft_Click(object sender, EventArgs e) => CreateAircraftCarrier(nameof(DrawingAircraftCarrier)); + + private void buttonDeleteAircraft_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(TextBoxIdAircraft.Text) || _company == null) return; + + if ( + MessageBox.Show( + "Удалить объект " + TextBoxIdAircraft.Text, + "Удаление", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question) == DialogResult.No + ) return; + + int pos = Convert.ToInt32(TextBoxIdAircraft.Text); + if (_company - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не был удален"); + } + } + + private void buttonTest_Click(object sender, EventArgs e) + { + if (_company == null) return; + DrawingSimpleAircraftCarrier? aircraft = null; + int counter = 100; + while (aircraft == null) + { + aircraft = _company.GetRandom(); + counter--; + if (counter <= 0) break; + } + + if (aircraft == null) return; + + FormAircraftCarrier form = new(); + form.setCar = aircraft; + form.ShowDialog(); + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) return; + pictureBox.Image = _company.Show(); + } +} diff --git a/AircraftCarrier/AircraftCarrier/FormShipCollection.resx b/AircraftCarrier/AircraftCarrier/FormShipCollection.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormShipCollection.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/AircraftCarrier/AircraftCarrier/MovementStategy/IMoveableObject.cs b/AircraftCarrier/AircraftCarrier/MovementStategy/IMoveableObject.cs index d456ddb..bc6fa56 100644 --- a/AircraftCarrier/AircraftCarrier/MovementStategy/IMoveableObject.cs +++ b/AircraftCarrier/AircraftCarrier/MovementStategy/IMoveableObject.cs @@ -5,4 +5,4 @@ public interface IMoveableObject ObjectParameters? GetObjectPosition { get; } int GetStep { get; } bool TryMoveObject(MovementDirection direction); -} +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/MovementStategy/ObjectParameters.cs b/AircraftCarrier/AircraftCarrier/MovementStategy/ObjectParameters.cs index c5a1ecc..e3850c6 100644 --- a/AircraftCarrier/AircraftCarrier/MovementStategy/ObjectParameters.cs +++ b/AircraftCarrier/AircraftCarrier/MovementStategy/ObjectParameters.cs @@ -20,4 +20,4 @@ public class ObjectParameters _width = width; _height = height; } -} +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/Program.cs b/AircraftCarrier/AircraftCarrier/Program.cs index f373679..3d06fee 100644 --- a/AircraftCarrier/AircraftCarrier/Program.cs +++ b/AircraftCarrier/AircraftCarrier/Program.cs @@ -1,3 +1,5 @@ +using AircraftCarrier.CollectionGenericObjects; + namespace AircraftCarrier { internal static class Program @@ -11,7 +13,8 @@ namespace AircraftCarrier // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAircraftCarrier()); + //Application.Run(new FormAircraftCarrier()); + Application.Run(new FormShipCollection()); } } } \ No newline at end of file