pre release

This commit is contained in:
rozenkranzz 2025-02-10 09:12:26 +04:00
parent 602604faba
commit fc7f5298ad
10 changed files with 675 additions and 77 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -0,0 +1,167 @@
namespace ProjectLiner
{
partial class FormShipCollection
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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<DrawingBaseLiner>());
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();
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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<DrawingBaseLiner>? _collection = null;
private int GetMaxCount => _pictureWidth * _pictureHeight /
(_placeSizeWidth * _placeSizeHeight);
public AbstractCompany(int picWidth, int picHeight,
IGenericObjectsCollection<DrawingBaseLiner> 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();
}

View File

@ -0,0 +1,89 @@
namespace ProjectLiner.GenericObjectsCollection;
public class GenericObjectsCollection<T> : IGenericObjectsCollection<T>
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<T?>();
}
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;
}
}

View File

@ -0,0 +1,12 @@
namespace ProjectLiner.GenericObjectsCollection;
public interface IGenericObjectsCollection<T>
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);
}

View File

@ -0,0 +1,76 @@
using ProjectLiner.Drawnings;
using ProjectLiner.GenericObjectsCollection;
namespace ProjectLiner.CollectionGenericObjects;
public class LandingStage : AbstractCompany
{
public LandingStage(int picWidth, int picHeight,
IGenericObjectsCollection<DrawingBaseLiner> 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++;
}
}
}
}

View File

@ -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());
}
}
}