From 9e7872158eda04c0ed556961d21aeec2e0935f6a Mon Sep 17 00:00:00 2001
From: ksenianeva <95441235+ksenianeva@users.noreply.github.com>
Date: Tue, 4 Oct 2022 00:23:44 +0400
Subject: [PATCH] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=BB?=
=?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?=
=?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.=20=D0=9F=D0=B5?=
=?UTF-8?q?=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=BA=D0=BE?=
=?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D1=8B.?=
=?UTF-8?q?=20=D0=9F=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD=D1=83=D1=82=D1=8B?=
=?UTF-8?q?=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ContainerShip/DrawingContainerShip.cs | 99 +++++++++++++++++++
ContainerShip/ContainerShip/DrawingShip.cs | 13 ++-
.../ContainerShip/EntityContainerShip.cs | 32 ++++++
ContainerShip/ContainerShip/EntityShip.cs | 2 +-
.../ContainerShip/FormShip.Designer.cs | 15 +++
ContainerShip/ContainerShip/FormShip.cs | 22 ++++-
6 files changed, 173 insertions(+), 10 deletions(-)
create mode 100644 ContainerShip/ContainerShip/DrawingContainerShip.cs
create mode 100644 ContainerShip/ContainerShip/EntityContainerShip.cs
diff --git a/ContainerShip/ContainerShip/DrawingContainerShip.cs b/ContainerShip/ContainerShip/DrawingContainerShip.cs
new file mode 100644
index 0000000..c7718c3
--- /dev/null
+++ b/ContainerShip/ContainerShip/DrawingContainerShip.cs
@@ -0,0 +1,99 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ContainerShip
+{
+ internal class DrawingContainerShip : DrawingShip
+ {
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия обвеса
+ /// Признак наличия антикрыла
+ /// Признак наличия гоночной полосы
+ public DrawingContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) :
+ base(speed, weight, bodyColor)
+ {
+ Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers);
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (Ship is not EntityContainerShip containerShip)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush dopBrush = new SolidBrush(containerShip.DopColor);
+ Pen dopPen = new (containerShip.DopColor);
+
+ base.DrawTransport(g);
+ if (containerShip.Containers)
+ {
+ Point[] container1 =
+ {
+ new Point((int)(_startPosX + 5), (int)(_startPosY + 15)),
+ new Point((int)(_startPosX + 5), (int)(_startPosY + 5)),
+ new Point((int)(_startPosX + 25), (int)_startPosY + 5),
+ new Point((int)_startPosX + 25, (int)_startPosY + 15)
+ };
+
+
+ Point[] container2 =
+ {
+ new Point((int)_startPosX + 40, (int)_startPosY + 15),
+ new Point((int)_startPosX + 40, (int)_startPosY + 5),
+ new Point((int)_startPosX + 75, (int)_startPosY + 5),
+ new Point((int)_startPosX + 75, (int)_startPosY + 15)
+ };
+
+ Point[] container3 =
+ {
+ new Point((int)_startPosX + 16 * 5, (int)_startPosY + 15),
+ new Point((int)_startPosX + 16 * 5, (int)_startPosY + 5),
+ new Point((int)_startPosX + 22 * 5, (int)_startPosY + 5),
+ new Point((int)_startPosX + 22 * 5, (int)_startPosY + 15)
+ };
+
+ Point[] container4 =
+ {
+ new Point((int)_startPosX + 22 * 5, (int)_startPosY + 15),
+ new Point((int)_startPosX + 22 * 5, (int)_startPosY),
+ new Point((int)_startPosX + 26 * 5, (int)_startPosY),
+ new Point((int)_startPosX + 26 * 5, (int)_startPosY + 15)
+ };
+
+ g.FillPolygon(dopBrush, container1);
+ g.DrawPolygon(pen, container1);
+ g.FillPolygon(dopBrush, container2);
+ g.DrawPolygon(pen, container2);
+ g.FillPolygon(dopBrush, container3);
+ g.DrawPolygon(pen, container3);
+ g.FillPolygon(dopBrush, container4);
+ g.DrawPolygon(pen, container4);
+
+
+ }
+
+
+
+
+ if (containerShip.Crane)
+ {
+ g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 15, _startPosX + 8 * 5, _startPosY - 30);
+ g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY - 30);
+ g.DrawLine(dopPen, _startPosX + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY - 25);
+ g.DrawLine(dopPen, _startPosX + 8 * 5 + 8 * 5, _startPosY - 30, _startPosX + 8 * 5 + 8 * 5, _startPosY);
+ }
+
+ }
+ }
+}
+
diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs
index 00b6e4c..e11497c 100644
--- a/ContainerShip/ContainerShip/DrawingShip.cs
+++ b/ContainerShip/ContainerShip/DrawingShip.cs
@@ -9,9 +9,9 @@ namespace ContainerShip
{
internal class DrawingShip
{
- public EntityShip Ship { private set; get; }
- private float _startPosX;
- private float _startPosY;
+ public EntityShip Ship { protected set; get; }
+ protected float _startPosX;
+ protected float _startPosY;
private int? _pictureWidth = null;
private int _startPosXInt;
private int _startPosYInt;
@@ -33,10 +33,9 @@ namespace ContainerShip
/// Скорость
/// Вес автомобиля
/// Цвет кузова
- public void Init(int speed, float weight, Color bodyColor)
+ public DrawingShip(int speed, float weight, Color bodyColor)
{
- Ship = new EntityShip();
- Ship.Init(speed, weight, bodyColor);
+ Ship = new EntityShip(speed, weight, bodyColor);
}
/// Координата X
@@ -100,7 +99,7 @@ namespace ContainerShip
/// Отрисовка
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
diff --git a/ContainerShip/ContainerShip/EntityContainerShip.cs b/ContainerShip/ContainerShip/EntityContainerShip.cs
new file mode 100644
index 0000000..816351d
--- /dev/null
+++ b/ContainerShip/ContainerShip/EntityContainerShip.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ContainerShip
+{
+ internal class EntityContainerShip : EntityShip
+ {
+ public Color DopColor { get; private set; }
+ public bool Containers { get; private set; }
+ public bool Crane { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия обвеса
+ /// Признак наличия антикрыла
+ /// Признак наличия гоночной полосы
+ public EntityContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) :
+ base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ Crane = crane;
+ Containers = containers;
+ }
+ }
+}
diff --git a/ContainerShip/ContainerShip/EntityShip.cs b/ContainerShip/ContainerShip/EntityShip.cs
index 15ca4a1..df462f0 100644
--- a/ContainerShip/ContainerShip/EntityShip.cs
+++ b/ContainerShip/ContainerShip/EntityShip.cs
@@ -31,7 +31,7 @@ namespace ContainerShip
///
///
///
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityShip(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
diff --git a/ContainerShip/ContainerShip/FormShip.Designer.cs b/ContainerShip/ContainerShip/FormShip.Designer.cs
index de9ee47..7d6bb68 100644
--- a/ContainerShip/ContainerShip/FormShip.Designer.cs
+++ b/ContainerShip/ContainerShip/FormShip.Designer.cs
@@ -38,6 +38,7 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.pictureBoxShip = new System.Windows.Forms.PictureBox();
this.ButtonCreate = new System.Windows.Forms.Button();
+ this.ButtonCreateModif = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
this.SuspendLayout();
@@ -142,11 +143,24 @@
this.ButtonCreate.UseVisualStyleBackColor = false;
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
+ // ButtonCreateModif
+ //
+ this.ButtonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.ButtonCreateModif.BackColor = System.Drawing.SystemColors.Window;
+ this.ButtonCreateModif.Location = new System.Drawing.Point(130, 381);
+ this.ButtonCreateModif.Name = "ButtonCreateModif";
+ this.ButtonCreateModif.Size = new System.Drawing.Size(143, 34);
+ this.ButtonCreateModif.TabIndex = 9;
+ this.ButtonCreateModif.Text = "Модификация";
+ this.ButtonCreateModif.UseVisualStyleBackColor = false;
+ this.ButtonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
// FormShip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.ButtonCreateModif);
this.Controls.Add(this.ButtonCreate);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
@@ -177,5 +191,6 @@
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private PictureBox pictureBoxShip;
private Button ButtonCreate;
+ private Button ButtonCreateModif;
}
}
\ No newline at end of file
diff --git a/ContainerShip/ContainerShip/FormShip.cs b/ContainerShip/ContainerShip/FormShip.cs
index 46bfc3c..af5a79a 100644
--- a/ContainerShip/ContainerShip/FormShip.cs
+++ b/ContainerShip/ContainerShip/FormShip.cs
@@ -61,16 +61,34 @@ namespace ContainerShip
Draw();
}
+ private void SetData()
+ {
+ Random rnd = new();
+ _ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
+ toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}";
+ toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}";
+ toolStripStatusLabelBodyColor.Text = $": {_ship.Ship.BodyColor.Name}";
+ }
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _ship = new DrawingShip();
- _ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ _ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}";
toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}";
toolStripStatusLabelBodyColor.Text = $": {_ship.Ship.BodyColor.Name}";
Draw();
}
+
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ Color.FromArgb(rnd.Next(0,256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Convert.ToBoolean(rnd.Next(0,2)), Convert.ToBoolean(rnd.Next(0,2)));
+ SetData();
+ Draw();
+ }
}
}
\ No newline at end of file