&X^LcDZuLKEvH#unm~
zll#JCZc)X=MIA_0K5bHttns|$WFwI--{679&2ryOO
z0~WZ$fas^bKk%Ue;sN_n)8OU;m;|p)BijuaHoSd8r&i&X)IXMMz>)ECNdv>0AjeuYBaVN1Za^+onr{TpmqO+H?
zoLptr&UM0ec#ZtR)6dPy%1S1aO-)Vh+qW+vA)%t8;&Al!0Qf6Fb`Ok`liT%d>yghh
z*`*^V_lZ01n6n@Cq}+c+;~Zj7Jt!-zX(JZvCIRigm;+Set;<7*#a!B`K2es&L(=Bly(;3RU_?1nd1
zrr*#Wwe2Far;(dW?^-Y2WzNWH7_Bc+>VwK2_%u8ZEL1Q>8m+&Z*Q%eH3@F2FxW`_Z
zKja3nAD-emE%x!=?~r184T@7`D$*oFnm6f6n+EOU5giZrwnf!Ot)`gkAk$PtSBeZ=
zLg^V2SJfL$@h9MK$$9&Z2=di(GVdA*BM+FNk43D8lziI3K_7ebI``GoVNb#ptQ8vS
zH4-+SXTG3PSijJOrrqAUr#@0}C^c3e^E(2rD$uXA!kE@ab9|Aim}+>;hI0XsH=8Nu<3aK3wDu7Q#`BVn|m*Ezwo
zdTAndA=%I?LeTymp>;|Ds?drdFFfrhZfc?iD2}G!A5vZrr4>_6h}UIBC)yvs(-M
zBeg*X|{MuyCV`C126byEDr))^k0z!9>@_Q8%s&bbnHC!IN47
zQOAi$Fe`8({J%{lF!O<}kY<=i_6Vd*ykvs|(gj0zoA#=oDqFISIzz(;T==yNF9?ti0)DTa%*J?4qfbRzWAwdx%3QR#F)JJ3Hs4<7YLX%O+iM_
zN1V7pUdgK=SgW$ZqFE(gicxNNY@;bXhiq3J@KjGwinC$ew1~8B4T7d4QYwxj4D
zXQ6@C%dQ!8rXSRrxt(Wa952lP(8YKfGMadDN<5Cv6<5QD#>%x_r?jC+mnUB8wniGd
z?UJP)0%B^JSp2xQeufOg0uzm{6=jls7B=|k6Kpwl`T}nu&cz)rth?c6LYwLzYxF%|
z6TW!10S(U~RvK=$n~f8!y6x=yk+<(i9@s;(3D-ddQFy;F*6FT_lRV_shZfH9GCgb}
zXw$jmqYMw5GhK_1dc*CvtTDgQt?&TFj@Iby_%ZG8(&?!4pyaj>G#cy*WVDOQxARuE
zov;Z=sAIMzXbqwEn#S0%v8$?S*VHiy7GKkMf1F7kYr-+lv4?z+F0)$870jW%dBOE*
zliw9E$dblnK=Ju74N;X0WIPw>Had`!teB^R*V*hw$1LKzDf*K$?l?B#fneKy8n8;M*+#Jv%(B7U+?h)an){K*3
zx0;@*(WVQ?6eFF&hrVu3bb`|ocTYm8Ksoq)Hy8~5o%-0PFc}xjhoaX
z7*v`#R<3ctsN5jzmgV;B_8=$xT$W4OepRiI@7x8Z4KCWx*gdooZIph@f48yx;u`nZa{&hD%265^*)
zhS7SE3XZ?_G##11oD8@AOqd6Tiq5`ZkY!OS=o#~N5n(%}8_2Jy-J4*^n1v6~zTJ8J
zOH$TTa1@EzWyXhTIAbd66N40F0;_vSj71YNY^7%-<4AK6jEaYX`^P^W3E8qzI$CTV
zoP^3RVV>i@PTu`%F3=j#LE1Ig^k0SoJb$+cH6l0?-_B#0#$XKu=BOD|>lX3)kqJ4H
zN^d9)AN83K9e7)E`}GpF2!|G+v?fZx1~?vzpBFT(io)06BCvQqM9pM%#u^EmS1)%k
z$hDz*LO0tfIGCBplfba(>HTxkHspM!l8?5D}Be`8+
znpP{{`mQbYexeMG4&Y|5x>;mdud&B7mUZ!LKBieqv2s$UerLm;uGAT$a7pnQAUHDK
zlHqi?kUAeePLVvj3=E%>E`HTFGv2i}7@XIsF@Pqq8k;?7quFH5BAiJ##N89x@y5ps
z2rrmjRD{t~%PMnijg}wYuCc(fOX?}FUrv1!?+U%bTsq}3XgHC{Iu{4M^*lg$c(eX4
zzx0Sv$PPI3;RxyT4&PU%A?B}P&L~GxIV&_xJ>{6I$;K*dmCBtE*87O+mF^WjlToi
z#W2n9ggmpzIu5kYH)fKM#~_Man<7-tsgb?3q;pbRttMdzVd>yT3I$>SE2oxQvVFu=DsdER*
zvnwzYy2hsF`Xsnn1uzzL2Fy`{^HvNGs$J8tr!LLRr?{dI4&00T@?9Nx(1sCqf@&x#
zGtUZhvB{*1!=OSEJh#q)RhpE?IO?I{QGUW60u>&gg`~tSf4e4}>b=L4x1zL=T)t5N
zq_Kyd9yhd|ARdu9FvN!m@tl=z)p4%f&L((Pi2b;Av9l*3X$eUKJ(9XFw%4SdxhgG#
z)~*jbC2MTF+K_VkD)+K0nr}tzQ%~0==nEGFH|CcTj_n>T&lVr!@?*i~Fh4#*c%xV5omzL51+=AZAb
zI~3PvOUQ)jL}i*e4GimT*`Bw_E0=Si;0eN+5a8WqAQ?o0LO&d%;
z=-u2vjp7EETj_BVK~7+0CMgO~J;W`%pFC@Bu#QXuamK=V<*>7Jw+_DV7f;UX2{GY2
ze|hls)sEqP9S6=4#T|c`K?;J)OqvN7hez%@7-~&4tl};f=;~4JInD2
z(E%%_VeXDU?%B!aWPXb%8vEF`x_zXU6HZDxk{H9LM=h3_k6MgGRxO?C6n)gvc7MFH
zuI`YPGNFnUpA=kgu<5A1{;P;hY*M$bz3}dqmg3N>gp5(FQidMMnvt~DODLsJQgn^?
zeqGU{U3~zxUP7cO7H&R&d>f(Tc(p0`s;Xq>S>Jmt#e~b6*41a?jf8|!7JpgQQRikw
zqmHMOrUcV%D(~;3(s0TjR7vpp2WCo&M>$wA#*S{BE>X7*KxrZOM{X2N_cgr&MGd`m
z;C$6G#qY38`AZ5YIvs#97l!wn$x9xpBf3K)+D`yZ5uKU%JOj1TU_#kW!0FBOjVMX=
zm^$Je@s|OjrS~nkR3CY9dO5VEU!}p9pWvm1OIFiU7Eg;`(u9NbtkoOim&6~qv~AF0
z^5}V+wv52rn=3YzpQYAutv@2nx^eTeavk$qiRJ6TuS9jeP|dh`&8W>Carpis4@tM%
ztKiEX0aa0NH5Pp)SDcjn-yK>kt3f*?YENyJe#2PpAzRq&5?+cu`(@G`3V~Nv
zrHlR9%PZD5U8!fktf|eyLKCZ2bbEFGhuuB+>X(+nOUu-bip3SJ{wX}2bNb{*!%ymFn8{Kar}xh4nj8`}Y?9m9GDL3;&W_e^=pOlIw3G
z|M7n8x2E&^UMO<~DI@azKY&utG;uW`l*K6q6v^};lR3F4D*&1-*m12I^z9mcATLy)
zUb)QLArt^Yjel9+0R&+Gnb04c`J~U8-zo+$&a36GCN>^PgmDN$+R8HJjeP$(?X~M}
zX_QX}-pcn!=!2qy?^hL)t{h<@gsbTD&HK-I8M*`%hju?A&d6)FX_VG_6yi_VEC_6^
z7;`e?T=HXEd)EMT#Il~Ro&!bqbsfm){=hm+&n7PhIx$XP2Yb6kc1`wxd?4j&Bzz&K
z7o~Z4a0vE5v<+2m
ze3KGtX!X-w*2jd{hy$Gu?*-Z^IOLyK*W~G{Ncwnz9tsXQH`F!9{dKozKG_j~@(EaX
zI2>|n9C>&xyG>maFXysQG)7xEK&gM5S4mioyCG%Mk$NkuWIR>V?
zZle^b%)mth&;Mz3#
Date: Wed, 21 Feb 2024 16:33:40 +0400
Subject: [PATCH 02/11] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?=
=?UTF-8?q?=D1=82=D0=B0=D0=BB=20SetPosition=20=D0=B8=20SetPictureSize?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ProjectLiner/ProjectLiner/DrawningLiner.cs | 54 ++++++++++++++-----
.../ProjectLiner/FormLiner.Designer.cs | 2 +
2 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/ProjectLiner/ProjectLiner/DrawningLiner.cs b/ProjectLiner/ProjectLiner/DrawningLiner.cs
index 76d0856..d5023a3 100644
--- a/ProjectLiner/ProjectLiner/DrawningLiner.cs
+++ b/ProjectLiner/ProjectLiner/DrawningLiner.cs
@@ -33,7 +33,7 @@ public class DrawningLiner
///
/// Ширина прорисовки лайнера
///
- private readonly int _drawningLinerWidth = 180;
+ private readonly int _drawningLinerWidth = 150;
///
/// Высота прорисовки лайнера
@@ -68,9 +68,29 @@ public class DrawningLiner
/// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах
public bool SetPictureSize(int width, int height)
{
- _pictureWidth = width;
- _pictureHeight = height;
- return true;
+ if (width > _drawningLinerWidth && height > _drawningLinerHeight)
+ {
+ _pictureWidth = width;
+ _pictureHeight = height;
+ if (_startPosX != null && _startPosY != null)
+ {
+ if (_startPosX.Value < 0)
+ _startPosX = 0;
+ if (_startPosY.Value < 0)
+ _startPosY = 0;
+ if (_startPosX.Value + _drawningLinerWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth - _drawningLinerWidth;
+ }
+ if (_startPosY.Value + _drawningLinerHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _drawningLinerHeight;
+ }
+ }
+
+ return true;
+ }
+ return false;
}
///
@@ -84,16 +104,22 @@ public class DrawningLiner
{
return;
}
-
- if (x < 0 || y < 0)
+ else
{
- return;
+ _startPosX = x;
+ _startPosY = y;
+
+ if (_startPosX.Value + _drawningLinerWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth - _drawningLinerWidth;
+ }
+ if (_startPosY.Value + _drawningLinerHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _drawningLinerHeight;
+ }
}
- _startPosX = x;
- _startPosY = y;
}
-
///
/// Изменение направления перемещения
///
@@ -169,7 +195,7 @@ public class DrawningLiner
Point point1 = new Point(_startPosX.Value, _startPosY.Value + 80);
Point point2 = new Point(_startPosX.Value + 50, _startPosY.Value + 130);
Point point3 = new Point(_startPosX.Value + 135, _startPosY.Value + 130);
- Point point4 = new Point(_startPosX.Value + 185, _startPosY.Value + 80);
+ Point point4 = new Point(_startPosX.Value + 155, _startPosY.Value + 80);
Point[] curvePoints = { point1, point2, point3, point4 };
g.FillPolygon(br, curvePoints);
@@ -185,9 +211,9 @@ public class DrawningLiner
// шлюпки
if (EntityLiner.Boats)
{
- g.FillEllipse(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 85, 30, 15);
- g.FillEllipse(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 85, 30, 15);
- g.FillEllipse(additionalBrush, _startPosX.Value + 130, _startPosY.Value + 85, 30, 15);
+ g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 85, 30, 15);
+ g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 85, 30, 15);
+ g.FillEllipse(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 85, 30, 15);
}
// труба
diff --git a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
index e55a740..94eb653 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
@@ -39,6 +39,7 @@
//
// pictureBoxLiner
//
+ pictureBoxLiner.BackColor = SystemColors.Control;
pictureBoxLiner.Dock = DockStyle.Fill;
pictureBoxLiner.Location = new Point(0, 0);
pictureBoxLiner.Name = "pictureBoxLiner";
@@ -48,6 +49,7 @@
//
// buttonCreate
//
+ buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 520);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(150, 82);
--
2.25.1
From bd746e928870a62316697671aa6adaffda9ad5ca Mon Sep 17 00:00:00 2001
From: gettterot
Date: Wed, 21 Feb 2024 16:54:00 +0400
Subject: [PATCH 03/11] =?UTF-8?q?=D0=A1=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB?=
=?UTF-8?q?=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=BC=20=D0=BF?=
=?UTF-8?q?=D0=B5=D1=80=D0=B2=D1=8B=D0=BC=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD?=
=?UTF-8?q?=D0=B8=D0=B5=D0=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ProjectLiner/ProjectLiner/DrawningLiner.cs | 10 ++++++----
ProjectLiner/ProjectLiner/FormLiner.cs | 6 ++++--
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/ProjectLiner/ProjectLiner/DrawningLiner.cs b/ProjectLiner/ProjectLiner/DrawningLiner.cs
index d5023a3..35d42b6 100644
--- a/ProjectLiner/ProjectLiner/DrawningLiner.cs
+++ b/ProjectLiner/ProjectLiner/DrawningLiner.cs
@@ -50,10 +50,9 @@ public class DrawningLiner
/// Признак наличия якоря
/// Признак наличия шлюпок
/// Признак наличия трубы
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool anchor, bool boats, bool pipe)
+ public void Init(EntityLiner liner)
{
- EntityLiner = new EntityLiner();
- EntityLiner.Init(speed, weight, bodyColor, additionalColor, anchor, boats, pipe);
+ EntityLiner = liner;
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
@@ -108,7 +107,10 @@ public class DrawningLiner
{
_startPosX = x;
_startPosY = y;
-
+ if (_startPosX.Value < 0)
+ _startPosX = 0;
+ if (_startPosY.Value < 0)
+ _startPosY = 0;
if (_startPosX.Value + _drawningLinerWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningLinerWidth;
diff --git a/ProjectLiner/ProjectLiner/FormLiner.cs b/ProjectLiner/ProjectLiner/FormLiner.cs
index e370c8b..c72187d 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.cs
@@ -42,11 +42,13 @@ namespace ProjectLiner
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
- _drawningLiner = new DrawningLiner();
- _drawningLiner.Init(random.Next(100, 300), random.Next(1000, 3000),
+ EntityLiner liner = new EntityLiner();
+ liner.Init(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ _drawningLiner = new DrawningLiner();
+ _drawningLiner.Init(liner);
_drawningLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
_drawningLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
--
2.25.1
From 6c4691699b6863b562c036f4715849765ed5e854 Mon Sep 17 00:00:00 2001
From: gettterot
Date: Wed, 6 Mar 2024 07:52:17 +0400
Subject: [PATCH 04/11] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?=
=?UTF-8?q?=D0=B8=D0=B5=20=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB=D1=8C?=
=?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?=
=?UTF-8?q?=D0=B0=20=D0=B4=D0=BB=D1=8F=20entity=20liner?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../{ => Drawnings}/DirectionType.cs | 2 +-
.../DrawningCommonLiner.cs} | 130 ++++++++----------
.../ProjectLiner/Drawnings/DrawningLiner.cs | 72 ++++++++++
.../Entities/EntityCommonLiner.cs | 50 +++++++
.../{ => Entities}/EntityLiner.cs | 31 +----
.../ProjectLiner/FormLiner.Designer.cs | 20 ++-
ProjectLiner/ProjectLiner/FormLiner.cs | 73 +++++++---
7 files changed, 258 insertions(+), 120 deletions(-)
rename ProjectLiner/ProjectLiner/{ => Drawnings}/DirectionType.cs (91%)
rename ProjectLiner/ProjectLiner/{DrawningLiner.cs => Drawnings/DrawningCommonLiner.cs} (60%)
create mode 100644 ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs
create mode 100644 ProjectLiner/ProjectLiner/Entities/EntityCommonLiner.cs
rename ProjectLiner/ProjectLiner/{ => Entities}/EntityLiner.cs (58%)
diff --git a/ProjectLiner/ProjectLiner/DirectionType.cs b/ProjectLiner/ProjectLiner/Drawnings/DirectionType.cs
similarity index 91%
rename from ProjectLiner/ProjectLiner/DirectionType.cs
rename to ProjectLiner/ProjectLiner/Drawnings/DirectionType.cs
index 12c5fb2..cc78a5a 100644
--- a/ProjectLiner/ProjectLiner/DirectionType.cs
+++ b/ProjectLiner/ProjectLiner/Drawnings/DirectionType.cs
@@ -1,4 +1,4 @@
-namespace ProjectLiner;
+namespace ProjectLiner.Drawnings;
///
/// Направление перемещения
diff --git a/ProjectLiner/ProjectLiner/DrawningLiner.cs b/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
similarity index 60%
rename from ProjectLiner/ProjectLiner/DrawningLiner.cs
rename to ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
index 35d42b6..2bc1885 100644
--- a/ProjectLiner/ProjectLiner/DrawningLiner.cs
+++ b/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
@@ -1,14 +1,17 @@
-namespace ProjectLiner;
+using ProjectLiner.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
-///
-/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
-///
-public class DrawningLiner
+namespace ProjectLiner.Drawnings;
+public class DrawningCommonLiner
{
///
/// Класс-сущность
///
- public EntityLiner? EntityLiner { get; private set; }
+ public EntityCommonLiner? EntityCommonLiner { get; protected set; }
///
/// Ширина окна
@@ -23,12 +26,12 @@ public class DrawningLiner
///
/// Левая координата прорисовки лайнера
///
- private int? _startPosX;
+ protected int? _startPosX;
///
/// Верхняя кооридната прорисовки лайнера
///
- private int? _startPosY;
+ protected int? _startPosY;
///
/// Ширина прорисовки лайнера
@@ -38,27 +41,44 @@ public class DrawningLiner
///
/// Высота прорисовки лайнера
///
- private readonly int _drawningLinerHeight = 125;
+ private readonly int _drawningLinerHeight = 90;
///
- /// Инициализация свойств
+ /// Пустой конструктор
///
- /// Скорость
- /// Вес
- /// Основной цвет
- /// Дополнительный цвет
- /// Признак наличия якоря
- /// Признак наличия шлюпок
- /// Признак наличия трубы
- public void Init(EntityLiner liner)
+
+ public DrawningCommonLiner()
{
- EntityLiner = liner;
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
+ ///
+ /// конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+
+ public DrawningCommonLiner(int speed, double weight, Color bodycolor) : this()
+ {
+ EntityCommonLiner = new EntityCommonLiner(speed, weight, bodycolor);
+ }
+
+ ///
+ /// конструктор для наследников
+ ///
+ /// Высота
+ /// Длина
+
+ protected DrawningCommonLiner(int drawningLinerWight, int drawningLinerHeight) : this()
+ {
+ _drawningLinerHeight = drawningLinerHeight;
+ _drawningLinerWidth = drawningLinerWight;
+ }
+
///
/// Установка границ поля
///
@@ -73,7 +93,7 @@ public class DrawningLiner
_pictureHeight = height;
if (_startPosX != null && _startPosY != null)
{
- if (_startPosX.Value < 0)
+ if (_startPosX.Value < 0)
_startPosX = 0;
if (_startPosY.Value < 0)
_startPosY = 0;
@@ -129,7 +149,7 @@ public class DrawningLiner
/// true - перемещене выполнено, false - перемещение невозможно
public bool MoveTransport(DirectionType direction)
{
- if (EntityLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityCommonLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
@@ -138,30 +158,30 @@ public class DrawningLiner
{
//влево
case DirectionType.Left:
- if (_startPosX.Value - EntityLiner.Step > 0)
+ if (_startPosX.Value - EntityCommonLiner.Step > 0)
{
- _startPosX -= (int)EntityLiner.Step;
+ _startPosX -= (int)EntityCommonLiner.Step;
}
return true;
//вверх
case DirectionType.Up:
- if (_startPosY.Value - EntityLiner.Step > 0)
+ if (_startPosY.Value - EntityCommonLiner.Step > 0)
{
- _startPosY -= (int)EntityLiner.Step;
+ _startPosY -= (int)EntityCommonLiner.Step;
}
return true;
// вправо
case DirectionType.Right:
- if (_startPosX.Value + EntityLiner.Step < _pictureWidth-_drawningLinerWidth)
+ if (_startPosX.Value + EntityCommonLiner.Step < _pictureWidth - _drawningLinerWidth)
{
- _startPosX += (int)EntityLiner.Step;
+ _startPosX += (int)EntityCommonLiner.Step;
}
return true;
//вниз
case DirectionType.Down:
- if (_startPosY.Value + EntityLiner.Step < _pictureHeight-_drawningLinerHeight)
+ if (_startPosY.Value + EntityCommonLiner.Step < _pictureHeight - _drawningLinerHeight)
{
- _startPosY += (int)EntityLiner.Step;
+ _startPosY += (int)EntityCommonLiner.Step;
}
return true;
default:
@@ -173,61 +193,33 @@ public class DrawningLiner
/// Прорисовка объекта
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
- if (EntityLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityCommonLiner == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
- Brush additionalBrush = new SolidBrush(EntityLiner.AdditionalColor);
- Brush br = new SolidBrush(EntityLiner.BodyColor);
+ Brush br = new SolidBrush(EntityCommonLiner.BodyColor);
- // якорь
- if (EntityLiner.Anchor)
- {
- g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 85, _startPosX.Value + 45, _startPosY.Value + 115);
- g.DrawLine(pen, _startPosX.Value + 30, _startPosY.Value + 95, _startPosX.Value + 60, _startPosY.Value + 95);
- g.DrawLine(pen, _startPosX.Value + 25, _startPosY.Value + 100, _startPosX.Value + 45, _startPosY.Value + 115);
- g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 115, _startPosX.Value + 65, _startPosY.Value + 100);
- }
// кузов лайнера
- Point point1 = new Point(_startPosX.Value, _startPosY.Value + 80);
- Point point2 = new Point(_startPosX.Value + 50, _startPosY.Value + 130);
- Point point3 = new Point(_startPosX.Value + 135, _startPosY.Value + 130);
- Point point4 = new Point(_startPosX.Value + 155, _startPosY.Value + 80);
+ Point point1 = new Point(_startPosX.Value, _startPosY.Value + 40);
+ Point point2 = new Point(_startPosX.Value + 50, _startPosY.Value + 90);
+ Point point3 = new Point(_startPosX.Value + 135, _startPosY.Value + 90);
+ Point point4 = new Point(_startPosX.Value + 155, _startPosY.Value + 40);
Point[] curvePoints = { point1, point2, point3, point4 };
g.FillPolygon(br, curvePoints);
// борт лайнера
- Point point5 = new Point(_startPosX.Value+40, _startPosY.Value + 40);
- Point point6 = new Point(_startPosX.Value + 140, _startPosY.Value + 40);
- Point point7 = new Point(_startPosX.Value + 140, _startPosY.Value + 80);
- Point point8 = new Point(_startPosX.Value + 40, _startPosY.Value + 80);
+ Point point5 = new Point(_startPosX.Value + 40, _startPosY.Value);
+ Point point6 = new Point(_startPosX.Value + 140, _startPosY.Value);
+ Point point7 = new Point(_startPosX.Value + 140, _startPosY.Value + 40);
+ Point point8 = new Point(_startPosX.Value + 40, _startPosY.Value + 40);
Point[] curvePoints2 = { point5, point6, point7, point8 };
- g.FillPolygon(additionalBrush, curvePoints2);
+ g.FillPolygon(br, curvePoints2);
- // шлюпки
- if (EntityLiner.Boats)
- {
- g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 85, 30, 15);
- g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 85, 30, 15);
- g.FillEllipse(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 85, 30, 15);
- }
-
- // труба
- if (EntityLiner.Pipe)
- {
-
- Point point9 = new Point(_startPosX.Value + 90, _startPosY.Value + 10);
- Point point10 = new Point(_startPosX.Value + 90, _startPosY.Value + 40);
- Point point11 = new Point(_startPosX.Value + 115, _startPosY.Value + 40);
- Point point12 = new Point(_startPosX.Value + 115, _startPosY.Value + 10);
- Point[] curvePoints3 = { point9, point10, point11, point12 };
- g.FillPolygon(br, curvePoints3);
- }
}
}
diff --git a/ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs b/ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs
new file mode 100644
index 0000000..a2ce841
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs
@@ -0,0 +1,72 @@
+using ProjectLiner.Entities;
+
+namespace ProjectLiner.Drawnings;
+
+///
+/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+///
+public class DrawningLiner : DrawningCommonLiner
+{
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия якоря
+ /// Признак наличия шлюпок
+ /// Признак наличия трубы
+ public DrawningLiner(int speed, double weight, Color bodycolor, Color additionalColor, bool anchor, bool boats, bool pipe) : base(150, 125)
+ {
+ EntityCommonLiner = new EntityLiner(speed, weight, bodycolor, additionalColor, anchor, boats, pipe);
+
+ }
+
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityCommonLiner == null || EntityCommonLiner is not EntityLiner liner || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush additionalBrush = new SolidBrush(liner.AdditionalColor);
+ Brush br = new SolidBrush(liner.BodyColor);
+
+ _startPosY += 40;
+ base.DrawTransport(g);
+ _startPosY -= 40;
+
+
+ // якорь
+ if (liner.Anchor)
+ {
+ g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 85, _startPosX.Value + 45, _startPosY.Value + 115);
+ g.DrawLine(pen, _startPosX.Value + 30, _startPosY.Value + 95, _startPosX.Value + 60, _startPosY.Value + 95);
+ g.DrawLine(pen, _startPosX.Value + 25, _startPosY.Value + 100, _startPosX.Value + 45, _startPosY.Value + 115);
+ g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 115, _startPosX.Value + 65, _startPosY.Value + 100);
+ }
+
+ // шлюпки
+ if (liner.Boats)
+ {
+ g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 85, 30, 15);
+ g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 85, 30, 15);
+ g.FillEllipse(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 85, 30, 15);
+ }
+
+ // труба
+ if (liner.Pipe)
+ {
+
+ Point point9 = new Point(_startPosX.Value + 90, _startPosY.Value + 10);
+ Point point10 = new Point(_startPosX.Value + 90, _startPosY.Value + 40);
+ Point point11 = new Point(_startPosX.Value + 115, _startPosY.Value + 40);
+ Point point12 = new Point(_startPosX.Value + 115, _startPosY.Value + 10);
+ Point[] curvePoints3 = { point9, point10, point11, point12 };
+ g.FillPolygon(br, curvePoints3);
+ }
+ }
+
+}
diff --git a/ProjectLiner/ProjectLiner/Entities/EntityCommonLiner.cs b/ProjectLiner/ProjectLiner/Entities/EntityCommonLiner.cs
new file mode 100644
index 0000000..bb99401
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/Entities/EntityCommonLiner.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+///
+/// Класс-сущность обычного "Лайнера"
+///
+
+namespace ProjectLiner.Entities
+{
+ public class EntityCommonLiner
+ {
+ ///
+ /// Скорость
+ ///
+ public int Speed { get; private set; }
+
+ ///
+ /// Вес
+ ///
+ public double Weight { get; private set; }
+
+ ///
+ /// Основной цвет
+ ///
+ public Color BodyColor { get; private set; }
+
+ ///
+ /// Шаг перемещения автомобиля
+ ///
+ public double Step => Speed * 100 / Weight;
+
+ ///
+ /// Конструктор лайнера
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Основной цвет
+
+ public EntityCommonLiner(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+
+ }
+ }
+}
diff --git a/ProjectLiner/ProjectLiner/EntityLiner.cs b/ProjectLiner/ProjectLiner/Entities/EntityLiner.cs
similarity index 58%
rename from ProjectLiner/ProjectLiner/EntityLiner.cs
rename to ProjectLiner/ProjectLiner/Entities/EntityLiner.cs
index 66d27c1..18a65d3 100644
--- a/ProjectLiner/ProjectLiner/EntityLiner.cs
+++ b/ProjectLiner/ProjectLiner/Entities/EntityLiner.cs
@@ -1,24 +1,10 @@
-namespace ProjectLiner;
+namespace ProjectLiner.Entities;
///
/// Класс-сущность "Лайнер"
///
-public class EntityLiner
+public class EntityLiner: EntityCommonLiner
{
- ///
- /// Скорость
- ///
- public int Speed { get; private set; }
-
- ///
- /// Вес
- ///
- public double Weight { get; private set; }
-
- ///
- /// Основной цвет
- ///
- public Color BodyColor { get; private set; }
///
/// Дополнительный цвет (для опциональных элементов)
@@ -40,26 +26,17 @@ public class EntityLiner
///
public bool Pipe { get; private set; }
- ///
- /// Шаг перемещения автомобиля
- ///
- public double Step => Speed * 100 / Weight;
///
/// Инициализация полей объекта-класса спортивного автомобиля
///
- /// Скорость
- /// Вес автомобиля
- /// Основной цвет
/// Дополнительный цвет
/// Признак наличия якоря
/// Признак наличия шлюпок
/// Признак наличия трубы
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool anchor, bool boats, bool pipe)
+ public EntityLiner(int speed, double weight, Color bodyColor, Color additionalColor, bool anchor, bool boats, bool pipe) : base(speed, weight, bodyColor)
{
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
+ new EntityCommonLiner(speed, weight, bodyColor);
AdditionalColor = additionalColor;
Anchor = anchor;
Boats = boats;
diff --git a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
index 94eb653..2806d52 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
@@ -34,6 +34,7 @@
buttonUp = new Button();
buttonLeft = new Button();
buttonRight = new Button();
+ buttonCreateCommonLiner = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
SuspendLayout();
//
@@ -50,11 +51,11 @@
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 520);
+ buttonCreate.Location = new Point(12, 544);
buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(150, 82);
+ buttonCreate.Size = new Size(203, 58);
buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать";
+ buttonCreate.Text = "Создать Лайнер";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
@@ -106,11 +107,23 @@
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
+ // buttonCreateCommonLiner
+ //
+ buttonCreateCommonLiner.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateCommonLiner.Location = new Point(221, 544);
+ buttonCreateCommonLiner.Name = "buttonCreateCommonLiner";
+ buttonCreateCommonLiner.Size = new Size(240, 58);
+ buttonCreateCommonLiner.TabIndex = 6;
+ buttonCreateCommonLiner.Text = "Создать Обычный Лайнер";
+ buttonCreateCommonLiner.UseVisualStyleBackColor = true;
+ buttonCreateCommonLiner.Click += buttonCreateCommonLiner_Click;
+ //
// FormLiner
//
AutoScaleDimensions = new SizeF(11F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(948, 614);
+ Controls.Add(buttonCreateCommonLiner);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
@@ -131,5 +144,6 @@
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;
+ private Button buttonCreateCommonLiner;
}
}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormLiner.cs b/ProjectLiner/ProjectLiner/FormLiner.cs
index c72187d..8597fce 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.cs
@@ -7,12 +7,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using ProjectLiner.Drawnings;
namespace ProjectLiner
{
public partial class FormLiner : Form
{
- private DrawningLiner? _drawningLiner;
+ private DrawningCommonLiner? _drawningCommonLiner;
public FormLiner()
{
InitializeComponent();
@@ -23,35 +24,66 @@ namespace ProjectLiner
///
private void Draw()
{
- if (_drawningLiner == null)
+ if (_drawningCommonLiner == null)
{
return;
}
Bitmap bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningLiner.DrawTransport(gr);
+ _drawningCommonLiner.DrawTransport(gr);
pictureBoxLiner.Image = bmp;
}
///
- /// Обработка нажатия кнопки "Создать"
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ Random random = new();
+ switch (type)
+ {
+ case nameof(DrawningCommonLiner):
+ _drawningCommonLiner = new DrawningCommonLiner(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
+ break;
+ case nameof(DrawningLiner):
+ _drawningCommonLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+
+ }
+
+ _drawningCommonLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
+ _drawningCommonLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
+
+ Draw();
+ }
+
+ ///
+ /// Обработка нажатия кнопки "Создать Лайнер"
///
///
///
private void buttonCreate_Click(object sender, EventArgs e)
{
- Random random = new();
- EntityLiner liner = new EntityLiner();
- liner.Init(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
- _drawningLiner = new DrawningLiner();
- _drawningLiner.Init(liner);
- _drawningLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
- _drawningLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
- Draw();
+ CreateObject(nameof(DrawningLiner));
+ }
+
+ ///
+ /// Обработка нажатия кнопки "Создать Обычный Лайнер"
+ ///
+ ///
+ ///
+
+ private void buttonCreateCommonLiner_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningCommonLiner));
}
///
@@ -61,7 +93,7 @@ namespace ProjectLiner
///
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_drawningLiner == null)
+ if (_drawningCommonLiner == null)
{
return;
}
@@ -71,16 +103,16 @@ namespace ProjectLiner
switch (name)
{
case "buttonUp":
- result = _drawningLiner.MoveTransport(DirectionType.Up);
+ result = _drawningCommonLiner.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- result = _drawningLiner.MoveTransport(DirectionType.Down);
+ result = _drawningCommonLiner.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- result = _drawningLiner.MoveTransport(DirectionType.Left);
+ result = _drawningCommonLiner.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
- result = _drawningLiner.MoveTransport(DirectionType.Right);
+ result = _drawningCommonLiner.MoveTransport(DirectionType.Right);
break;
}
@@ -89,5 +121,6 @@ namespace ProjectLiner
Draw();
}
}
+
}
}
--
2.25.1
From ecfe3f3131795c7eb4b6f126e3e20de3b27862a8 Mon Sep 17 00:00:00 2001
From: gettterot
Date: Wed, 6 Mar 2024 09:38:21 +0400
Subject: [PATCH 05/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?=
=?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3?=
=?UTF-8?q?=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC?=
=?UTF-8?q?=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=20=D1=86=D0=B5?=
=?UTF-8?q?=D0=BD=D1=82=D1=80=D1=83=20=D0=B8=20=D0=BA=20=D0=BA=D1=80=D0=B0?=
=?UTF-8?q?=D1=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ProjectLiner/Drawnings/DirectionType.cs | 5 +
.../Drawnings/DrawningCommonLiner.cs | 20 +++
.../ProjectLiner/Drawnings/DrawningLiner.cs | 4 +-
.../ProjectLiner/FormLiner.Designer.cs | 26 ++++
ProjectLiner/ProjectLiner/FormLiner.cs | 49 +++++-
.../MovementStrategy/AbstractStrategy.cs | 145 ++++++++++++++++++
.../MovementStrategy/IMoveableObjectcs.cs | 30 ++++
.../MovementStrategy/MoveToBorder.cs | 58 +++++++
.../MovementStrategy/MoveToCenter.cs | 60 ++++++++
.../MovementStrategy/MoveableLiner.cs | 69 +++++++++
.../MovementStrategy/MovementDirection.cs | 30 ++++
.../MovementStrategy/ObjectParameters.cs | 78 ++++++++++
.../MovementStrategy/StrategyStatus.cs | 27 ++++
13 files changed, 598 insertions(+), 3 deletions(-)
create mode 100644 ProjectLiner/ProjectLiner/MovementStrategy/AbstractStrategy.cs
create mode 100644 ProjectLiner/ProjectLiner/MovementStrategy/IMoveableObjectcs.cs
create mode 100644 ProjectLiner/ProjectLiner/MovementStrategy/MoveToBorder.cs
create mode 100644 ProjectLiner/ProjectLiner/MovementStrategy/MoveToCenter.cs
create mode 100644 ProjectLiner/ProjectLiner/MovementStrategy/MoveableLiner.cs
create mode 100644 ProjectLiner/ProjectLiner/MovementStrategy/MovementDirection.cs
create mode 100644 ProjectLiner/ProjectLiner/MovementStrategy/ObjectParameters.cs
create mode 100644 ProjectLiner/ProjectLiner/MovementStrategy/StrategyStatus.cs
diff --git a/ProjectLiner/ProjectLiner/Drawnings/DirectionType.cs b/ProjectLiner/ProjectLiner/Drawnings/DirectionType.cs
index cc78a5a..bca182c 100644
--- a/ProjectLiner/ProjectLiner/Drawnings/DirectionType.cs
+++ b/ProjectLiner/ProjectLiner/Drawnings/DirectionType.cs
@@ -5,6 +5,11 @@
///
public enum DirectionType
{
+ ///
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
+
///
/// Вверх
///
diff --git a/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs b/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
index 2bc1885..f3e6fe6 100644
--- a/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
+++ b/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
@@ -43,6 +43,26 @@ public class DrawningCommonLiner
///
private readonly int _drawningLinerHeight = 90;
+ ///
+ /// Координата X объекта
+ ///
+ public int? GetPosX => _startPosX;
+
+ ///
+ /// Координата Y объекта
+ ///
+ public int? GetPosY => _startPosY;
+
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningLinerWidth;
+
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningLinerHeight;
+
///
/// Пустой конструктор
///
diff --git a/ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs b/ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs
index a2ce841..46a4021 100644
--- a/ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs
+++ b/ProjectLiner/ProjectLiner/Drawnings/DrawningLiner.cs
@@ -12,7 +12,7 @@ public class DrawningLiner : DrawningCommonLiner
///
/// Скорость
/// Вес
- /// Основной цвет
+ /// Основной цвет
/// Дополнительный цвет
/// Признак наличия якоря
/// Признак наличия шлюпок
@@ -65,7 +65,7 @@ public class DrawningLiner : DrawningCommonLiner
Point point11 = new Point(_startPosX.Value + 115, _startPosY.Value + 40);
Point point12 = new Point(_startPosX.Value + 115, _startPosY.Value + 10);
Point[] curvePoints3 = { point9, point10, point11, point12 };
- g.FillPolygon(br, curvePoints3);
+ g.FillPolygon(additionalBrush, curvePoints3);
}
}
diff --git a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
index 2806d52..c21ee63 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
@@ -35,6 +35,8 @@
buttonLeft = new Button();
buttonRight = new Button();
buttonCreateCommonLiner = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
SuspendLayout();
//
@@ -118,11 +120,33 @@
buttonCreateCommonLiner.UseVisualStyleBackColor = true;
buttonCreateCommonLiner.Click += buttonCreateCommonLiner_Click;
//
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
+ comboBoxStrategy.Location = new Point(742, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(194, 33);
+ comboBoxStrategy.TabIndex = 11;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(816, 51);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(120, 37);
+ buttonStrategyStep.TabIndex = 12;
+ buttonStrategyStep.Text = "Шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += buttonStrategyStep_Click;
+ //
// FormLiner
//
AutoScaleDimensions = new SizeF(11F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(948, 614);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateCommonLiner);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
@@ -145,5 +169,7 @@
private Button buttonLeft;
private Button buttonRight;
private Button buttonCreateCommonLiner;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormLiner.cs b/ProjectLiner/ProjectLiner/FormLiner.cs
index 8597fce..aa13498 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.cs
@@ -8,15 +8,19 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectLiner.Drawnings;
+using ProjectLiner.MovementStrategy;
namespace ProjectLiner
{
public partial class FormLiner : Form
{
private DrawningCommonLiner? _drawningCommonLiner;
+
+ private AbstractStrategy? _strategy;
public FormLiner()
{
InitializeComponent();
+ _strategy = null;
}
///
@@ -61,7 +65,8 @@ namespace ProjectLiner
_drawningCommonLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
_drawningCommonLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
-
+ _strategy = null;
+ comboBoxStrategy.Enabled = true;
Draw();
}
@@ -122,5 +127,47 @@ namespace ProjectLiner
}
}
+ ///
+ /// Обработка нажатия кнопки "Шаг"
+ ///
+ ///
+ ///
+ private void buttonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningCommonLiner == null)
+ {
+ return;
+ }
+
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(new MoveableLiner(_drawningCommonLiner), pictureBoxLiner.Width, pictureBoxLiner.Height);
+ }
+
+ if (_strategy == null)
+ {
+ return;
+ }
+
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
}
}
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/AbstractStrategy.cs b/ProjectLiner/ProjectLiner/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..ca37c66
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,145 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+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() { return _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 (IsTargetDestination())
+ {
+ _state = StrategyStatus.Finish;
+ return;
+ }
+
+ MoveToTarget();
+ }
+
+ ///
+ /// Перемещение влево
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveLeft() => MoveTo(MovementDirection.Left);
+
+ ///
+ /// Перемещение вправо
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveRight() => MoveTo(MovementDirection.Right);
+
+ ///
+ /// Перемещение вверх
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveUp() => MoveTo(MovementDirection.Up);
+
+ ///
+ /// Перемещение вниз
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ 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 IsTargetDestination();
+
+ ///
+ /// Попытка перемещения в требуемом направлении
+ ///
+ /// Направление
+ /// Результат попытки (true - удалось, false - неудача)
+ private bool MoveTo(MovementDirection movementDirection)
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return false;
+ }
+
+ return _moveableObject?.TryMoveObject(movementDirection) ?? false;
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/IMoveableObjectcs.cs b/ProjectLiner/ProjectLiner/MovementStrategy/IMoveableObjectcs.cs
new file mode 100644
index 0000000..a5ace3f
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/IMoveableObjectcs.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLiner.MovementStrategy;
+
+///
+/// Интерфейс для работы с перемещаемым объектом
+///
+public interface IMoveableObject
+{
+ ///
+ /// Получение координаты объекта
+ ///
+ ObjectParameters? GetObjectPosition { get; }
+
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ /// Направление
+ /// true - объект перемещен, false - перемещение невозможно
+ bool TryMoveObject(MovementDirection direction);
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/MoveToBorder.cs b/ProjectLiner/ProjectLiner/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..37eced3
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLiner.MovementStrategy;
+
+///
+/// Стратегия перемещения объекта к правой нижней границы
+///
+public class MoveToBorder : AbstractStrategy
+{
+ protected override bool IsTargetDestination()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+
+ return objParams.RightBorder <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
+ objParams.DownBorder <= FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
+ }
+
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ int diffX = objParams.RightBorder - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ int diffY = objParams.DownBorder - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+}
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/MoveToCenter.cs b/ProjectLiner/ProjectLiner/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..afe820c
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLiner.MovementStrategy;
+
+///
+/// Стратегия перемещения объекта в центр экрана
+///
+public class MoveToCenter : AbstractStrategy
+{
+ protected override bool IsTargetDestination()
+ {
+ 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();
+ }
+ }
+ }
+}
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/MoveableLiner.cs b/ProjectLiner/ProjectLiner/MovementStrategy/MoveableLiner.cs
new file mode 100644
index 0000000..c87517a
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/MoveableLiner.cs
@@ -0,0 +1,69 @@
+using ProjectLiner.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLiner.MovementStrategy;
+
+///
+/// Класс-реализация IMoveableObject с использованием DrawningCommonLiner
+///
+public class MoveableLiner : IMoveableObject
+{
+ ///
+ /// Поле-объект класса DrawningCommonLiner или его наследника
+ ///
+ private readonly DrawningCommonLiner? _CommonLiner = null;
+
+ ///
+ /// Конструктор
+ ///
+ /// Объект класса DrawningCommonLiner
+ public MoveableLiner(DrawningCommonLiner CommonLiner)
+ {
+ _CommonLiner = CommonLiner;
+ }
+
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_CommonLiner == null || _CommonLiner.EntityCommonLiner == null || !_CommonLiner.GetPosX.HasValue || !_CommonLiner.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(_CommonLiner.GetPosX.Value, _CommonLiner.GetPosY.Value, _CommonLiner.GetWidth, _CommonLiner.GetHeight);
+ }
+ }
+
+ public int GetStep => (int)(_CommonLiner?.EntityCommonLiner?.Step ?? 0);
+
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (_CommonLiner == null || _CommonLiner.EntityCommonLiner == null)
+ {
+ return false;
+ }
+
+ return _CommonLiner.MoveTransport(GetDirectionType(direction));
+ }
+
+ ///
+ /// Конвертация из MovementDirection в DirectionType
+ ///
+ /// MovementDirection
+ /// DirectionType
+ 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.Unknow,
+ };
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/MovementDirection.cs b/ProjectLiner/ProjectLiner/MovementStrategy/MovementDirection.cs
new file mode 100644
index 0000000..3981ef6
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/MovementDirection.cs
@@ -0,0 +1,30 @@
+namespace ProjectLiner.MovementStrategy;
+
+
+
+///
+/// Направление перемещения
+///
+public enum MovementDirection
+{
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+
+ ///
+ /// Влево
+ ///
+ Left = 3,
+
+ ///
+ /// Вправо
+ ///
+ Right = 4
+}
+
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/ObjectParameters.cs b/ProjectLiner/ProjectLiner/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..251aa9a
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLiner.MovementStrategy;
+
+///
+/// Параметры-координаты объекта
+///
+public class ObjectParameters
+{
+ ///
+ /// Координата X
+ ///
+ private readonly int _x;
+
+ ///
+ /// Координата Y
+ ///
+ 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;
+
+ ///
+ /// конструктор
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина объекта
+ /// Высота объекта
+ public ObjectParameters(int x, int y, int width, int height)
+ {
+ _x = x;
+ _y = y;
+ _width = width;
+ _height = height;
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/StrategyStatus.cs b/ProjectLiner/ProjectLiner/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..b221f83
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLiner.MovementStrategy;
+///
+/// Статус выполнения операции перемещения
+///
+public enum StrategyStatus
+{
+ ///
+ /// Все готово к началу
+ ///
+ NotInit,
+
+ ///
+ /// Выполняется
+ ///
+ InProgress,
+
+ ///
+ /// Завершено
+ ///
+ Finish
+}
\ No newline at end of file
--
2.25.1
From f1f6698e1fee6a2d006a12400df5b08df8cb7ae5 Mon Sep 17 00:00:00 2001
From: gettterot
Date: Wed, 6 Mar 2024 09:45:25 +0400
Subject: [PATCH 06/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?=
=?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD?=
=?UTF-8?q?=D1=82=D0=B0=D1=80=D0=B8=D1=8F=20=D0=B2=20DrawningCommonLiner?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs b/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
index f3e6fe6..b47fb35 100644
--- a/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
+++ b/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
@@ -6,6 +6,9 @@ using System.Text;
using System.Threading.Tasks;
namespace ProjectLiner.Drawnings;
+///
+/// Класс, отвечающий за прорисовку и перемещение обычного объекта-сущности
+///
public class DrawningCommonLiner
{
///
@@ -36,7 +39,7 @@ public class DrawningCommonLiner
///
/// Ширина прорисовки лайнера
///
- private readonly int _drawningLinerWidth = 150;
+ private readonly int _drawningLinerWidth = 155;
///
/// Высота прорисовки лайнера
--
2.25.1
From fb4cc240a19c23c1fc6d7ca4efc589d6059815e5 Mon Sep 17 00:00:00 2001
From: gettterot
Date: Fri, 15 Mar 2024 09:36:48 +0400
Subject: [PATCH 07/11] Adding abstract class
---
.../MovementStrategy/IMoveableObjectcs.cs | 10 ++++++++++
.../MovementStrategy/MoveableLiner.cs | 15 ++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/IMoveableObjectcs.cs b/ProjectLiner/ProjectLiner/MovementStrategy/IMoveableObjectcs.cs
index a5ace3f..e2b5686 100644
--- a/ProjectLiner/ProjectLiner/MovementStrategy/IMoveableObjectcs.cs
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/IMoveableObjectcs.cs
@@ -16,6 +16,8 @@ public interface IMoveableObject
///
ObjectParameters? GetObjectPosition { get; }
+ int AnotherStep { set; }
+
///
/// Шаг объекта
///
@@ -27,4 +29,12 @@ public interface IMoveableObject
/// Направление
/// true - объект перемещен, false - перемещение невозможно
bool TryMoveObject(MovementDirection direction);
+
+
+ ///
+ /// ненужный метод
+ ///
+ /// Первое число
+
+ void MegaTurboStep(int value);
}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/MovementStrategy/MoveableLiner.cs b/ProjectLiner/ProjectLiner/MovementStrategy/MoveableLiner.cs
index c87517a..b067010 100644
--- a/ProjectLiner/ProjectLiner/MovementStrategy/MoveableLiner.cs
+++ b/ProjectLiner/ProjectLiner/MovementStrategy/MoveableLiner.cs
@@ -1,4 +1,5 @@
using ProjectLiner.Drawnings;
+using ProjectLiner.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -40,13 +41,20 @@ public class MoveableLiner : IMoveableObject
public int GetStep => (int)(_CommonLiner?.EntityCommonLiner?.Step ?? 0);
+ public int AnotherStep
+ {
+ set
+ {
+ AnotherStep = value;
+ }
+ }
+
public bool TryMoveObject(MovementDirection direction)
{
if (_CommonLiner == null || _CommonLiner.EntityCommonLiner == null)
{
return false;
}
-
return _CommonLiner.MoveTransport(GetDirectionType(direction));
}
@@ -66,4 +74,9 @@ public class MoveableLiner : IMoveableObject
_ => DirectionType.Unknow,
};
}
+
+ public void MegaTurboStep(int value)
+ {
+ AnotherStep = value;
+ }
}
\ No newline at end of file
--
2.25.1
From 359c50745bfc19c79681f2cac128f312eae3bf2c Mon Sep 17 00:00:00 2001
From: gettterot
Date: Tue, 19 Mar 2024 10:26:26 +0400
Subject: [PATCH 08/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?=
=?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD?=
=?UTF-8?q?=D0=B8=D0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 118 +++++++++++
.../ICollectionGenericObjects.cs | 49 +++++
.../LinerSharingService.cs | 74 +++++++
.../MassiveGenericObjects.cs | 111 +++++++++++
.../ProjectLiner/FormLiner.Designer.cs | 66 +++---
ProjectLiner/ProjectLiner/FormLiner.cs | 68 ++-----
.../FormLinerCollection.Designer.cs | 173 ++++++++++++++++
.../ProjectLiner/FormLinerCollection.cs | 188 ++++++++++++++++++
.../ProjectLiner/FormLinerCollection.resx | 120 +++++++++++
ProjectLiner/ProjectLiner/Program.cs | 2 +-
10 files changed, 874 insertions(+), 95 deletions(-)
create mode 100644 ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
create mode 100644 ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
create mode 100644 ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs
create mode 100644 ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
create mode 100644 ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs
create mode 100644 ProjectLiner/ProjectLiner/FormLinerCollection.cs
create mode 100644 ProjectLiner/ProjectLiner/FormLinerCollection.resx
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..1eb7aa1
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,118 @@
+using ProjectLiner.CollectionGenericObjects;
+using ProjectLiner.Drawnings;
+
+namespace ProjectLiner.CollectionGenericObjects
+{
+ ///
+ /// Абстракция компании, хранящий коллекцию лайнеров
+ ///
+ public abstract class AbstractCompany
+ {
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 110;
+
+ ///
+ /// Ширина окна
+ ///
+ protected readonly int _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ protected readonly int _pictureHeight;
+
+ ///
+ /// Коллекция лайнеров
+ ///
+ protected ICollectionGenericObjects? _collection = null;
+
+ ///
+ /// Вычисление максимального количества элементов, который можно разместить в окне
+ ///
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+
+ ///
+ /// Конструктор
+ ///
+ /// Ширина окна
+ /// Высота окна
+ /// Коллекция лайнеров
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ {
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = collection;
+ _collection.SetMaxCount = GetMaxCount;
+ }
+
+ ///
+ /// Перегрузка оператора сложения для класса
+ ///
+ /// Компания
+ /// Добавляемый объект
+ ///
+ public static bool operator +(AbstractCompany company, DrawningCommonLiner Liner)
+ {
+ return company._collection?.Insert(Liner) ?? false;
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static bool operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position) ?? false;
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningCommonLiner? 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)
+ {
+ DrawningCommonLiner? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..9e2ed2f
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,49 @@
+namespace ProjectLiner.CollectionGenericObjects
+{
+ ///
+ /// Интерфейс описания действий для набора хранимых объектов
+ ///
+ /// Параметр: ограничение - ссылочный тип
+ public interface ICollectionGenericObjects
+ where T : class
+ {
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+ bool Insert(T obj);
+
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла удачно, false - вставка не удалась
+ bool Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло удачно, false - удаление не удалось
+ bool Remove(int position);
+
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs
new file mode 100644
index 0000000..0501fa8
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs
@@ -0,0 +1,74 @@
+
+using ProjectLiner.Drawnings;
+using ProjectLiner.CollectionGenericObjects;
+
+namespace ProjectLiner.CollectionGenericObjects;
+
+///
+/// Реализация абстрактной компании - лайнер
+///
+public class LinerSharingService : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ /// Ширина
+ /// Высота
+ /// Коллекция
+ public LinerSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackgound(Graphics g)
+ {
+
+ int count_width = _pictureWidth / _placeSizeWidth; // кол-во мест в ширину
+ int count_height = _pictureHeight / _placeSizeHeight;
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < count_width; i++)
+ {
+ for (int j = 0; j < count_height + 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 50, j * _placeSizeHeight); // вертикаль
+ g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + 10, j * _placeSizeHeight + _placeSizeHeight);
+ }
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+ int positionWidth = 0;
+ int positionHeight = height - 1;
+
+ if (_collection?.Count != null)
+ {
+ for (int i = 0; i < (_collection.Count); i++)
+ {
+ if (_collection.Get(i) != null)
+ {
+ _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i).SetPosition(_placeSizeWidth * positionWidth + 25, positionHeight * _placeSizeHeight + 10);
+ }
+
+ if (positionWidth < width - 1)
+ {
+ positionWidth++;
+ }
+
+ else
+ {
+ positionWidth = 0;
+ positionHeight--;
+ }
+ if (positionHeight < 0)
+ {
+ return;
+ }
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..9865dd0
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,111 @@
+using ProjectLiner.CollectionGenericObjects;
+
+namespace ProjectLiner.CollectionGenericObjects
+{
+ ///
+ /// Параметризованный набор объектов
+ ///
+ /// Параметр: ограничение - ссылочный тип
+ public class MassiveGenericObjects : ICollectionGenericObjects
+ 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 MassiveGenericObjects()
+ {
+ _collection = Array.Empty();
+ }
+
+ public T? Get(int position)
+ {
+ if (position < 0 || position >= Count)
+ return null;
+ return _collection[position];
+ }
+
+ public bool Insert(T obj)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public bool Insert(T obj, int position)
+ {
+ if (position < 0 || position >= Count)
+ return false;
+
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return true;
+ }
+
+ int temp = position + 1;
+ while (temp < Count)
+ {
+ if (_collection[temp] == null)
+ {
+ _collection[temp] = obj;
+ return true;
+ }
+ temp++;
+ }
+
+ temp = position - 1;
+ while (temp > 0)
+ {
+ if (_collection[temp] == null)
+ {
+ _collection[temp] = obj;
+ return true;
+ }
+ temp--;
+ }
+
+ return false;
+ }
+
+ public bool Remove(int position)
+ {
+ if (position < 0 || position >= Count)
+ return false;
+
+ _collection[position] = null;
+
+ return true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
index c21ee63..7dc1072 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxLiner = new PictureBox();
- buttonCreate = new Button();
buttonDown = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonRight = new Button();
- buttonCreateCommonLiner = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
@@ -45,30 +43,21 @@
pictureBoxLiner.BackColor = SystemColors.Control;
pictureBoxLiner.Dock = DockStyle.Fill;
pictureBoxLiner.Location = new Point(0, 0);
+ pictureBoxLiner.Margin = new Padding(5, 5, 5, 5);
pictureBoxLiner.Name = "pictureBoxLiner";
- pictureBoxLiner.Size = new Size(948, 614);
+ pictureBoxLiner.Size = new Size(1465, 1007);
pictureBoxLiner.TabIndex = 0;
pictureBoxLiner.TabStop = false;
//
- // buttonCreate
- //
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 544);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(203, 58);
- buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать Лайнер";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += buttonCreate_Click;
- //
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.bottom;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
- buttonDown.Location = new Point(830, 552);
+ buttonDown.Location = new Point(1283, 905);
+ buttonDown.Margin = new Padding(5, 5, 5, 5);
buttonDown.Name = "buttonDown";
- buttonDown.Size = new Size(50, 50);
+ buttonDown.Size = new Size(77, 82);
buttonDown.TabIndex = 2;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
@@ -78,9 +67,10 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.top;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
- buttonUp.Location = new Point(830, 496);
+ buttonUp.Location = new Point(1283, 813);
+ buttonUp.Margin = new Padding(5, 5, 5, 5);
buttonUp.Name = "buttonUp";
- buttonUp.Size = new Size(50, 50);
+ buttonUp.Size = new Size(77, 82);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
@@ -90,9 +80,10 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- buttonLeft.Location = new Point(774, 552);
+ buttonLeft.Location = new Point(1196, 905);
+ buttonLeft.Margin = new Padding(5, 5, 5, 5);
buttonLeft.Name = "buttonLeft";
- buttonLeft.Size = new Size(50, 50);
+ buttonLeft.Size = new Size(77, 82);
buttonLeft.TabIndex = 4;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
@@ -102,39 +93,31 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
- buttonRight.Location = new Point(886, 552);
+ buttonRight.Location = new Point(1369, 905);
+ buttonRight.Margin = new Padding(5, 5, 5, 5);
buttonRight.Name = "buttonRight";
- buttonRight.Size = new Size(50, 50);
+ buttonRight.Size = new Size(77, 82);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
- // buttonCreateCommonLiner
- //
- buttonCreateCommonLiner.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateCommonLiner.Location = new Point(221, 544);
- buttonCreateCommonLiner.Name = "buttonCreateCommonLiner";
- buttonCreateCommonLiner.Size = new Size(240, 58);
- buttonCreateCommonLiner.TabIndex = 6;
- buttonCreateCommonLiner.Text = "Создать Обычный Лайнер";
- buttonCreateCommonLiner.UseVisualStyleBackColor = true;
- buttonCreateCommonLiner.Click += buttonCreateCommonLiner_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
- comboBoxStrategy.Location = new Point(742, 12);
+ comboBoxStrategy.Location = new Point(1147, 20);
+ comboBoxStrategy.Margin = new Padding(5, 5, 5, 5);
comboBoxStrategy.Name = "comboBoxStrategy";
- comboBoxStrategy.Size = new Size(194, 33);
+ comboBoxStrategy.Size = new Size(298, 49);
comboBoxStrategy.TabIndex = 11;
//
// buttonStrategyStep
//
- buttonStrategyStep.Location = new Point(816, 51);
+ buttonStrategyStep.Location = new Point(1261, 84);
+ buttonStrategyStep.Margin = new Padding(5, 5, 5, 5);
buttonStrategyStep.Name = "buttonStrategyStep";
- buttonStrategyStep.Size = new Size(120, 37);
+ buttonStrategyStep.Size = new Size(185, 61);
buttonStrategyStep.TabIndex = 12;
buttonStrategyStep.Text = "Шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
@@ -142,18 +125,17 @@
//
// FormLiner
//
- AutoScaleDimensions = new SizeF(11F, 25F);
+ AutoScaleDimensions = new SizeF(17F, 41F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(948, 614);
+ ClientSize = new Size(1465, 1007);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateCommonLiner);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(buttonDown);
- Controls.Add(buttonCreate);
Controls.Add(pictureBoxLiner);
+ Margin = new Padding(5, 5, 5, 5);
Name = "FormLiner";
Text = "Лайнер";
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).EndInit();
@@ -163,12 +145,10 @@
#endregion
private PictureBox pictureBoxLiner;
- private Button buttonCreate;
private Button buttonDown;
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;
- private Button buttonCreateCommonLiner;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectLiner/ProjectLiner/FormLiner.cs b/ProjectLiner/ProjectLiner/FormLiner.cs
index aa13498..683457a 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.cs
@@ -23,6 +23,23 @@ namespace ProjectLiner
_strategy = null;
}
+
+ ///
+ /// Стратегия перемещения
+ ///
+
+ public DrawningLiner SetLiner
+ {
+ set
+ {
+ _drawningCommonLiner = value;
+ _drawningCommonLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
///
/// Метод прорисовки лайнера
///
@@ -39,57 +56,6 @@ namespace ProjectLiner
pictureBoxLiner.Image = bmp;
}
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningCommonLiner):
- _drawningCommonLiner = new DrawningCommonLiner(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
- break;
- case nameof(DrawningLiner):
- _drawningCommonLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
- break;
- default:
- return;
-
- }
-
- _drawningCommonLiner.SetPictureSize(pictureBoxLiner.Width, pictureBoxLiner.Height);
- _drawningCommonLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
- ///
- /// Обработка нажатия кнопки "Создать Лайнер"
- ///
- ///
- ///
- private void buttonCreate_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawningLiner));
- }
-
- ///
- /// Обработка нажатия кнопки "Создать Обычный Лайнер"
- ///
- ///
- ///
-
- private void buttonCreateCommonLiner_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawningCommonLiner));
- }
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs
new file mode 100644
index 0000000..1aeb63b
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs
@@ -0,0 +1,173 @@
+namespace ProjectLiner
+{
+ partial class FormLinerCollection
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ groupBoxTools = new GroupBox();
+ buttonRefresh = new Button();
+ buttonGoToCheck = new Button();
+ buttonRemoveLiner = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddCommonLiner = new Button();
+ buttonAddLiner = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGoToCheck);
+ groupBoxTools.Controls.Add(buttonRemoveLiner);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddCommonLiner);
+ groupBoxTools.Controls.Add(buttonAddLiner);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(1053, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(272, 845);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(33, 683);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(217, 76);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonGoToCheck.Location = new Point(33, 562);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(217, 76);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveLiner
+ //
+ buttonRemoveLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveLiner.Location = new Point(33, 416);
+ buttonRemoveLiner.Name = "buttonRemoveLiner";
+ buttonRemoveLiner.Size = new Size(217, 76);
+ buttonRemoveLiner.TabIndex = 4;
+ buttonRemoveLiner.Text = "Удаление Лайнера";
+ buttonRemoveLiner.UseVisualStyleBackColor = true;
+ buttonRemoveLiner.Click += ButtonRemoveLiner_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(33, 363);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(217, 47);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddCommonLiner
+ //
+ buttonAddCommonLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddCommonLiner.Location = new Point(33, 236);
+ buttonAddCommonLiner.Name = "buttonAddCommonLiner";
+ buttonAddCommonLiner.Size = new Size(217, 76);
+ buttonAddCommonLiner.TabIndex = 2;
+ buttonAddCommonLiner.Text = "Добавление Обычного Лайнера";
+ buttonAddCommonLiner.UseVisualStyleBackColor = true;
+ buttonAddCommonLiner.Click += ButtonAddCommonLiner_Click;
+ //
+ // buttonAddLiner
+ //
+ buttonAddLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddLiner.Location = new Point(33, 126);
+ buttonAddLiner.Name = "buttonAddLiner";
+ buttonAddLiner.Size = new Size(217, 76);
+ buttonAddLiner.TabIndex = 1;
+ buttonAddLiner.Text = "Добавление Лайнера";
+ buttonAddLiner.UseVisualStyleBackColor = true;
+ buttonAddLiner.Click += ButtonAddLiner_Click;
+ //
+ // comboBoxSelectorCompany
+ //
+ comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectorCompany.FormattingEnabled = true;
+ comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
+ comboBoxSelectorCompany.Location = new Point(18, 46);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(242, 49);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // pictureBox
+ //
+ pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Location = new Point(0, 0);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(1053, 845);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormLinerCollection
+ //
+ AutoScaleDimensions = new SizeF(17F, 41F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1325, 845);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormLinerCollection";
+ Text = "Коллекция автомобилей";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private Button buttonAddLiner;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddCommonLiner;
+ private PictureBox pictureBox;
+ private Button buttonGoToCheck;
+ private Button buttonRemoveLiner;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonRefresh;
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
new file mode 100644
index 0000000..38bb839
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
@@ -0,0 +1,188 @@
+using ProjectLiner.CollectionGenericObjects;
+using ProjectLiner.Drawnings;
+using System.Windows.Forms;
+
+namespace ProjectLiner
+{
+ ///
+ /// Форма работы с компанией и ее коллекцией
+ ///
+ public partial class FormLinerCollection : Form
+ {
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormLinerCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new LinerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ Random random = new();
+ DrawningCommonLiner drawingLiner;
+ switch (type)
+ {
+ case nameof(DrawningCommonLiner):
+ drawingLiner = new DrawningCommonLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningLiner):
+ drawingLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawingLiner)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ ///
+ /// Получение цвета
+ ///
+ /// Генератор случайных чисел
+ ///
+ private static Color GetColor(Random random)
+ {
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
+ return color;
+ }
+
+ ///
+ /// Добавление обычного лайнер
+ ///
+ ///
+ ///
+ private void ButtonAddCommonLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCommonLiner));
+
+ ///
+ /// Добавление лайнера
+ ///
+ ///
+ ///
+ private void ButtonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner));
+
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveLiner_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_company - pos)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawningCommonLiner? liner = null;
+ int counter = 100;
+ while (liner == null)
+ {
+ liner = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (liner == null)
+ {
+ return;
+ }
+
+ FormLiner form = new()
+ {
+ SetLiner = (DrawningLiner)liner
+ };
+ form.ShowDialog();
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+ }
+ }
+}
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.resx b/ProjectLiner/ProjectLiner/FormLinerCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/Program.cs b/ProjectLiner/ProjectLiner/Program.cs
index b3dc92e..e3f64ca 100644
--- a/ProjectLiner/ProjectLiner/Program.cs
+++ b/ProjectLiner/ProjectLiner/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectLiner
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormLiner());
+ Application.Run(new FormLinerCollection());
}
}
}
\ No newline at end of file
--
2.25.1
From dac8a3ec17177b0c4414f7b6c2a347da9f021789 Mon Sep 17 00:00:00 2001
From: gettterot
Date: Wed, 20 Mar 2024 08:23:41 +0400
Subject: [PATCH 09/11] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?=
=?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?=
=?UTF-8?q?=20=D1=81=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA?=
=?UTF-8?q?=D0=BE=D0=B9=20sharing?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 3 +-
.../LinerSharingService.cs | 64 ++++++++-----------
.../MassiveGenericObjects.cs | 3 +-
.../Drawnings/DrawningCommonLiner.cs | 6 +-
.../ProjectLiner/FormLiner.Designer.cs | 16 ++---
ProjectLiner/ProjectLiner/FormLiner.cs | 2 +-
.../ProjectLiner/FormLinerCollection.cs | 4 +-
7 files changed, 41 insertions(+), 57 deletions(-)
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
index 1eb7aa1..0e550fc 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
@@ -1,5 +1,4 @@
-using ProjectLiner.CollectionGenericObjects;
-using ProjectLiner.Drawnings;
+using ProjectLiner.Drawnings;
namespace ProjectLiner.CollectionGenericObjects
{
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs
index 0501fa8..ad2d528 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/LinerSharingService.cs
@@ -1,6 +1,4 @@
-
-using ProjectLiner.Drawnings;
-using ProjectLiner.CollectionGenericObjects;
+using ProjectLiner.Drawnings;
namespace ProjectLiner.CollectionGenericObjects;
@@ -15,60 +13,52 @@ public class LinerSharingService : AbstractCompany
/// Ширина
/// Высота
/// Коллекция
- public LinerSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ public LinerSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackgound(Graphics g)
{
-
- int count_width = _pictureWidth / _placeSizeWidth; // кол-во мест в ширину
- int count_height = _pictureHeight / _placeSizeHeight;
- Pen pen = new(Color.Black, 3);
- for (int i = 0; i < count_width; i++)
+ Pen pen = new(Color.Black, 4);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
- for (int j = 0; j < count_height + 1; ++j)
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
- g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 50, j * _placeSizeHeight); // вертикаль
- g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + 10, j * _placeSizeHeight + _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth, (int)(j * _placeSizeHeight * 1.3),
+ i * _placeSizeWidth + _placeSizeWidth - 40, (int)(j * _placeSizeHeight * 1.3));
}
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
+
protected override void SetObjectsPosition()
{
-
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
- int positionWidth = 0;
- int positionHeight = height - 1;
- if (_collection?.Count != null)
+ int curWidth = width - 1;
+ int curHeight = 0;
+
+ for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
- for (int i = 0; i < (_collection.Count); i++)
+ if (_collection?.Get(i) != null)
{
- if (_collection.Get(i) != null)
- {
- _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
- _collection.Get(i).SetPosition(_placeSizeWidth * positionWidth + 25, positionHeight * _placeSizeHeight + 10);
- }
+ _collection.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i)?.SetPosition(_placeSizeWidth * curWidth + 10, (int)(curHeight * _placeSizeHeight * 1.3));
+ }
- if (positionWidth < width - 1)
- {
- positionWidth++;
- }
-
- else
- {
- positionWidth = 0;
- positionHeight--;
- }
- if (positionHeight < 0)
- {
- return;
- }
+ if (curWidth > 0)
+ curWidth--;
+ else
+ {
+ curWidth = width - 1;
+ curHeight++;
+ }
+ if (curHeight > height)
+ {
+ return;
}
}
-
}
}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
index 9865dd0..9ed2684 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,5 +1,4 @@
-using ProjectLiner.CollectionGenericObjects;
-
+
namespace ProjectLiner.CollectionGenericObjects
{
///
diff --git a/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs b/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
index b47fb35..ef854f9 100644
--- a/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
+++ b/ProjectLiner/ProjectLiner/Drawnings/DrawningCommonLiner.cs
@@ -1,9 +1,5 @@
using ProjectLiner.Entities;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+
namespace ProjectLiner.Drawnings;
///
diff --git a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
index 7dc1072..8b9984b 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.Designer.cs
@@ -43,7 +43,7 @@
pictureBoxLiner.BackColor = SystemColors.Control;
pictureBoxLiner.Dock = DockStyle.Fill;
pictureBoxLiner.Location = new Point(0, 0);
- pictureBoxLiner.Margin = new Padding(5, 5, 5, 5);
+ pictureBoxLiner.Margin = new Padding(5);
pictureBoxLiner.Name = "pictureBoxLiner";
pictureBoxLiner.Size = new Size(1465, 1007);
pictureBoxLiner.TabIndex = 0;
@@ -55,7 +55,7 @@
buttonDown.BackgroundImage = Properties.Resources.bottom;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(1283, 905);
- buttonDown.Margin = new Padding(5, 5, 5, 5);
+ buttonDown.Margin = new Padding(5);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(77, 82);
buttonDown.TabIndex = 2;
@@ -68,7 +68,7 @@
buttonUp.BackgroundImage = Properties.Resources.top;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(1283, 813);
- buttonUp.Margin = new Padding(5, 5, 5, 5);
+ buttonUp.Margin = new Padding(5);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(77, 82);
buttonUp.TabIndex = 3;
@@ -81,7 +81,7 @@
buttonLeft.BackgroundImage = Properties.Resources.left;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(1196, 905);
- buttonLeft.Margin = new Padding(5, 5, 5, 5);
+ buttonLeft.Margin = new Padding(5);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(77, 82);
buttonLeft.TabIndex = 4;
@@ -94,7 +94,7 @@
buttonRight.BackgroundImage = Properties.Resources.right;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(1369, 905);
- buttonRight.Margin = new Padding(5, 5, 5, 5);
+ buttonRight.Margin = new Padding(5);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(77, 82);
buttonRight.TabIndex = 5;
@@ -107,7 +107,7 @@
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
comboBoxStrategy.Location = new Point(1147, 20);
- comboBoxStrategy.Margin = new Padding(5, 5, 5, 5);
+ comboBoxStrategy.Margin = new Padding(5);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(298, 49);
comboBoxStrategy.TabIndex = 11;
@@ -115,7 +115,7 @@
// buttonStrategyStep
//
buttonStrategyStep.Location = new Point(1261, 84);
- buttonStrategyStep.Margin = new Padding(5, 5, 5, 5);
+ buttonStrategyStep.Margin = new Padding(5);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(185, 61);
buttonStrategyStep.TabIndex = 12;
@@ -135,7 +135,7 @@
Controls.Add(buttonUp);
Controls.Add(buttonDown);
Controls.Add(pictureBoxLiner);
- Margin = new Padding(5, 5, 5, 5);
+ Margin = new Padding(5);
Name = "FormLiner";
Text = "Лайнер";
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).EndInit();
diff --git a/ProjectLiner/ProjectLiner/FormLiner.cs b/ProjectLiner/ProjectLiner/FormLiner.cs
index 683457a..fbbb11d 100644
--- a/ProjectLiner/ProjectLiner/FormLiner.cs
+++ b/ProjectLiner/ProjectLiner/FormLiner.cs
@@ -28,7 +28,7 @@ namespace ProjectLiner
/// Стратегия перемещения
///
- public DrawningLiner SetLiner
+ public DrawningCommonLiner SetLiner
{
set
{
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
index 38bb839..56b4370 100644
--- a/ProjectLiner/ProjectLiner/FormLinerCollection.cs
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
@@ -32,7 +32,7 @@ namespace ProjectLiner
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
- _company = new LinerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ _company = new LinerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
break;
}
}
@@ -165,7 +165,7 @@ namespace ProjectLiner
FormLiner form = new()
{
- SetLiner = (DrawningLiner)liner
+ SetLiner = liner
};
form.ShowDialog();
}
--
2.25.1
From 9aec819091d6c5544d4a97e63a53877b8fc5bd63 Mon Sep 17 00:00:00 2001
From: gettterot
Date: Sun, 24 Mar 2024 16:26:53 +0400
Subject: [PATCH 10/11] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C?=
=?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=BA=D1=80=D0=B5=D0=BF=D0=BB?=
=?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=B5=D1=82=D0=BA=D0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 9 +--
.../ICollectionGenericObjects.cs | 6 +-
.../MassiveGenericObjects.cs | 69 +++++++++++--------
.../ProjectLiner/FormLinerCollection.cs | 4 +-
4 files changed, 50 insertions(+), 38 deletions(-)
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
index 0e550fc..5076923 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
@@ -57,9 +57,10 @@ namespace ProjectLiner.CollectionGenericObjects
/// Компания
/// Добавляемый объект
///
- public static bool operator +(AbstractCompany company, DrawningCommonLiner Liner)
+
+ public static int operator +(AbstractCompany company, DrawningCommonLiner airplan)
{
- return company._collection?.Insert(Liner) ?? false;
+ return company._collection.Insert(airplan);
}
///
@@ -68,9 +69,9 @@ namespace ProjectLiner.CollectionGenericObjects
/// Компания
/// Номер удаляемого объекта
///
- public static bool operator -(AbstractCompany company, int position)
+ public static DrawningCommonLiner operator -(AbstractCompany company, int position)
{
- return company._collection?.Remove(position) ?? false;
+ return company._collection.Remove(position);
}
///
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
index 9e2ed2f..776e2ad 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -22,7 +22,7 @@
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj);
+ int Insert(T obj);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -30,14 +30,14 @@
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
/// true - удаление прошло удачно, false - удаление не удалось
- bool Remove(int position);
+ T? Remove(int position);
///
/// Получение объекта по позиции
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
index 9ed2684..f668f85 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -12,7 +12,7 @@ namespace ProjectLiner.CollectionGenericObjects
/// Массив объектов, которые храним
///
private T?[] _collection;
-
+
public int Count => _collection.Length;
public int SetMaxCount
@@ -48,63 +48,74 @@ namespace ProjectLiner.CollectionGenericObjects
return _collection[position];
}
- public bool Insert(T obj)
+ public int Insert(T obj)
{
for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
- return true;
+ return i;
}
}
- return false;
+ return -1;
}
- public bool Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
if (position < 0 || position >= Count)
- return false;
-
- if (_collection[position] == null)
{
- _collection[position] = obj;
- return true;
+ return -1;
}
- int temp = position + 1;
- while (temp < Count)
+ if (_collection[position] != null)
{
- if (_collection[temp] == null)
+ bool pushed = false;
+ for (int index = position + 1; index < Count; index++)
{
- _collection[temp] = obj;
- return true;
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
}
- temp++;
- }
- temp = position - 1;
- while (temp > 0)
- {
- if (_collection[temp] == null)
+ if (!pushed)
{
- _collection[temp] = obj;
- return true;
+ for (int index = position - 1; index >= 0; index--)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+ }
+
+ if (!pushed)
+ {
+ return position;
}
- temp--;
}
- return false;
+ _collection[position] = obj;
+ return position;
}
- public bool Remove(int position)
+ public T? Remove(int position)
{
if (position < 0 || position >= Count)
- return false;
+ {
+ return null;
+ }
+ if (_collection[position] == null) return null;
+
+ T? temp = _collection[position];
_collection[position] = null;
-
- return true;
+ return temp;
}
}
}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
index 56b4370..3e759f4 100644
--- a/ProjectLiner/ProjectLiner/FormLinerCollection.cs
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
@@ -63,7 +63,7 @@ namespace ProjectLiner
return;
}
- if (_company + drawingLiner)
+ if (_company + drawingLiner != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@@ -123,7 +123,7 @@ namespace ProjectLiner
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_company - pos)
+ if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
--
2.25.1
From 10ce368f63784e829f1c73b07a5a920f6ba2b020 Mon Sep 17 00:00:00 2001
From: gettterot
Date: Wed, 3 Apr 2024 08:28:54 +0400
Subject: [PATCH 11/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?=
=?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20?=
=?UTF-8?q?=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=20=D1=85=D1=80=D0=B0=D0=BD?=
=?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?=
=?UTF-8?q?=D0=BE=D0=B2=20=D0=B2=20"=D0=A1=D0=B5=D1=80=D0=B2=D0=B8=D1=81?=
=?UTF-8?q?=D0=B5"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 2 +-
.../CollectionType.cs | 24 +
.../ListGenericObjects.cs | 52 +++
.../MassiveGenericObjects.cs | 56 +--
.../StorageCollection.cs | 68 +++
.../FormLinerCollection.Designer.cs | 305 ++++++++++---
.../ProjectLiner/FormLinerCollection.cs | 416 ++++++++++--------
7 files changed, 641 insertions(+), 282 deletions(-)
create mode 100644 ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionType.cs
create mode 100644 ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs
create mode 100644 ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
index 5076923..b5cc584 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
@@ -71,7 +71,7 @@ namespace ProjectLiner.CollectionGenericObjects
///
public static DrawningCommonLiner operator -(AbstractCompany company, int position)
{
- return company._collection.Remove(position);
+ return company._collection.Remove(position) ;
}
///
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionType.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..d5b8c2c
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,24 @@
+
+namespace ProjectLiner.CollectionGenericObjects;
+
+
+///
+/// Тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2,
+}
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..dc81bc1
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,52 @@
+using ProjectLiner.CollectionGenericObjects;
+
+///
+/// Параметризованный набор объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public class ListGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Список объектов, которые храним
+ ///
+ private readonly List _collection;
+ ///
+ /// Максимально допустимое число объектов в списке
+ ///
+ private int _maxCount;
+ public int Count => _collection.Count;
+ public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
+ ///
+ /// Конструктор
+ ///
+ public ListGenericObjects()
+ {
+ _collection = new();
+ }
+ public T? Get(int position)
+ {
+ if (position >= Count || position < 0) return null;
+ return _collection[position];
+ }
+ public int Insert(T obj)
+ {
+ if (Count + 1 > _maxCount) return -1;
+ _collection.Add(obj);
+ return Count;
+ }
+ public int Insert(T obj, int position)
+ {
+ if (Count + 1 > _maxCount) return -1;
+ if (position < 0 || position > Count) return -1;
+ _collection.Insert(position, obj);
+ return 1;
+ }
+ public T? Remove(int position)
+ {
+ if (position < 0 || position > Count) return null;
+ T? temp = _collection[position];
+ _collection.RemoveAt(position);
+ return temp;
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
index f668f85..661b751 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -63,45 +63,33 @@ namespace ProjectLiner.CollectionGenericObjects
public int Insert(T obj, int position)
{
- if (position < 0 || position >= Count)
+ if (position >= Count || position < 0) return -1;
+ if (_collection[position] == null)
{
- return -1;
+ _collection[position] = obj;
+ return position;
}
-
- if (_collection[position] != null)
+ int temp = position + 1;
+ while (temp < Count)
{
- bool pushed = false;
- for (int index = position + 1; index < Count; index++)
+ if (_collection[temp] == null)
{
- if (_collection[index] == null)
- {
- position = index;
- pushed = true;
- break;
- }
- }
-
- if (!pushed)
- {
- for (int index = position - 1; index >= 0; index--)
- {
- if (_collection[index] == null)
- {
- position = index;
- pushed = true;
- break;
- }
- }
- }
-
- if (!pushed)
- {
- return position;
+ _collection[temp] = obj;
+ return temp;
}
+ ++temp;
}
-
- _collection[position] = obj;
- return position;
+ temp = position - 1;
+ while (temp >= 0)
+ {
+ if (_collection[temp] == null)
+ {
+ _collection[temp] = obj;
+ return temp;
+ }
+ --temp;
+ }
+ return -1;
}
public T? Remove(int position)
@@ -111,7 +99,7 @@ namespace ProjectLiner.CollectionGenericObjects
return null;
}
- if (_collection[position] == null) return null;
+ //if (_collection[position] == null) return null;
T? temp = _collection[position];
_collection[position] = null;
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..6e2ed1a
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,68 @@
+using ProjectLiner.CollectionGenericObjects;
+
+///
+/// Класс-хранилище коллекций
+///
+///
+public class StorageCollection
+ where T : class
+{
+ ///
+ /// Словарь (хранилище) с коллекциями
+ ///
+ readonly Dictionary> _storages;
+ ///
+ /// Возвращение списка названий коллекций
+ ///
+ public List Keys => _storages.Keys.ToList();
+ ///
+ /// Конструктор
+ ///
+ public StorageCollection()
+ {
+ _storages = new Dictionary>();
+ }
+ ///
+ /// Добавление коллекции в хранилище
+ ///
+ /// Название коллекции
+ /// тип коллекции
+ public void AddCollection(string name, CollectionType collectionType)
+ {
+ if (name == null || _storages.ContainsKey(name)) { return; }
+ switch (collectionType)
+
+ {
+ case CollectionType.None:
+ return;
+ case CollectionType.Massive:
+ _storages[name] = new MassiveGenericObjects();
+ return;
+ case CollectionType.List:
+ _storages[name] = new ListGenericObjects();
+ return;
+ }
+ }
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ public void DelCollection(string name)
+ {
+ if (_storages.ContainsKey(name))
+ _storages.Remove(name);
+ }
+ ///
+ /// Доступ к коллекции
+ ///
+ /// Название коллекции
+ ///
+ public ICollectionGenericObjects? this[string name]
+ {
+ get
+ {
+ if (name == null || !_storages.ContainsKey(name)) { return null; }
+ return _storages[name];
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs
index 1aeb63b..50e79a9 100644
--- a/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.Designer.cs
@@ -29,98 +29,149 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
- buttonRefresh = new Button();
- buttonGoToCheck = new Button();
- buttonRemoveLiner = new Button();
- maskedTextBoxPosition = new MaskedTextBox();
- buttonAddCommonLiner = new Button();
- buttonAddLiner = new Button();
+ buttonCreateCompany = new Button();
+ panelStorage = new Panel();
+ buttonCollectionDel = new Button();
+ listBoxCollection = new ListBox();
+ buttonCollectionAdd = new Button();
+ radioButtonList = new RadioButton();
+ radioButtonMassive = new RadioButton();
+ textBoxCollectionName = new TextBox();
+ labelCollectionName = new Label();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
+ panelCompanyTools = new Panel();
+ button1 = new Button();
+ button2 = new Button();
+ maskedTextBox1 = new MaskedTextBox();
+ button3 = new Button();
+ button4 = new Button();
+ button5 = new Button();
groupBoxTools.SuspendLayout();
+ panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ panelCompanyTools.SuspendLayout();
SuspendLayout();
//
// groupBoxTools
//
- groupBoxTools.Controls.Add(buttonRefresh);
- groupBoxTools.Controls.Add(buttonGoToCheck);
- groupBoxTools.Controls.Add(buttonRemoveLiner);
- groupBoxTools.Controls.Add(maskedTextBoxPosition);
- groupBoxTools.Controls.Add(buttonAddCommonLiner);
- groupBoxTools.Controls.Add(buttonAddLiner);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(1053, 0);
+ groupBoxTools.Location = new Point(681, 0);
+ groupBoxTools.Margin = new Padding(2);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(272, 845);
+ groupBoxTools.Padding = new Padding(2);
+ groupBoxTools.Size = new Size(176, 648);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
- // buttonRefresh
+ // buttonCreateCompany
//
- buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(33, 683);
- buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(217, 76);
- buttonRefresh.TabIndex = 6;
- buttonRefresh.Text = "Обновить";
- buttonRefresh.UseVisualStyleBackColor = true;
- buttonRefresh.Click += ButtonRefresh_Click;
+ buttonCreateCompany.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
+ buttonCreateCompany.Location = new Point(5, 317);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(166, 23);
+ buttonCreateCompany.TabIndex = 8;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
- // buttonGoToCheck
+ // panelStorage
//
- buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(33, 562);
- buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(217, 76);
- buttonGoToCheck.TabIndex = 5;
- buttonGoToCheck.Text = "Передать на тесты";
- buttonGoToCheck.UseVisualStyleBackColor = true;
- buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ panelStorage.Controls.Add(buttonCollectionDel);
+ panelStorage.Controls.Add(listBoxCollection);
+ panelStorage.Controls.Add(buttonCollectionAdd);
+ panelStorage.Controls.Add(radioButtonList);
+ panelStorage.Controls.Add(radioButtonMassive);
+ panelStorage.Controls.Add(textBoxCollectionName);
+ panelStorage.Controls.Add(labelCollectionName);
+ panelStorage.Dock = DockStyle.Top;
+ panelStorage.Location = new Point(2, 28);
+ panelStorage.Margin = new Padding(2);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(172, 247);
+ panelStorage.TabIndex = 7;
//
- // buttonRemoveLiner
+ // buttonCollectionDel
//
- buttonRemoveLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveLiner.Location = new Point(33, 416);
- buttonRemoveLiner.Name = "buttonRemoveLiner";
- buttonRemoveLiner.Size = new Size(217, 76);
- buttonRemoveLiner.TabIndex = 4;
- buttonRemoveLiner.Text = "Удаление Лайнера";
- buttonRemoveLiner.UseVisualStyleBackColor = true;
- buttonRemoveLiner.Click += ButtonRemoveLiner_Click;
+ buttonCollectionDel.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
+ buttonCollectionDel.Location = new Point(3, 212);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(166, 23);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить Коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
//
- // maskedTextBoxPosition
+ // listBoxCollection
//
- maskedTextBoxPosition.Location = new Point(33, 363);
- maskedTextBoxPosition.Mask = "00";
- maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- maskedTextBoxPosition.Size = new Size(217, 47);
- maskedTextBoxPosition.TabIndex = 3;
- maskedTextBoxPosition.ValidatingType = typeof(int);
+ listBoxCollection.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 17;
+ listBoxCollection.Location = new Point(3, 110);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(166, 89);
+ listBoxCollection.TabIndex = 5;
//
- // buttonAddCommonLiner
+ // buttonCollectionAdd
//
- buttonAddCommonLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddCommonLiner.Location = new Point(33, 236);
- buttonAddCommonLiner.Name = "buttonAddCommonLiner";
- buttonAddCommonLiner.Size = new Size(217, 76);
- buttonAddCommonLiner.TabIndex = 2;
- buttonAddCommonLiner.Text = "Добавление Обычного Лайнера";
- buttonAddCommonLiner.UseVisualStyleBackColor = true;
- buttonAddCommonLiner.Click += ButtonAddCommonLiner_Click;
+ buttonCollectionAdd.Font = new Font("Segoe UI", 7.948052F, FontStyle.Regular, GraphicsUnit.Point);
+ buttonCollectionAdd.Location = new Point(2, 82);
+ buttonCollectionAdd.Margin = new Padding(2);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(170, 23);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
//
- // buttonAddLiner
+ // radioButtonList
//
- buttonAddLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddLiner.Location = new Point(33, 126);
- buttonAddLiner.Name = "buttonAddLiner";
- buttonAddLiner.Size = new Size(217, 76);
- buttonAddLiner.TabIndex = 1;
- buttonAddLiner.Text = "Добавление Лайнера";
- buttonAddLiner.UseVisualStyleBackColor = true;
- buttonAddLiner.Click += ButtonAddLiner_Click;
+ radioButtonList.AutoSize = true;
+ radioButtonList.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point);
+ radioButtonList.Location = new Point(89, 58);
+ radioButtonList.Margin = new Padding(2);
+ radioButtonList.Name = "radioButtonList";
+ radioButtonList.Size = new Size(73, 23);
+ radioButtonList.TabIndex = 3;
+ radioButtonList.TabStop = true;
+ radioButtonList.Text = "Список";
+ radioButtonList.UseVisualStyleBackColor = true;
+ //
+ // radioButtonMassive
+ //
+ radioButtonMassive.AutoSize = true;
+ radioButtonMassive.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point);
+ radioButtonMassive.Location = new Point(2, 58);
+ radioButtonMassive.Margin = new Padding(2);
+ radioButtonMassive.Name = "radioButtonMassive";
+ radioButtonMassive.Size = new Size(71, 23);
+ radioButtonMassive.TabIndex = 2;
+ radioButtonMassive.TabStop = true;
+ radioButtonMassive.Text = "массив";
+ radioButtonMassive.UseVisualStyleBackColor = true;
+ //
+ // textBoxCollectionName
+ //
+ textBoxCollectionName.Location = new Point(0, 26);
+ textBoxCollectionName.Margin = new Padding(2);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(172, 33);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point);
+ labelCollectionName.Location = new Point(14, 5);
+ labelCollectionName.Margin = new Padding(2, 0, 2, 0);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(140, 19);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции";
//
// comboBoxSelectorCompany
//
@@ -128,33 +179,125 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(18, 46);
+ comboBoxSelectorCompany.Location = new Point(13, 279);
+ comboBoxSelectorCompany.Margin = new Padding(2);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
- comboBoxSelectorCompany.Size = new Size(242, 49);
+ comboBoxSelectorCompany.Size = new Size(158, 33);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//
- pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Dock = DockStyle.Bottom;
+ pictureBox.Enabled = false;
pictureBox.Location = new Point(0, 0);
+ pictureBox.Margin = new Padding(2);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(1053, 845);
+ pictureBox.Size = new Size(681, 648);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.BackColor = SystemColors.Window;
+ panelCompanyTools.Controls.Add(button1);
+ panelCompanyTools.Controls.Add(button2);
+ panelCompanyTools.Controls.Add(maskedTextBox1);
+ panelCompanyTools.Controls.Add(button5);
+ panelCompanyTools.Controls.Add(button3);
+ panelCompanyTools.Controls.Add(button4);
+ panelCompanyTools.Location = new Point(681, 346);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(176, 302);
+ panelCompanyTools.TabIndex = 9;
+ //
+ // button1
+ //
+ button1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ button1.Location = new Point(4, 2);
+ button1.Margin = new Padding(2);
+ button1.Name = "button1";
+ button1.Size = new Size(140, 46);
+ button1.TabIndex = 1;
+ button1.Text = "Добавление Лайнера";
+ button1.UseVisualStyleBackColor = true;
+ button1.Click += ButtonAddLiner_Click;
+ //
+ // button2
+ //
+ button2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ button2.Location = new Point(2, 52);
+ button2.Margin = new Padding(2);
+ button2.Name = "button2";
+ button2.Size = new Size(140, 46);
+ button2.TabIndex = 2;
+ button2.Text = "Добавление Обычного Лайнера";
+ button2.UseVisualStyleBackColor = true;
+ button2.Click += ButtonAddCommonLiner_Click;
+ //
+ // maskedTextBox1
+ //
+ maskedTextBox1.Location = new Point(2, 102);
+ maskedTextBox1.Margin = new Padding(2);
+ maskedTextBox1.Mask = "00";
+ maskedTextBox1.Name = "maskedTextBox1";
+ maskedTextBox1.Size = new Size(142, 33);
+ maskedTextBox1.TabIndex = 3;
+ maskedTextBox1.ValidatingType = typeof(int);
+ //
+ // button3
+ //
+ button3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ button3.Location = new Point(2, 134);
+ button3.Margin = new Padding(2);
+ button3.Name = "button3";
+ button3.Size = new Size(140, 46);
+ button3.TabIndex = 4;
+ button3.Text = "Удаление Лайнера";
+ button3.UseVisualStyleBackColor = true;
+ button3.Click += ButtonRemoveLiner_Click;
+ //
+ // button4
+ //
+ button4.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ button4.Location = new Point(2, 184);
+ button4.Margin = new Padding(2);
+ button4.Name = "button4";
+ button4.Size = new Size(140, 46);
+ button4.TabIndex = 5;
+ button4.Text = "Передать на тесты";
+ button4.UseVisualStyleBackColor = true;
+ button4.Click += ButtonGoToCheck_Click;
+ //
+ // button5
+ //
+ button5.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ button5.Location = new Point(2, 234);
+ button5.Margin = new Padding(2);
+ button5.Name = "button5";
+ button5.Size = new Size(140, 46);
+ button5.TabIndex = 6;
+ button5.Text = "Обновить";
+ button5.UseVisualStyleBackColor = true;
+ button5.Click += ButtonRefresh_Click;
+ //
// FormLinerCollection
//
- AutoScaleDimensions = new SizeF(17F, 41F);
+ AutoScaleDimensions = new SizeF(11F, 25F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1325, 845);
+ ClientSize = new Size(857, 648);
+ Controls.Add(panelCompanyTools);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
+ Margin = new Padding(2);
Name = "FormLinerCollection";
Text = "Коллекция автомобилей";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@@ -169,5 +312,21 @@
private Button buttonRemoveLiner;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonRefresh;
+ private Panel panelStorage;
+ private Label labelCollectionName;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private Button buttonCollectionAdd;
+ private RadioButton radioButtonList;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCreateCompany;
+ private Panel panelCompanyTools;
+ private Button button1;
+ private Button button2;
+ private MaskedTextBox maskedTextBox1;
+ private Button button5;
+ private Button button3;
+ private Button button4;
}
}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
index 3e759f4..67b99b3 100644
--- a/ProjectLiner/ProjectLiner/FormLinerCollection.cs
+++ b/ProjectLiner/ProjectLiner/FormLinerCollection.cs
@@ -1,188 +1,256 @@
-using ProjectLiner.CollectionGenericObjects;
+
+using ProjectLiner.CollectionGenericObjects;
using ProjectLiner.Drawnings;
-using System.Windows.Forms;
-namespace ProjectLiner
+namespace ProjectLiner;
+///
+/// Форма работы с компанией и ее коллекцией
+///
+public partial class FormLinerCollection : Form
{
///
- /// Форма работы с компанией и ее коллекцией
+ /// Хранилише коллекций
///
- public partial class FormLinerCollection : Form
+ private readonly StorageCollection _storageCollection;
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+ ///
+ /// Конструктор
+ ///
+ public FormLinerCollection()
{
- ///
- /// Компания
- ///
- private AbstractCompany? _company = null;
-
- ///
- /// Конструктор
- ///
- public FormLinerCollection()
+ InitializeComponent();
+ _storageCollection = new();
+ }
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ panelCompanyTools.Enabled = false;
+ }
+ ///
+ /// Добавление грузовика
+ ///
+ ///
+ ///
+ private void ButtonAddCommonLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCommonLiner));
+ ///
+ /// Добавление подметательно-уборочной машины
+ ///
+ ///
+ ///
+ private void ButtonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner));
+ ///
+ /// Создание объекта класса-перемещенияв
+ ///
+ ///
+ private void CreateObject(string type)
+ {
+ if (_company == null)
{
- InitializeComponent();
+ return;
}
-
- ///
- /// Выбор компании
- ///
- ///
- ///
- private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ Random random = new();
+ DrawningCommonLiner drawningCommonLiner;
+ switch (type)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new LinerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ case nameof(DrawningCommonLiner):
+ drawningCommonLiner = new DrawningCommonLiner(random.Next(100, 300),
+ random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningLiner):
+ drawningCommonLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
}
-
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
+ if (_company + drawningCommonLiner != -1)
{
- if (_company == null)
- {
- return;
- }
-
- Random random = new();
- DrawningCommonLiner drawingLiner;
- switch (type)
- {
- case nameof(DrawningCommonLiner):
- drawingLiner = new DrawningCommonLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
- break;
- case nameof(DrawningLiner):
- drawingLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random),
- Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)));
- break;
- default:
- return;
- }
-
- if (_company + drawingLiner != -1)
- {
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _company.Show();
- }
- else
- {
- MessageBox.Show("Не удалось добавить объект");
- }
- }
-
- ///
- /// Получение цвета
- ///
- /// Генератор случайных чисел
- ///
- private static Color GetColor(Random random)
- {
- Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
- ColorDialog dialog = new();
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- color = dialog.Color;
- }
-
- return color;
- }
-
- ///
- /// Добавление обычного лайнер
- ///
- ///
- ///
- private void ButtonAddCommonLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCommonLiner));
-
- ///
- /// Добавление лайнера
- ///
- ///
- ///
- private void ButtonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner));
-
- ///
- /// Удаление объекта
- ///
- ///
- ///
- private void ButtonRemoveLiner_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
- {
- return;
- }
-
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
- {
- return;
- }
-
- int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_company - pos != null)
- {
- MessageBox.Show("Объект удален");
- pictureBox.Image = _company.Show();
- }
- else
- {
- MessageBox.Show("Не удалось удалить объект");
- }
- }
-
- ///
- /// Передача объекта в другую форму
- ///
- ///
- ///
- private void ButtonGoToCheck_Click(object sender, EventArgs e)
- {
- if (_company == null)
- {
- return;
- }
-
- DrawningCommonLiner? 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;
- }
-
+ MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
}
-}
+ ///
+ /// Получение цвета
+ ///
+ /// Генератор случайных чисел
+ ///
+ private static Color GetColor(Random random)
+ {
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0,
+ 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ return color;
+ }
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveLiner_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
+ {
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_company - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+
+ }
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ DrawningCommonLiner? liner = null;
+ int counter = 100;
+ while (liner == null)
+ {
+ liner = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0) break;
+ }
+ if (liner == null)
+ {
+ return;
+ }
+ FormLiner form = new FormLiner();
+ form.SetLiner = liner;
+ form.ShowDialog();
+ }
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+
+ }
+ ///
+ /// Добавление коллекции
+ ///
+ ///
+ ///
+ private void ButtonCollectionAdd_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
+ {
+ MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ CollectionType collectionType = CollectionType.None;
+ if (radioButtonMassive.Checked)
+ {
+ collectionType = CollectionType.Massive;
+ }
+ else if (radioButtonList.Checked)
+ {
+ collectionType = CollectionType.List;
+ }
+ _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
+ RerfreshListBoxItems();
+ }
+ ///
+ /// Удаление коллекции
+ ///
+ ///
+ ///
+ private void ButtonCollectionDel_Click(object sender, EventArgs e)
+ {
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+ if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ RerfreshListBoxItems();
+ }
+ ///
+ /// Обновление списка в listBoxCollection
+ ///
+ private void RerfreshListBoxItems()
+ {
+ listBoxCollection.Items.Clear();
+ for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
+ {
+ string? colName = _storageCollection.Keys?[i];
+ if (!string.IsNullOrEmpty(colName))
+ {
+ listBoxCollection.Items.Add(colName);
+ }
+ }
+ }
+ ///
+ /// Создание компании
+ ///
+ ///
+ ///
+ private void ButtonCreateCompany_Click(object sender, EventArgs e)
+ {
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+ ICollectionGenericObjects? collection =
+ _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
+ if (collection == null)
+ {
+ MessageBox.Show("Коллекция не проинициализирована");
+ return;
+ }
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new LinerSharingService(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+ panelCompanyTools.Enabled = true;
+ RerfreshListBoxItems();
+ }
+}
\ No newline at end of file
--
2.25.1