Compare commits

...

9 Commits

Author SHA1 Message Date
b982e14de2 change delegate type 2025-02-15 10:33:41 +04:00
5dc4b4e506 completed 2025-02-15 10:24:16 +04:00
d723288bc4 pre release 2025-02-15 02:16:07 +04:00
e28c9878fe completed 2025-02-13 20:35:54 +04:00
fc7f5298ad pre release 2025-02-10 09:12:26 +04:00
602604faba some fixes 2025-02-08 22:12:26 +04:00
0b77e3af08 Added movement strategy through abstract class 2025-02-06 21:38:12 +04:00
c4dc78fc09 Added parent classes and constructors 2025-02-06 18:51:06 +04:00
d4ada468ee LabWork01 completed 2025-02-04 16:53:14 +04:00
39 changed files with 2683 additions and 77 deletions

View File

@ -0,0 +1,10 @@
namespace ProjectLiner.Drawnings;
public enum DirectionType
{
None = -1,
Up = 1,
Down = 2,
Left = 3,
Right = 4,
}

View File

@ -0,0 +1,154 @@
using ProjectLiner.Entities;
namespace ProjectLiner.Drawnings;
public class DrawingBaseLiner
{
public BaseLinerEntity? BaseLiner { get; protected set; }
private int? _pictureWidth;
private int? _pictureHeight;
protected int? _startPosX;
protected int? _startPosY;
private readonly int _drawingLinerWidth = 140;
private readonly int _drawingLinerHeight = 40;
public int? GetPosX => _startPosX;
public int? GetPosY => _startPosY;
public int GetWidth => _drawingLinerWidth;
public int GetHeight => _drawingLinerHeight;
private DrawingBaseLiner()
{
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
public DrawingBaseLiner(int speed, double weight, Color primaryColor) : this()
{
BaseLiner = new BaseLinerEntity(speed, weight, primaryColor);
}
public DrawingBaseLiner(int drawingBaseLinerWidth, int drawingBaseLinerHeight)
{
_drawingLinerHeight = drawingBaseLinerHeight;
_drawingLinerWidth = drawingBaseLinerWidth;
}
public bool SetPictureSize(int width, int height)
{
if (_drawingLinerWidth <= width && _drawingLinerHeight <= height)
{
_pictureWidth = width;
_pictureHeight = height;
return true;
}
else
{
return false;
}
}
public void SetPosition(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
if (x < 0)
{
x = 0;
}
else if (x > _pictureWidth.Value - _drawingLinerWidth)
{
x = _pictureWidth.Value - _drawingLinerWidth;
}
if (y < 0)
{
y = 0;
}
else if (y > _pictureHeight.Value - _drawingLinerHeight)
{
y = _pictureHeight.Value - _drawingLinerHeight;
}
_startPosX = x;
_startPosY = y;
}
public bool MoveTransport(DirectionType direction)
{
if (BaseLiner == null ||
!_startPosX.HasValue || !_startPosY.HasValue ||
!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{
return false;
}
switch (direction)
{
//left
case DirectionType.Left:
if (_startPosX.Value - BaseLiner.Step > 0)
{
_startPosX -= (int)BaseLiner.Step;
}
break;
//up
case DirectionType.Up:
if (_startPosY.Value - BaseLiner.Step > 0)
{
_startPosY -= (int)BaseLiner.Step;
}
break;
//right
case DirectionType.Right:
if (_startPosX.Value + BaseLiner.Step <
_pictureWidth.Value - _drawingLinerWidth)
{
_startPosX += (int)BaseLiner.Step;
}
break;
//down
case DirectionType.Down:
if (_startPosY.Value + BaseLiner.Step <
_pictureHeight.Value - _drawingLinerHeight)
{
_startPosY += (int)BaseLiner.Step;
}
break;
default:
return false;
}
return true;
}
public virtual void DrawTransport(Graphics g)
{
if (BaseLiner == null ||
!_startPosX.HasValue || !_startPosY.HasValue)
return;
int x = _startPosX.Value;
int y = _startPosY.Value;
Pen borderPen = new(Color.Black);
Brush bodyBrush = new SolidBrush(BaseLiner.PrimaryColor); // Hull
Brush deckBrush = new SolidBrush(Color.White); // Deck
// body (hull)
Point[] hullPoints = {
new Point(x + 20, y + 40), // bottom Left
new Point(x + 120, y + 40), // bottom right
new Point(x + 140, y + 10), // Top left
new Point(x , y + 10) // Top right
};
g.FillPolygon(bodyBrush, hullPoints);
g.DrawPolygon(borderPen, hullPoints);
// first deck
g.FillRectangle(deckBrush, x + 30, y, 100, 10);
g.DrawRectangle(borderPen, x + 30, y, 100, 10);
}
}

View File

@ -0,0 +1,47 @@
using ProjectLiner.Entities;
namespace ProjectLiner.Drawnings;
public class DrawingLiner : DrawingBaseLiner
{
public DrawingLiner(
int speed, double weight, Color primaryColor, Color secondaryColor,
LinerEntityType type, int capacity, int maxPassengers,
bool hasExtraDeck, bool hasPool
) : base(140, 50)
{
BaseLiner = new LinerEntity(speed, weight, primaryColor, secondaryColor,
type, capacity, maxPassengers, hasExtraDeck, hasPool);
}
public override void DrawTransport(Graphics g)
{
if (BaseLiner == null || BaseLiner is not LinerEntity linerEntity ||
!_startPosX.HasValue || !_startPosY.HasValue)
return;
_startPosY += 10;
base.DrawTransport(g);
_startPosY -= 10;
int x = _startPosX.Value;
int y = _startPosY.Value;
Pen borderPen = new(Color.Black);
Brush additionalBrush = new SolidBrush(linerEntity.SecondaryColor);
Brush poolBrush = new SolidBrush(Color.Cyan); // Pool
if (linerEntity.HasPool)
{
// pool on the deck
g.FillEllipse(poolBrush, x + 35, y + 5, 30, 10);
g.DrawEllipse(borderPen, x + 35, y + 5, 30, 10);
}
if (linerEntity.HasExtraDeck)
{
// optional deck
g.FillRectangle(additionalBrush, x + 70, y, 50, 10);
g.DrawRectangle(borderPen, x + 70, y, 50, 10);
}
}
}

View File

@ -0,0 +1,20 @@
namespace ProjectLiner.Entities;
public class BaseLinerEntity
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color PrimaryColor { get; private set; }
public double Step => Speed / (Weight / 100);
public BaseLinerEntity(int speed, double weight, Color primaryColor)
{
Speed = speed;
Weight = weight;
PrimaryColor = primaryColor;
}
public void SetPrimaryColor(Color color)
{
PrimaryColor = color;
}
}

View File

@ -0,0 +1,36 @@
namespace ProjectLiner.Entities;
public enum LinerEntityType
{
Passenger,
Cargo,
Military,
Mixed
}
public class LinerEntity : BaseLinerEntity
{
public Color SecondaryColor { get; private set; }
public LinerEntityType Type { get; private set; }
public int Capacity { get; private set; }
public int MaxPassengers { get; private set; }
public bool HasExtraDeck { get; private set; }
public bool HasPool { get; private set; }
public LinerEntity(
int speed, double weight, Color primaryColor, Color secondaryColor,
LinerEntityType type, int capacity, int maxPassengers,
bool hasExtraDeck, bool hasPool
) : base(speed, weight, primaryColor)
{
SecondaryColor = secondaryColor;
Type = type;
Capacity = capacity;
MaxPassengers = maxPassengers;
HasExtraDeck = hasExtraDeck;
HasPool = hasPool;
}
public void SetColors(Color secondaryColor)
{
SecondaryColor = secondaryColor;
}
}

View File

@ -1,39 +0,0 @@
namespace ProjectLiner
{
partial class Form1
{
/// <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()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace ProjectLiner
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,156 @@
namespace ProjectLiner
{
partial class FormLiner
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLiner));
pictureBoxLiner = new PictureBox();
buttonMoveLeft = new Button();
buttonMoveUp = new Button();
buttonMoveDown = new Button();
buttonMoveRight = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
SuspendLayout();
//
// pictureBoxLiner
//
pictureBoxLiner.Dock = DockStyle.Fill;
pictureBoxLiner.Location = new Point(0, 0);
pictureBoxLiner.Margin = new Padding(3, 2, 3, 2);
pictureBoxLiner.Name = "pictureBoxLiner";
pictureBoxLiner.Size = new Size(981, 637);
pictureBoxLiner.TabIndex = 0;
pictureBoxLiner.TabStop = false;
//
// buttonMoveLeft
//
buttonMoveLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonMoveLeft.BackgroundImage = Properties.Resources.icons8_arrow_left_60;
buttonMoveLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonMoveLeft.Location = new Point(875, 602);
buttonMoveLeft.Margin = new Padding(3, 2, 3, 2);
buttonMoveLeft.Name = "buttonMoveLeft";
buttonMoveLeft.Size = new Size(31, 26);
buttonMoveLeft.TabIndex = 2;
buttonMoveLeft.UseVisualStyleBackColor = true;
buttonMoveLeft.Click += ButtonMove_Click;
//
// buttonMoveUp
//
buttonMoveUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonMoveUp.BackgroundImage = Properties.Resources.icons8_arrow_up_60;
buttonMoveUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonMoveUp.Location = new Point(911, 571);
buttonMoveUp.Margin = new Padding(3, 2, 3, 2);
buttonMoveUp.Name = "buttonMoveUp";
buttonMoveUp.Size = new Size(31, 26);
buttonMoveUp.TabIndex = 3;
buttonMoveUp.UseVisualStyleBackColor = true;
buttonMoveUp.Click += ButtonMove_Click;
//
// buttonMoveDown
//
buttonMoveDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonMoveDown.BackgroundImage = Properties.Resources.icons8_arrow_down_60;
buttonMoveDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonMoveDown.Location = new Point(911, 602);
buttonMoveDown.Margin = new Padding(3, 2, 3, 2);
buttonMoveDown.Name = "buttonMoveDown";
buttonMoveDown.Size = new Size(31, 26);
buttonMoveDown.TabIndex = 4;
buttonMoveDown.UseVisualStyleBackColor = true;
buttonMoveDown.Click += ButtonMove_Click;
//
// buttonMoveRight
//
buttonMoveRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonMoveRight.BackgroundImage = (Image)resources.GetObject("buttonMoveRight.BackgroundImage");
buttonMoveRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonMoveRight.Location = new Point(947, 602);
buttonMoveRight.Margin = new Padding(3, 2, 3, 2);
buttonMoveRight.Name = "buttonMoveRight";
buttonMoveRight.Size = new Size(31, 26);
buttonMoveRight.TabIndex = 5;
buttonMoveRight.UseVisualStyleBackColor = true;
buttonMoveRight.Click += ButtonMove_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(848, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(121, 23);
comboBoxStrategy.TabIndex = 7;
//
// buttonStrategyStep
//
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonStrategyStep.Location = new Point(894, 41);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(75, 23);
buttonStrategyStep.TabIndex = 8;
buttonStrategyStep.Text = "Step";
buttonStrategyStep.UseVisualStyleBackColor = true;
buttonStrategyStep.Click += buttonStrategyStep_Click;
//
// FormLiner
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(981, 637);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonMoveRight);
Controls.Add(buttonMoveDown);
Controls.Add(buttonMoveUp);
Controls.Add(buttonMoveLeft);
Controls.Add(pictureBoxLiner);
Margin = new Padding(3, 2, 3, 2);
Name = "FormLiner";
StartPosition = FormStartPosition.CenterScreen;
Text = "Liner";
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxLiner;
private Button buttonMoveLeft;
private Button buttonMoveUp;
private Button buttonMoveDown;
private Button buttonMoveRight;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
}

View File

@ -0,0 +1,110 @@
using ProjectLiner.Drawnings;
using ProjectLiner.Entities;
using ProjectLiner.MovementStrategy;
namespace ProjectLiner
{
public partial class FormLiner : Form
{
private DrawingBaseLiner? _drawingLiner;
private AbstractStrategy? _strategy;
public FormLiner()
{
InitializeComponent();
_strategy = null;
}
public DrawingBaseLiner SetLiner
{
set
{
_drawingLiner = value;
_drawingLiner.SetPictureSize(pictureBoxLiner.Width,
pictureBoxLiner.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
private void Draw()
{
if (_drawingLiner == null)
{
return;
}
Bitmap bitmap = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
Graphics graphics = Graphics.FromImage(bitmap);
_drawingLiner?.DrawTransport(graphics);
pictureBoxLiner.Image = bitmap;
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingLiner == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonMoveUp":
result = _drawingLiner.MoveTransport(DirectionType.Up);
break;
case "buttonMoveDown":
result = _drawingLiner.MoveTransport(DirectionType.Down);
break;
case "buttonMoveLeft":
result = _drawingLiner.MoveTransport(DirectionType.Left);
break;
case "buttonMoveRight":
result = _drawingLiner.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
private void buttonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawingLiner == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_strategy == null)
{
return;
}
_strategy.SetData(new MoveableLiner(_drawingLiner),
pictureBoxLiner.Width, pictureBoxLiner.Height);
}
if (_strategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == StrategyStatus.Finished)
{
comboBoxStrategy.Enabled = true;
_strategy = null;
}
}
}
}

View File

@ -0,0 +1,132 @@
<?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>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="buttonMoveRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAL
DAAACwwBP0AiyAAAARZJREFUaEPtmTsKwlAQRbMBcQNi69IEG7VS0A1Z6M78V9roHUgghJuvIJnJPXCa
wAwc0ryXJEIIIYQQQggRgVHqIFjAd+raHkTnCj85tzA0+djMPQwLCzbDRrPYzJDRLDRvuGgWWTRUNAtk
holmcWWGiGZhVf4UPYVH+IRseV/tdDix2AtkCz3YOtreLFvkyVbRD8iWeLNxNBv26grWwga9+oK192k2
6NXBBS9hLXfIhr25gY04QbbAk41jjRk8Q7bIg61iMybwAG+QLe2rnWL7Aguqcgddw6LKdB9rsDBmiFiD
xRUNE2uwwLyhYg0WmRku1mChZshYY1CxRvEzk+tDRRPmcFC/S41xqhBCCCGEEEL8kyT5Avbp6yDpsmlv
AAAAAElFTkSuQmCC
</value>
</data>
</root>

View File

@ -0,0 +1,426 @@
namespace ProjectLiner
{
partial class FormLinerConfig
{
/// <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()
{
groupBoxParameters = new GroupBox();
labelAdvancedObject = new Label();
labelBasicObject = new Label();
groupBoxColors = new GroupBox();
panelPurple = new Panel();
panelYellow = new Panel();
panelBlack = new Panel();
panelBlue = new Panel();
panelGray = new Panel();
panelGreen = new Panel();
panelWhite = new Panel();
panelRed = new Panel();
comboBoxLinerType = new ComboBox();
checkBoxPool = new CheckBox();
checkBoxExtraDeck = new CheckBox();
numericUpDownMaxPassengers = new NumericUpDown();
numericUpDownCapacity = new NumericUpDown();
numericUpDownWeight = new NumericUpDown();
numericUpDownSpeed = new NumericUpDown();
labelPassengers = new Label();
labelCapacity = new Label();
labelWeight = new Label();
labelLinerType = new Label();
labelSpeed = new Label();
pictureBoxLiner = new PictureBox();
buttonAdd = new Button();
buttonCancel = new Button();
panelObject = new Panel();
labelSecondaryColor = new Label();
labelPrimaryColor = new Label();
groupBoxParameters.SuspendLayout();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownMaxPassengers).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
panelObject.SuspendLayout();
SuspendLayout();
//
// groupBoxParameters
//
groupBoxParameters.Controls.Add(labelAdvancedObject);
groupBoxParameters.Controls.Add(labelBasicObject);
groupBoxParameters.Controls.Add(groupBoxColors);
groupBoxParameters.Controls.Add(comboBoxLinerType);
groupBoxParameters.Controls.Add(checkBoxPool);
groupBoxParameters.Controls.Add(checkBoxExtraDeck);
groupBoxParameters.Controls.Add(numericUpDownMaxPassengers);
groupBoxParameters.Controls.Add(numericUpDownCapacity);
groupBoxParameters.Controls.Add(numericUpDownWeight);
groupBoxParameters.Controls.Add(numericUpDownSpeed);
groupBoxParameters.Controls.Add(labelPassengers);
groupBoxParameters.Controls.Add(labelCapacity);
groupBoxParameters.Controls.Add(labelWeight);
groupBoxParameters.Controls.Add(labelLinerType);
groupBoxParameters.Controls.Add(labelSpeed);
groupBoxParameters.Dock = DockStyle.Left;
groupBoxParameters.Location = new Point(0, 0);
groupBoxParameters.Name = "groupBoxParameters";
groupBoxParameters.Size = new Size(594, 261);
groupBoxParameters.TabIndex = 0;
groupBoxParameters.TabStop = false;
groupBoxParameters.Text = "Parameters";
//
// labelAdvancedObject
//
labelAdvancedObject.BorderStyle = BorderStyle.FixedSingle;
labelAdvancedObject.Location = new Point(433, 214);
labelAdvancedObject.Name = "labelAdvancedObject";
labelAdvancedObject.Size = new Size(155, 35);
labelAdvancedObject.TabIndex = 5;
labelAdvancedObject.Text = "Advanced Object";
labelAdvancedObject.TextAlign = ContentAlignment.MiddleCenter;
labelAdvancedObject.MouseDown += LabelObject_MouseDown;
//
// labelBasicObject
//
labelBasicObject.BorderStyle = BorderStyle.FixedSingle;
labelBasicObject.Location = new Point(274, 214);
labelBasicObject.Name = "labelBasicObject";
labelBasicObject.Size = new Size(155, 35);
labelBasicObject.TabIndex = 5;
labelBasicObject.Text = "Basic Object";
labelBasicObject.TextAlign = ContentAlignment.MiddleCenter;
labelBasicObject.MouseDown += LabelObject_MouseDown;
//
// groupBoxColors
//
groupBoxColors.Controls.Add(panelPurple);
groupBoxColors.Controls.Add(panelYellow);
groupBoxColors.Controls.Add(panelBlack);
groupBoxColors.Controls.Add(panelBlue);
groupBoxColors.Controls.Add(panelGray);
groupBoxColors.Controls.Add(panelGreen);
groupBoxColors.Controls.Add(panelWhite);
groupBoxColors.Controls.Add(panelRed);
groupBoxColors.Location = new Point(274, 19);
groupBoxColors.Name = "groupBoxColors";
groupBoxColors.Size = new Size(314, 164);
groupBoxColors.TabIndex = 4;
groupBoxColors.TabStop = false;
groupBoxColors.Text = "Colors";
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(242, 95);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(67, 62);
panelPurple.TabIndex = 0;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(242, 27);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(67, 62);
panelYellow.TabIndex = 0;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(169, 95);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(67, 62);
panelBlack.TabIndex = 0;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(169, 27);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(67, 62);
panelBlue.TabIndex = 0;
//
// panelGray
//
panelGray.BackColor = Color.Gray;
panelGray.Location = new Point(93, 95);
panelGray.Name = "panelGray";
panelGray.Size = new Size(67, 62);
panelGray.TabIndex = 0;
//
// panelGreen
//
panelGreen.BackColor = Color.Green;
panelGreen.Location = new Point(93, 27);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(67, 62);
panelGreen.TabIndex = 0;
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(16, 95);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(67, 62);
panelWhite.TabIndex = 0;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(16, 27);
panelRed.Name = "panelRed";
panelRed.Size = new Size(67, 62);
panelRed.TabIndex = 0;
//
// comboBoxLinerType
//
comboBoxLinerType.FormattingEnabled = true;
comboBoxLinerType.Items.AddRange(new object[] { "Passenger", "Cargo", "Military", "Mixed" });
comboBoxLinerType.Location = new Point(11, 43);
comboBoxLinerType.Name = "comboBoxLinerType";
comboBoxLinerType.Size = new Size(121, 23);
comboBoxLinerType.TabIndex = 3;
//
// checkBoxPool
//
checkBoxPool.AutoSize = true;
checkBoxPool.Location = new Point(138, 230);
checkBoxPool.Name = "checkBoxPool";
checkBoxPool.Size = new Size(90, 19);
checkBoxPool.TabIndex = 2;
checkBoxPool.Text = "Pool feature";
checkBoxPool.UseVisualStyleBackColor = true;
//
// checkBoxExtraDeck
//
checkBoxExtraDeck.AutoSize = true;
checkBoxExtraDeck.Location = new Point(11, 230);
checkBoxExtraDeck.Name = "checkBoxExtraDeck";
checkBoxExtraDeck.Size = new Size(121, 19);
checkBoxExtraDeck.TabIndex = 2;
checkBoxExtraDeck.Text = "Extra Deck feature";
checkBoxExtraDeck.UseVisualStyleBackColor = true;
//
// numericUpDownMaxPassengers
//
numericUpDownMaxPassengers.Location = new Point(105, 186);
numericUpDownMaxPassengers.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownMaxPassengers.Name = "numericUpDownMaxPassengers";
numericUpDownMaxPassengers.Size = new Size(120, 23);
numericUpDownMaxPassengers.TabIndex = 1;
numericUpDownMaxPassengers.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownCapacity
//
numericUpDownCapacity.Location = new Point(105, 153);
numericUpDownCapacity.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownCapacity.Name = "numericUpDownCapacity";
numericUpDownCapacity.Size = new Size(120, 23);
numericUpDownCapacity.TabIndex = 1;
numericUpDownCapacity.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(105, 118);
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(120, 23);
numericUpDownWeight.TabIndex = 1;
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(105, 85);
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
numericUpDownSpeed.Name = "numericUpDownSpeed";
numericUpDownSpeed.Size = new Size(120, 23);
numericUpDownSpeed.TabIndex = 1;
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
//
// labelPassengers
//
labelPassengers.Location = new Point(11, 188);
labelPassengers.Name = "labelPassengers";
labelPassengers.Size = new Size(88, 21);
labelPassengers.TabIndex = 0;
labelPassengers.Text = "Passengers:";
//
// labelCapacity
//
labelCapacity.Location = new Point(11, 155);
labelCapacity.Name = "labelCapacity";
labelCapacity.Size = new Size(88, 21);
labelCapacity.TabIndex = 0;
labelCapacity.Text = "Capacity:";
//
// labelWeight
//
labelWeight.Location = new Point(11, 120);
labelWeight.Name = "labelWeight";
labelWeight.Size = new Size(88, 21);
labelWeight.TabIndex = 0;
labelWeight.Text = "Weight:";
//
// labelLinerType
//
labelLinerType.Location = new Point(11, 19);
labelLinerType.Name = "labelLinerType";
labelLinerType.Size = new Size(88, 21);
labelLinerType.TabIndex = 0;
labelLinerType.Text = "Type of Liner";
//
// labelSpeed
//
labelSpeed.Location = new Point(11, 87);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(88, 21);
labelSpeed.TabIndex = 0;
labelSpeed.Text = "Speed:";
//
// pictureBoxLiner
//
pictureBoxLiner.Location = new Point(9, 56);
pictureBoxLiner.Name = "pictureBoxLiner";
pictureBoxLiner.Size = new Size(179, 123);
pictureBoxLiner.TabIndex = 1;
pictureBoxLiner.TabStop = false;
//
// buttonAdd
//
buttonAdd.Location = new Point(609, 214);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(75, 33);
buttonAdd.TabIndex = 2;
buttonAdd.Text = "Add";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(713, 214);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 33);
buttonCancel.TabIndex = 2;
buttonCancel.Text = "Cancel";
buttonCancel.UseVisualStyleBackColor = true;
//
// panelObject
//
panelObject.AllowDrop = true;
panelObject.Controls.Add(pictureBoxLiner);
panelObject.Controls.Add(labelSecondaryColor);
panelObject.Controls.Add(labelPrimaryColor);
panelObject.Location = new Point(600, 12);
panelObject.Name = "panelObject";
panelObject.Size = new Size(198, 196);
panelObject.TabIndex = 3;
panelObject.DragDrop += PanelObject_DragDrop;
panelObject.DragEnter += PanelObject_DragEnter;
//
// labelSecondaryColor
//
labelSecondaryColor.AllowDrop = true;
labelSecondaryColor.BorderStyle = BorderStyle.FixedSingle;
labelSecondaryColor.Location = new Point(100, 7);
labelSecondaryColor.Name = "labelSecondaryColor";
labelSecondaryColor.Size = new Size(88, 35);
labelSecondaryColor.TabIndex = 5;
labelSecondaryColor.Text = "Secondray Color";
labelSecondaryColor.TextAlign = ContentAlignment.MiddleCenter;
labelSecondaryColor.DragDrop += LabelColor_DragDrop;
labelSecondaryColor.DragEnter += LabelColor_DragEnter;
//
// labelPrimaryColor
//
labelPrimaryColor.AllowDrop = true;
labelPrimaryColor.BorderStyle = BorderStyle.FixedSingle;
labelPrimaryColor.Location = new Point(9, 7);
labelPrimaryColor.Name = "labelPrimaryColor";
labelPrimaryColor.Size = new Size(88, 35);
labelPrimaryColor.TabIndex = 5;
labelPrimaryColor.Text = "Primary Color";
labelPrimaryColor.TextAlign = ContentAlignment.MiddleCenter;
labelPrimaryColor.DragDrop += LabelColor_DragDrop;
labelPrimaryColor.DragEnter += LabelColor_DragEnter;
//
// FormLinerConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(805, 261);
Controls.Add(panelObject);
Controls.Add(buttonCancel);
Controls.Add(buttonAdd);
Controls.Add(groupBoxParameters);
Name = "FormLinerConfig";
Text = "FormLinerConfig";
groupBoxParameters.ResumeLayout(false);
groupBoxParameters.PerformLayout();
groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownMaxPassengers).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).EndInit();
panelObject.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxParameters;
private Label labelWeight;
private Label labelSpeed;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private NumericUpDown numericUpDownCapacity;
private Label labelCapacity;
private CheckBox checkBoxPool;
private CheckBox checkBoxExtraDeck;
private NumericUpDown numericUpDownMaxPassengers;
private Label labelPassengers;
private Label labelLinerType;
private ComboBox comboBoxLinerType;
private PictureBox pictureBoxLiner;
private Button buttonAdd;
private Button buttonCancel;
private Label labelAdvancedObject;
private Label labelBasicObject;
private GroupBox groupBoxColors;
private Panel panelPurple;
private Panel panelYellow;
private Panel panelBlack;
private Panel panelBlue;
private Panel panelGray;
private Panel panelGreen;
private Panel panelWhite;
private Panel panelRed;
private Panel panelObject;
private Label labelSecondaryColor;
private Label labelPrimaryColor;
}
}

View File

@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectLiner.Drawnings;
using ProjectLiner.Entities;
namespace ProjectLiner
{
public partial class FormLinerConfig : Form
{
private DrawingBaseLiner? _liner;
private event Action<DrawingBaseLiner>? _linerDelegate;
public FormLinerConfig()
{
InitializeComponent();
buttonCancel.Click += (s, e) => Close();
panelRed.MouseDown += Panel_MouseDown;
panelGreen.MouseDown += Panel_MouseDown;
panelBlue.MouseDown += Panel_MouseDown;
panelYellow.MouseDown += Panel_MouseDown;
panelWhite.MouseDown += Panel_MouseDown;
panelGray.MouseDown += Panel_MouseDown;
panelBlack.MouseDown += Panel_MouseDown;
panelPurple.MouseDown += Panel_MouseDown;
}
public void SetLinerDelegate(Action<DrawingBaseLiner> linerDelegate)
{
_linerDelegate += linerDelegate;
}
private void DrawObject()
{
Bitmap bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
Graphics gr = Graphics.FromImage(bmp);
_liner?.SetPictureSize(pictureBoxLiner.Width,
pictureBoxLiner.Height);
_liner?.SetPosition(15, 15);
_liner?.DrawTransport(gr);
pictureBoxLiner.Image = bmp;
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ?
DragDropEffects.Copy : DragDropEffects.None;
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
{
case "labelBasicObject":
_liner = new DrawingBaseLiner((int)numericUpDownSpeed.Value,
(double)numericUpDownWeight.Value, Color.White);
break;
case "labelAdvancedObject":
_liner = new DrawingLiner((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value,
Color.White, Color.Black, (Entities.LinerEntityType)comboBoxLinerType.SelectedIndex,
(int)numericUpDownCapacity.Value, (int)numericUpDownMaxPassengers.Value,
checkBoxExtraDeck.Checked, checkBoxPool.Checked);
break;
}
DrawObject();
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (_liner != null)
{
_linerDelegate?.Invoke(_liner);
Close();
}
}
private void Panel_MouseDown(object? sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ?
DragDropEffects.Copy : DragDropEffects.None;
}
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
if (_liner == null || sender == null)
{
return;
}
Label label = (Label)sender;
Color color = (Color)e.Data?.GetData(typeof(Color));
switch (label.Name)
{
case "labelPrimaryColor":
_liner.BaseLiner?.SetPrimaryColor(color);
break;
case "labelSecondaryColor":
(_liner.BaseLiner as LinerEntity)?.SetColors(color);
break;
}
DrawObject();
}
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -0,0 +1,282 @@
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();
panelCompanyTools = new Panel();
buttonAddLiner = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonRefresh = new Button();
buttonRemoveObject = new Button();
buttonSu = new Button();
buttonCreateCompany = new Button();
comboBoxCompanySelector = new ComboBox();
panelCollectionStorages = new Panel();
listBoxCollections = new ListBox();
buttonRemoveCollection = new Button();
buttonAddCollection = new Button();
radioButtonList = new RadioButton();
radioButtonArray = new RadioButton();
textBoxCollectionName = new TextBox();
label1CollectionName = new Label();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelCollectionStorages.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(comboBoxCompanySelector);
groupBoxTools.Controls.Add(panelCollectionStorages);
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";
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddLiner);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonRemoveObject);
panelCompanyTools.Controls.Add(buttonSu);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Location = new Point(3, 412);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(194, 255);
panelCompanyTools.TabIndex = 4;
//
// buttonAddLiner
//
buttonAddLiner.Location = new Point(3, 3);
buttonAddLiner.Name = "buttonAddLiner";
buttonAddLiner.Size = new Size(188, 42);
buttonAddLiner.TabIndex = 1;
buttonAddLiner.Text = "Add Liner";
buttonAddLiner.UseVisualStyleBackColor = true;
buttonAddLiner.Click += ButtonAddLiner_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(6, 100);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(185, 23);
maskedTextBoxPosition.TabIndex = 2;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonRefresh
//
buttonRefresh.Location = new Point(3, 208);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(188, 38);
buttonRefresh.TabIndex = 1;
buttonRefresh.Text = "Refresh";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonRemoveObject
//
buttonRemoveObject.Location = new Point(3, 129);
buttonRemoveObject.Name = "buttonRemoveObject";
buttonRemoveObject.Size = new Size(188, 35);
buttonRemoveObject.TabIndex = 1;
buttonRemoveObject.Text = "Remove Liner or Ship";
buttonRemoveObject.UseVisualStyleBackColor = true;
buttonRemoveObject.Click += ButtonRemoveShip_Click;
//
// buttonSu
//
buttonSu.Location = new Point(3, 170);
buttonSu.Name = "buttonSu";
buttonSu.Size = new Size(188, 32);
buttonSu.TabIndex = 1;
buttonSu.Text = "Submit for testing";
buttonSu.UseVisualStyleBackColor = true;
buttonSu.Click += ButtonSubmitForTesting_Click;
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(6, 358);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(188, 34);
buttonCreateCompany.TabIndex = 3;
buttonCreateCompany.Text = "Create Company";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
// comboBoxCompanySelector
//
comboBoxCompanySelector.FormattingEnabled = true;
comboBoxCompanySelector.Items.AddRange(new object[] { "Landing Stage" });
comboBoxCompanySelector.Location = new Point(6, 329);
comboBoxCompanySelector.Name = "comboBoxCompanySelector";
comboBoxCompanySelector.Size = new Size(188, 23);
comboBoxCompanySelector.TabIndex = 0;
comboBoxCompanySelector.SelectedIndexChanged += ComboBoxCompanySelector_SelectedIndexChanged;
//
// panelCollectionStorages
//
panelCollectionStorages.Controls.Add(listBoxCollections);
panelCollectionStorages.Controls.Add(buttonRemoveCollection);
panelCollectionStorages.Controls.Add(buttonAddCollection);
panelCollectionStorages.Controls.Add(radioButtonList);
panelCollectionStorages.Controls.Add(radioButtonArray);
panelCollectionStorages.Controls.Add(textBoxCollectionName);
panelCollectionStorages.Controls.Add(label1CollectionName);
panelCollectionStorages.Dock = DockStyle.Top;
panelCollectionStorages.Location = new Point(3, 19);
panelCollectionStorages.Name = "panelCollectionStorages";
panelCollectionStorages.Size = new Size(194, 304);
panelCollectionStorages.TabIndex = 3;
//
// listBoxCollections
//
listBoxCollections.FormattingEnabled = true;
listBoxCollections.ItemHeight = 15;
listBoxCollections.Location = new Point(3, 124);
listBoxCollections.Name = "listBoxCollections";
listBoxCollections.Size = new Size(188, 124);
listBoxCollections.TabIndex = 4;
//
// buttonRemoveCollection
//
buttonRemoveCollection.Location = new Point(3, 254);
buttonRemoveCollection.Name = "buttonRemoveCollection";
buttonRemoveCollection.Size = new Size(188, 34);
buttonRemoveCollection.TabIndex = 3;
buttonRemoveCollection.Text = "Remove Collection";
buttonRemoveCollection.UseVisualStyleBackColor = true;
buttonRemoveCollection.Click += ButtonRemoveCollection_Click;
//
// buttonAddCollection
//
buttonAddCollection.Location = new Point(3, 84);
buttonAddCollection.Name = "buttonAddCollection";
buttonAddCollection.Size = new Size(188, 34);
buttonAddCollection.TabIndex = 3;
buttonAddCollection.Text = "Add Collection";
buttonAddCollection.UseVisualStyleBackColor = true;
buttonAddCollection.Click += ButtonAddCollection_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(109, 59);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(43, 19);
radioButtonList.TabIndex = 2;
radioButtonList.TabStop = true;
radioButtonList.Text = "List";
radioButtonList.UseVisualStyleBackColor = true;
//
// radioButtonArray
//
radioButtonArray.AutoSize = true;
radioButtonArray.Location = new Point(50, 59);
radioButtonArray.Name = "radioButtonArray";
radioButtonArray.Size = new Size(53, 19);
radioButtonArray.TabIndex = 2;
radioButtonArray.TabStop = true;
radioButtonArray.Text = "Array";
radioButtonArray.UseVisualStyleBackColor = true;
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(3, 30);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(188, 23);
textBoxCollectionName.TabIndex = 1;
//
// label1CollectionName
//
label1CollectionName.AutoSize = true;
label1CollectionName.Location = new Point(50, 12);
label1CollectionName.Name = "label1CollectionName";
label1CollectionName.Size = new Size(96, 15);
label1CollectionName.TabIndex = 0;
label1CollectionName.Text = "Collection Name";
//
// 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);
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
panelCollectionStorages.ResumeLayout(false);
panelCollectionStorages.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 buttonAddLiner;
private ComboBox comboBoxCompanySelector;
private PictureBox pictureBox;
private Panel panelCollectionStorages;
private RadioButton radioButtonList;
private RadioButton radioButtonArray;
private TextBox textBoxCollectionName;
private Label label1CollectionName;
private ListBox listBoxCollections;
private Button buttonRemoveCollection;
private Button buttonAddCollection;
private Panel panelCompanyTools;
private Button buttonCreateCompany;
}
}

View File

@ -0,0 +1,189 @@
using ProjectLiner.CollectionGenericObjects;
using ProjectLiner.Drawnings;
using ProjectLiner.Entities;
using ProjectLiner.GenericObjectsCollection;
namespace ProjectLiner;
public partial class FormShipCollection : Form
{
private readonly CollectionStorage<DrawingBaseLiner> _collectionStorage;
private AbstractCompany? _company = null;
public FormShipCollection()
{
InitializeComponent();
_collectionStorage = new CollectionStorage<DrawingBaseLiner>();
panelCompanyTools.Enabled = false;
}
private void ComboBoxCompanySelector_SelectedIndexChanged(object sender,
EventArgs e)
{
panelCompanyTools.Enabled = false;
}
private void ButtonAddLiner_Click(object sender, EventArgs e)
{
FormLinerConfig form = new();
form.SetLinerDelegate(SetLiner);
form.Show();
}
private void SetLiner(DrawingBaseLiner liner)
{
if (_company == null)
{
return;
}
if (_company + liner)
{
MessageBox.Show("Object was added");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Couldn't add object");
}
}
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();
}
private void ButtonAddCollection_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCollectionName.Text) ||
(!radioButtonList.Checked && !radioButtonArray.Checked))
{
MessageBox.Show("Please fill all fields", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
CollectionType collectionType = CollectionType.None;
if (radioButtonArray.Checked)
{
collectionType = CollectionType.Array;
}
else if (radioButtonList.Checked)
{
collectionType = CollectionType.List;
}
_collectionStorage.AddCollection(textBoxCollectionName.Text,
collectionType);
RerfreshListBoxItems();
}
private void ButtonRemoveCollection_Click(object sender, EventArgs e)
{
if (listBoxCollections.SelectedIndex < 0 ||
listBoxCollections.SelectedItem == null)
{
MessageBox.Show("Collection is not selected", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string collectionName = listBoxCollections.SelectedItem.ToString() ?? string.Empty;
if (MessageBox.Show($"Are you sure you want to remove the collection '{collectionName}'?",
"Confirm Removal", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_collectionStorage.DelCollection(collectionName);
RerfreshListBoxItems();
MessageBox.Show("Collection removed successfully", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void RerfreshListBoxItems()
{
listBoxCollections.Items.Clear();
for (int i = 0; i < _collectionStorage.Keys?.Count; ++i)
{
string? colName = _collectionStorage.Keys?[i];
if (!string.IsNullOrEmpty(colName))
{
listBoxCollections.Items.Add(colName);
}
}
}
private void ButtonCreateCompany_Click(object sender, EventArgs e)
{
if (listBoxCollections.SelectedIndex < 0 ||
listBoxCollections.SelectedItem == null)
{
MessageBox.Show("Collection is not selected");
return;
}
IGenericObjectsCollection<DrawingBaseLiner>? collection =
_collectionStorage[listBoxCollections.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Collection is not found");
return;
}
switch (comboBoxCompanySelector.Text)
{
case "Landing Stage":
_company = new LandingStage(pictureBox.Width,
pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
}

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,45 @@
namespace ProjectLiner.GenericObjectsCollection;
public class CollectionStorage<T>
where T : class
{
readonly Dictionary<string, IGenericObjectsCollection<T>> _storages;
public List<string> Keys => _storages.Keys.ToList();
public CollectionStorage()
{
_storages = new Dictionary<string, IGenericObjectsCollection<T>>();
}
public void AddCollection(string name, CollectionType collectionType)
{
if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
{
return;
}
switch (collectionType)
{
case CollectionType.Array:
_storages.Add(name, new GenericObjectsCollection<T>());
break;
case CollectionType.List:
_storages.Add(name, new ListGenericObjects<T>());
break;
}
}
public void DelCollection(string name)
{
if (string.IsNullOrEmpty(name) || !_storages.ContainsKey(name))
{
return;
}
_storages.Remove(name);
}
public IGenericObjectsCollection<T>? this[string name]
{
get
{
_storages.TryGetValue(name, out var collection);
return collection;
}
}
}

View File

@ -0,0 +1,8 @@
namespace ProjectLiner.GenericObjectsCollection;
public enum CollectionType
{
None = 0,
Array = 1,
List = 2
}

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

@ -0,0 +1,73 @@
namespace ProjectLiner.GenericObjectsCollection;
public class ListGenericObjects<T> : IGenericObjectsCollection<T>
where T : class
{
private readonly List<T> _collection;
private int _maxCount;
public int Count => _collection.Count;
public int SetMaxCount
{
set
{
if (value > 0)
{
_maxCount = value;
}
}
}
public ListGenericObjects()
{
_collection = new List<T>();
}
public T? Get(int position)
{
if (position < 0 || position >= _collection.Count)
{
return null;
}
return _collection[position];
}
public bool Insert(T obj)
{
if (_collection.Count < _maxCount)
{
_collection.Add(obj);
return true;
}
return false;
}
public bool Insert(T obj, int position)
{
if (position < 0 || position >= _maxCount)
{
return false;
}
if (position >= _collection.Count)
{
_collection.AddRange(Enumerable.Repeat(default(T)!, position - _collection.Count + 1));
}
if (_collection[position] == null)
{
_collection[position] = obj;
return true;
}
return false;
}
public bool Remove(int position)
{
if (position < 0 || position >= _collection.Count ||
_collection[position] == null)
{
return false;
}
_collection.RemoveAt(position);
return true;
}
}

View File

@ -0,0 +1,60 @@
namespace ProjectLiner.MovementStrategy;
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private StrategyStatus _state = StrategyStatus.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public StrategyStatus GetStatus() => _state;
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
{
_state = StrategyStatus.NotInit;
return;
}
_state = StrategyStatus.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != StrategyStatus.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = StrategyStatus.Finished;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
protected bool MoveRight() => MoveTo(MovementDirection.Right);
protected bool MoveUp() => MoveTo(MovementDirection.Up);
protected bool MoveDown() => MoveTo(MovementDirection.Down);
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != StrategyStatus.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(MovementDirection movementDirection)
{
if (_state != StrategyStatus.InProgress)
{
return false;
}
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
}
}

View File

@ -0,0 +1,8 @@
namespace ProjectLiner.MovementStrategy;
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool TryMoveObject(MovementDirection direction);
}

View File

@ -0,0 +1,39 @@
namespace ProjectLiner.MovementStrategy;
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
if (objParams.RightBorder + GetStep() < FieldWidth &&
objParams.DownBorder + GetStep() < FieldHeight)
{
MoveRight();
MoveDown();
} else if (objParams.RightBorder + GetStep() < FieldWidth)
{
MoveRight();
}
else if (objParams.DownBorder + GetStep() < FieldHeight)
{
MoveDown();
}
}
}

View File

@ -0,0 +1,50 @@
namespace ProjectLiner.MovementStrategy;
internal class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,47 @@
using ProjectLiner.Drawnings;
namespace ProjectLiner.MovementStrategy;
public class MoveableLiner : IMoveableObject
{
private readonly DrawingBaseLiner? _liner = null;
public MoveableLiner(DrawingBaseLiner liner)
{
_liner = liner;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_liner == null || _liner.BaseLiner == null ||
!_liner.GetPosX.HasValue || !_liner.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_liner.GetPosX.Value, _liner.GetPosY.Value, _liner.GetWidth, _liner.GetHeight);
}
}
public int GetStep => (int)(_liner?.BaseLiner?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_liner == null || _liner.BaseLiner == null)
{
return false;
}
return _liner.MoveTransport(GetDirectionType(direction));
}
private static DirectionType GetDirectionType(MovementDirection direction)
{
return direction switch
{
MovementDirection.Left => DirectionType.Left,
MovementDirection.Right => DirectionType.Right,
MovementDirection.Up => DirectionType.Up,
MovementDirection.Down => DirectionType.Down,
_ => DirectionType.None,
};
}
}

View File

@ -0,0 +1,9 @@
namespace ProjectLiner.MovementStrategy;
public enum MovementDirection
{
Up = 1,
Down = 2,
Left = 3,
Right = 4,
}

View File

@ -0,0 +1,26 @@
namespace ProjectLiner.MovementStrategy;
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int TopBorder => _y;
public int RightBorder => _x + _width;
public int DownBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}

View File

@ -0,0 +1,8 @@
namespace ProjectLiner.MovementStrategy;
public enum StrategyStatus
{
NotInit,
InProgress,
Finished,
}

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 Form1());
Application.Run(new FormShipCollection());
}
}
}

View File

@ -8,4 +8,19 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectLiner.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectLiner.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_arrow_down_60 {
get {
object obj = ResourceManager.GetObject("icons8-arrow-down-60", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_arrow_left_60 {
get {
object obj = ResourceManager.GetObject("icons8-arrow-left-60", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_arrow_right_60 {
get {
object obj = ResourceManager.GetObject("icons8-arrow-right-60", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap icons8_arrow_up_60 {
get {
object obj = ResourceManager.GetObject("icons8-arrow-up-60", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,133 @@
<?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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="icons8-arrow-down-60" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-arrow-down-60.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-arrow-up-60" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-arrow-up-60.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-arrow-right-60" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-arrow-right-60.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-arrow-left-60" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-arrow-left-60.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B