From fc7f5298ad58c512d71a4917c8884c5e18b98e3f Mon Sep 17 00:00:00 2001 From: rozenkranzz Date: Mon, 10 Feb 2025 09:12:26 +0400 Subject: [PATCH] pre release --- .../ProjectLiner/FormLiner.Designer.cs | 48 ++--- ProjectLiner/ProjectLiner/FormLiner.cs | 51 ++---- .../FormShipCollection.Designer.cs | 167 ++++++++++++++++++ .../ProjectLiner/FormShipCollection.cs | 136 ++++++++++++++ .../ProjectLiner/FormShipCollection.resx | 120 +++++++++++++ .../AbstractCompany.cs | 51 ++++++ .../GenericObjectsCollection.cs | 89 ++++++++++ .../IGenericObjectsCollection.cs | 12 ++ .../GenericObjectsCollection/LandingStage.cs | 76 ++++++++ ProjectLiner/ProjectLiner/Program.cs | 2 +- 10 files changed, 675 insertions(+), 77 deletions(-) create mode 100644 ProjectLiner/ProjectLiner/FormShipCollection.Designer.cs create mode 100644 ProjectLiner/ProjectLiner/FormShipCollection.cs create mode 100644 ProjectLiner/ProjectLiner/FormShipCollection.resx create mode 100644 ProjectLiner/ProjectLiner/GenericObjectsCollection/AbstractCompany.cs create mode 100644 ProjectLiner/ProjectLiner/GenericObjectsCollection/GenericObjectsCollection.cs create mode 100644 ProjectLiner/ProjectLiner/GenericObjectsCollection/IGenericObjectsCollection.cs create mode 100644 ProjectLiner/ProjectLiner/GenericObjectsCollection/LandingStage.cs diff --git a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs index 2a06e5c..94bd16f 100644 --- a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs +++ b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs @@ -30,12 +30,10 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLiner)); pictureBoxLiner = new PictureBox(); - buttonCreateFullLiner = new Button(); buttonMoveLeft = new Button(); buttonMoveUp = new Button(); buttonMoveDown = new Button(); buttonMoveRight = new Button(); - buttonCreateBaseLiner = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit(); @@ -47,28 +45,16 @@ pictureBoxLiner.Location = new Point(0, 0); pictureBoxLiner.Margin = new Padding(3, 2, 3, 2); pictureBoxLiner.Name = "pictureBoxLiner"; - pictureBoxLiner.Size = new Size(995, 620); + pictureBoxLiner.Size = new Size(981, 637); pictureBoxLiner.TabIndex = 0; pictureBoxLiner.TabStop = false; // - // buttonCreateFullLiner - // - buttonCreateFullLiner.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateFullLiner.Location = new Point(10, 589); - buttonCreateFullLiner.Margin = new Padding(3, 2, 3, 2); - buttonCreateFullLiner.Name = "buttonCreateFullLiner"; - buttonCreateFullLiner.Size = new Size(114, 22); - buttonCreateFullLiner.TabIndex = 1; - buttonCreateFullLiner.Text = "Create Full Liner"; - buttonCreateFullLiner.UseVisualStyleBackColor = true; - buttonCreateFullLiner.Click += ButtonCreateLiner_Click; - // // buttonMoveLeft // buttonMoveLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonMoveLeft.BackgroundImage = Properties.Resources.icons8_arrow_left_60; buttonMoveLeft.BackgroundImageLayout = ImageLayout.Stretch; - buttonMoveLeft.Location = new Point(889, 585); + buttonMoveLeft.Location = new Point(875, 602); buttonMoveLeft.Margin = new Padding(3, 2, 3, 2); buttonMoveLeft.Name = "buttonMoveLeft"; buttonMoveLeft.Size = new Size(31, 26); @@ -81,7 +67,7 @@ buttonMoveUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonMoveUp.BackgroundImage = Properties.Resources.icons8_arrow_up_60; buttonMoveUp.BackgroundImageLayout = ImageLayout.Stretch; - buttonMoveUp.Location = new Point(925, 554); + buttonMoveUp.Location = new Point(911, 571); buttonMoveUp.Margin = new Padding(3, 2, 3, 2); buttonMoveUp.Name = "buttonMoveUp"; buttonMoveUp.Size = new Size(31, 26); @@ -94,7 +80,7 @@ buttonMoveDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonMoveDown.BackgroundImage = Properties.Resources.icons8_arrow_down_60; buttonMoveDown.BackgroundImageLayout = ImageLayout.Stretch; - buttonMoveDown.Location = new Point(925, 585); + buttonMoveDown.Location = new Point(911, 602); buttonMoveDown.Margin = new Padding(3, 2, 3, 2); buttonMoveDown.Name = "buttonMoveDown"; buttonMoveDown.Size = new Size(31, 26); @@ -107,7 +93,7 @@ buttonMoveRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonMoveRight.BackgroundImage = (Image)resources.GetObject("buttonMoveRight.BackgroundImage"); buttonMoveRight.BackgroundImageLayout = ImageLayout.Stretch; - buttonMoveRight.Location = new Point(961, 585); + buttonMoveRight.Location = new Point(947, 602); buttonMoveRight.Margin = new Padding(3, 2, 3, 2); buttonMoveRight.Name = "buttonMoveRight"; buttonMoveRight.Size = new Size(31, 26); @@ -115,31 +101,21 @@ buttonMoveRight.UseVisualStyleBackColor = true; buttonMoveRight.Click += ButtonMove_Click; // - // buttonCreateBaseLiner - // - buttonCreateBaseLiner.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateBaseLiner.Location = new Point(130, 589); - buttonCreateBaseLiner.Margin = new Padding(3, 2, 3, 2); - buttonCreateBaseLiner.Name = "buttonCreateBaseLiner"; - buttonCreateBaseLiner.Size = new Size(114, 22); - buttonCreateBaseLiner.TabIndex = 6; - buttonCreateBaseLiner.Text = "Create Base Liner"; - buttonCreateBaseLiner.UseVisualStyleBackColor = true; - buttonCreateBaseLiner.Click += buttonCreateBaseLiner_Click; - // // comboBoxStrategy // + comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "To Center", "To Border" }); - comboBoxStrategy.Location = new Point(862, 12); + comboBoxStrategy.Location = new Point(848, 12); comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(121, 23); comboBoxStrategy.TabIndex = 7; // // buttonStrategyStep // - buttonStrategyStep.Location = new Point(908, 41); + buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStrategyStep.Location = new Point(894, 41); buttonStrategyStep.Name = "buttonStrategyStep"; buttonStrategyStep.Size = new Size(75, 23); buttonStrategyStep.TabIndex = 8; @@ -151,15 +127,13 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(995, 620); + ClientSize = new Size(981, 637); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateBaseLiner); Controls.Add(buttonMoveRight); Controls.Add(buttonMoveDown); Controls.Add(buttonMoveUp); Controls.Add(buttonMoveLeft); - Controls.Add(buttonCreateFullLiner); Controls.Add(pictureBoxLiner); Margin = new Padding(3, 2, 3, 2); Name = "FormLiner"; @@ -172,12 +146,10 @@ #endregion private PictureBox pictureBoxLiner; - private Button buttonCreateFullLiner; private Button buttonMoveLeft; private Button buttonMoveUp; private Button buttonMoveDown; private Button buttonMoveRight; - private Button buttonCreateBaseLiner; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectLiner/ProjectLiner/FormLiner.cs b/ProjectLiner/ProjectLiner/FormLiner.cs index d246d75..41bf8da 100644 --- a/ProjectLiner/ProjectLiner/FormLiner.cs +++ b/ProjectLiner/ProjectLiner/FormLiner.cs @@ -14,7 +14,19 @@ namespace ProjectLiner { InitializeComponent(); _strategy = null; - comboBoxStrategy.Enabled = false; + } + + public DrawingBaseLiner SetLiner + { + set + { + _drawingLiner = value; + _drawingLiner.SetPictureSize(pictureBoxLiner.Width, + pictureBoxLiner.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } } private void Draw() @@ -29,43 +41,6 @@ namespace ProjectLiner pictureBoxLiner.Image = bitmap; } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawingLiner): - _drawingLiner = new DrawingLiner(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), - Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), - LinerEntityType.Cargo, random.Next(1000, 10000), random.Next(10, 100), - random.Next(0, 2) == 1, random.Next(0, 2) == 1); - break; - case nameof(DrawingBaseLiner): - _drawingLiner = new DrawingBaseLiner(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255))); - break; - default: - return; - } - _drawingLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height); - _drawingLiner.SetPosition(random.Next(0, pictureBoxLiner.Width), random.Next(0, pictureBoxLiner.Height)); - - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - private void ButtonCreateLiner_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingLiner)); - } - - private void buttonCreateBaseLiner_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingBaseLiner)); - } - private void ButtonMove_Click(object sender, EventArgs e) { if (_drawingLiner == null) diff --git a/ProjectLiner/ProjectLiner/FormShipCollection.Designer.cs b/ProjectLiner/ProjectLiner/FormShipCollection.Designer.cs new file mode 100644 index 0000000..2b6cc55 --- /dev/null +++ b/ProjectLiner/ProjectLiner/FormShipCollection.Designer.cs @@ -0,0 +1,167 @@ +namespace ProjectLiner +{ + 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() + { + groupBoxTools = new GroupBox(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonSu = new Button(); + buttonRemoveObject = new Button(); + buttonAddShip = new Button(); + buttonAddLiner = new Button(); + comboBoxCompanySelector = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonSu); + groupBoxTools.Controls.Add(buttonRemoveObject); + groupBoxTools.Controls.Add(buttonAddShip); + groupBoxTools.Controls.Add(buttonAddLiner); + groupBoxTools.Controls.Add(comboBoxCompanySelector); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(901, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.RightToLeft = RightToLeft.No; + groupBoxTools.Size = new Size(200, 670); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Tools"; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(6, 291); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(182, 23); + maskedTextBoxPosition.TabIndex = 2; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Location = new Point(6, 543); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(182, 23); + buttonRefresh.TabIndex = 1; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonSu + // + buttonSu.Location = new Point(6, 422); + buttonSu.Name = "buttonSu"; + buttonSu.Size = new Size(182, 23); + buttonSu.TabIndex = 1; + buttonSu.Text = "Submit for testing"; + buttonSu.UseVisualStyleBackColor = true; + buttonSu.Click += ButtonSubmitForTesting_Click; + // + // buttonRemoveObject + // + buttonRemoveObject.Location = new Point(6, 320); + buttonRemoveObject.Name = "buttonRemoveObject"; + buttonRemoveObject.Size = new Size(182, 23); + buttonRemoveObject.TabIndex = 1; + buttonRemoveObject.Text = "Remove Liner or Ship"; + buttonRemoveObject.UseVisualStyleBackColor = true; + buttonRemoveObject.Click += ButtonRemoveShip_Click; + // + // buttonAddShip + // + buttonAddShip.Location = new Point(6, 181); + buttonAddShip.Name = "buttonAddShip"; + buttonAddShip.Size = new Size(182, 23); + buttonAddShip.TabIndex = 1; + buttonAddShip.Text = "Add Ship"; + buttonAddShip.UseVisualStyleBackColor = true; + buttonAddShip.Click += ButtonAddShip_Click; + // + // buttonAddLiner + // + buttonAddLiner.Location = new Point(6, 152); + buttonAddLiner.Name = "buttonAddLiner"; + buttonAddLiner.Size = new Size(182, 23); + buttonAddLiner.TabIndex = 1; + buttonAddLiner.Text = "Add Liner"; + buttonAddLiner.UseVisualStyleBackColor = true; + buttonAddLiner.Click += ButtonAddLiner_Click; + // + // comboBoxCompanySelector + // + comboBoxCompanySelector.FormattingEnabled = true; + comboBoxCompanySelector.Items.AddRange(new object[] { "Landing Stage" }); + comboBoxCompanySelector.Location = new Point(6, 22); + comboBoxCompanySelector.Name = "comboBoxCompanySelector"; + comboBoxCompanySelector.Size = new Size(182, 23); + comboBoxCompanySelector.TabIndex = 0; + comboBoxCompanySelector.SelectedIndexChanged += ComboBoxCompanySelector_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(901, 670); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormShipCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1101, 670); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormShipCollection"; + Text = "Ship_Collection"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonRefresh; + private Button buttonSu; + private Button buttonRemoveObject; + private Button buttonAddShip; + private Button buttonAddLiner; + private ComboBox comboBoxCompanySelector; + private PictureBox pictureBox; + } +} \ No newline at end of file diff --git a/ProjectLiner/ProjectLiner/FormShipCollection.cs b/ProjectLiner/ProjectLiner/FormShipCollection.cs new file mode 100644 index 0000000..3b1dd14 --- /dev/null +++ b/ProjectLiner/ProjectLiner/FormShipCollection.cs @@ -0,0 +1,136 @@ +using ProjectLiner.CollectionGenericObjects; +using ProjectLiner.Drawnings; +using ProjectLiner.Entities; +using ProjectLiner.GenericObjectsCollection; + +namespace ProjectLiner; + +public partial class FormShipCollection : Form +{ + private AbstractCompany? _company = null; + public FormShipCollection() + { + InitializeComponent(); + + } + private void ComboBoxCompanySelector_SelectedIndexChanged(object sender, + EventArgs e) + { + switch (comboBoxCompanySelector.Text) + { + case "Landing Stage": + _company = new LandingStage(pictureBox.Width, + pictureBox.Height, new GenericObjectsCollection()); + break; + default: + MessageBox.Show("No matching case found"); + break; + } + } + private void ButtonAddLiner_Click(object sender, EventArgs e) => + CreateObject(nameof(DrawingBaseLiner)); + private void ButtonAddShip_Click(object sender, EventArgs e) => + CreateObject(nameof(DrawingLiner)); + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawingBaseLiner drawingLiner; + switch (type) + { + case nameof(DrawingBaseLiner): + drawingLiner = new DrawingBaseLiner(random.Next(100, 300), + random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawingLiner): + drawingLiner = new DrawingLiner(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random), GetColor(random), + LinerEntityType.Cargo, random.Next(1000, 10000), random.Next(10, 100), + random.Next(0, 2) == 1, random.Next(0, 2) == 1); + break; + default: + return; + } + if (_company + drawingLiner) + { + MessageBox.Show("Object was added"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Couldn't add object"); + } + } + 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(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + return color; + } + private void ButtonRemoveShip_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || + _company == null) + { + return; + } + if (MessageBox.Show("Remove object?", "Removing...", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos) + { + MessageBox.Show("Object was removed"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Couldn't remove object"); + } + } + private void ButtonSubmitForTesting_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + DrawingBaseLiner? liner = null; + int counter = 100; + while (liner == null) + { + liner = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + if (liner == null) + { + return; + } + FormLiner form = new() + { + SetLiner = liner + }; + form.ShowDialog(); + } + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } +} diff --git a/ProjectLiner/ProjectLiner/FormShipCollection.resx b/ProjectLiner/ProjectLiner/FormShipCollection.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectLiner/ProjectLiner/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/ProjectLiner/ProjectLiner/GenericObjectsCollection/AbstractCompany.cs b/ProjectLiner/ProjectLiner/GenericObjectsCollection/AbstractCompany.cs new file mode 100644 index 0000000..73e2f48 --- /dev/null +++ b/ProjectLiner/ProjectLiner/GenericObjectsCollection/AbstractCompany.cs @@ -0,0 +1,51 @@ +using ProjectLiner.Drawnings; + +namespace ProjectLiner.GenericObjectsCollection; + +public abstract class AbstractCompany +{ + protected readonly int _placeSizeWidth = 210; + protected readonly int _placeSizeHeight = 80; + protected readonly int _pictureWidth; + protected readonly int _pictureHeight; + protected IGenericObjectsCollection? _collection = null; + private int GetMaxCount => _pictureWidth * _pictureHeight / + (_placeSizeWidth * _placeSizeHeight); + public AbstractCompany(int picWidth, int picHeight, + IGenericObjectsCollection collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + public static bool operator +(AbstractCompany company, DrawingBaseLiner liner) + { + return company._collection?.Insert(liner) ?? false; + } + public static bool operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position) ?? false; + } + + public DrawingBaseLiner? 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) + { + DrawingBaseLiner? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + protected abstract void DrawBackgound(Graphics g); + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectLiner/ProjectLiner/GenericObjectsCollection/GenericObjectsCollection.cs b/ProjectLiner/ProjectLiner/GenericObjectsCollection/GenericObjectsCollection.cs new file mode 100644 index 0000000..1e61c5e --- /dev/null +++ b/ProjectLiner/ProjectLiner/GenericObjectsCollection/GenericObjectsCollection.cs @@ -0,0 +1,89 @@ +namespace ProjectLiner.GenericObjectsCollection; + +public class GenericObjectsCollection : IGenericObjectsCollection + where T : class +{ + private T?[] _collection; + public int Count => _collection.Length; + + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } + + public GenericObjectsCollection() + { + _collection = Array.Empty(); + } + public T? Get(int position) + { + if (position < 0 || position >= _collection.Length) + { + return null; + } + return _collection[position]; + } + public bool Insert(T obj) + { + for (int i = 0; i < _collection.Length; ++i) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + return false; + } + public bool Insert(T obj, int position) + { + if (_collection[position] == null) + { + _collection[position] = obj; + } + else + { + while (position++ < _collection.Length) + { + if (_collection[position] == null) + { + _collection[position] = obj; + return true; + } + } + + while (position-- > 0) + { + if (_collection[position] == null) + { + _collection[position] = obj; + return true; + } + } + } + return false; + } + public bool Remove(int position) + { + if (_collection[position] == null) + { + return false; + } + _collection[position] = null; + return true; + } + +} diff --git a/ProjectLiner/ProjectLiner/GenericObjectsCollection/IGenericObjectsCollection.cs b/ProjectLiner/ProjectLiner/GenericObjectsCollection/IGenericObjectsCollection.cs new file mode 100644 index 0000000..3b03c8d --- /dev/null +++ b/ProjectLiner/ProjectLiner/GenericObjectsCollection/IGenericObjectsCollection.cs @@ -0,0 +1,12 @@ +namespace ProjectLiner.GenericObjectsCollection; + +public interface IGenericObjectsCollection + 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/ProjectLiner/ProjectLiner/GenericObjectsCollection/LandingStage.cs b/ProjectLiner/ProjectLiner/GenericObjectsCollection/LandingStage.cs new file mode 100644 index 0000000..ccee65d --- /dev/null +++ b/ProjectLiner/ProjectLiner/GenericObjectsCollection/LandingStage.cs @@ -0,0 +1,76 @@ +using ProjectLiner.Drawnings; +using ProjectLiner.GenericObjectsCollection; + +namespace ProjectLiner.CollectionGenericObjects; + +public class LandingStage : AbstractCompany +{ + public LandingStage(int picWidth, int picHeight, + IGenericObjectsCollection collection) + : base(picWidth, picHeight, collection) + { + } + protected override void DrawBackgound(Graphics g) + { + int spacing = 20; + + int horizontalCount = _pictureWidth / _placeSizeWidth; + int verticalCount = _pictureHeight / _placeSizeHeight; + + Pen parkingBrush = new Pen(Color.Black, 3); + + for (int i = 0; i < horizontalCount; i++) + { + for (int j = 0; j < verticalCount; j++) + { + int x = i * (_placeSizeWidth); + int y = j * (_placeSizeHeight); + Point[] parkingPlace = { + new Point(x + _placeSizeWidth - spacing, y), + new Point(x, y), + new Point(x, y + _placeSizeHeight), + new Point(x + _placeSizeWidth - spacing, y + _placeSizeHeight), + new Point(x, y + _placeSizeHeight), + new Point(x, y), + }; + g.DrawPolygon(parkingBrush, parkingPlace); + } + } + } + protected override void SetObjectsPosition() + { + if (_collection == null) + { + return; + } + + int spacing = 10; + + int horizontalCount = _pictureWidth / _placeSizeWidth; + int verticalCount = _pictureHeight / _placeSizeHeight; + + int index = 0; + + for (int i = 0; i < horizontalCount; i++) + { + for (int j = verticalCount - 1; j >= 0; j--) + { + if (index >= _collection.Count) + { + return; + } + + DrawingBaseLiner? obj = _collection.Get(index); + if (obj != null) + { + obj.SetPictureSize(_pictureWidth, _pictureHeight); + int x = i * (_placeSizeWidth); + int y = j * (_placeSizeHeight); + obj.SetPosition(x + spacing, y + spacing); + } + + index++; + } + } + } +} diff --git a/ProjectLiner/ProjectLiner/Program.cs b/ProjectLiner/ProjectLiner/Program.cs index b3dc92e..a294868 100644 --- a/ProjectLiner/ProjectLiner/Program.cs +++ b/ProjectLiner/ProjectLiner/Program.cs @@ -11,7 +11,7 @@ namespace ProjectLiner // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormLiner()); + Application.Run(new FormShipCollection()); } } } \ No newline at end of file -- 2.25.1