From 4b8abfe62b5b3a3ffd3b42138b4e0202b7b1bcd9 Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Tue, 27 Sep 2022 13:22:48 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Liner/DrawingLiner.cs | 43 ++++++++++++++++++++++++++++++++ Liner/Liner/DrawingShip.cs | 27 +++++++++++--------- Liner/Liner/EntityLiner.cs | 25 +++++++++++++++++++ Liner/Liner/FormShip.Designer.cs | 13 ++++++++++ Liner/Liner/FormShip.cs | 23 +++++++++++++---- 5 files changed, 114 insertions(+), 17 deletions(-) create mode 100644 Liner/Liner/DrawingLiner.cs create mode 100644 Liner/Liner/EntityLiner.cs diff --git a/Liner/Liner/DrawingLiner.cs b/Liner/Liner/DrawingLiner.cs new file mode 100644 index 0000000..0d99201 --- /dev/null +++ b/Liner/Liner/DrawingLiner.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Liner +{ + internal class DrawningLiner : DrawingShip + { + public DrawningLiner(int speed, float weight, Color bodyColor, Color dopColor, bool dopDeck, bool pool) : + base(speed, weight, bodyColor, 130, 45) + { + Ship = new EntityLiner(speed, weight, bodyColor, dopColor, dopDeck, pool); + } + public override void DrawTransport(Graphics g) + { + if (Ship is not EntityLiner liner) + { + return; + } + Pen pen = new(Color.Black); + Brush dopbrush = new SolidBrush(liner.DopColor); + if (liner.DopDeck) + { + g.FillRectangle(dopbrush, (int)_startPosX + 50, (int)_startPosY + 15, 60, 5); + g.DrawRectangle(pen, (int)_startPosX+ 50, (int)_startPosY + 15, 60, 5); + } + _startPosX += 10; + _startPosY += 5; + base.DrawTransport(g); + _startPosY -= 5; + _startPosX -= 10; + if (liner.Pool) + { + g.FillRectangle(dopbrush, (int)_startPosX + 15, (int)_startPosY + 25, 30, 3); + g.DrawRectangle(pen, (int)_startPosX + 15, (int)_startPosY + 25, 30, 3); + g.DrawLine(pen, _startPosX + 45, _startPosY + 25, _startPosX + 45, _startPosY + 20); + g.DrawLine(pen, _startPosX + 45, _startPosY + 20, _startPosX + 35, _startPosY + 20); + } + } + } +} diff --git a/Liner/Liner/DrawingShip.cs b/Liner/Liner/DrawingShip.cs index 2ce7dc1..271321a 100644 --- a/Liner/Liner/DrawingShip.cs +++ b/Liner/Liner/DrawingShip.cs @@ -8,9 +8,9 @@ namespace Liner { internal class DrawingShip { - public EntityShip Ship { get; set; } - private float _startPosX; - private float _startPosY; + public EntityShip Ship { get; protected set; } + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; protected readonly int _ShipWidth = 120; @@ -19,7 +19,12 @@ namespace Liner { Ship = new EntityShip(speed, weight, bodycolor); } - + protected DrawingShip(int speed, float weight, Color bodyColor, int shipWidth, int shipHeight) : + this(speed, weight, bodyColor) + { + _ShipWidth = shipWidth; + _ShipHeight = shipHeight; + } public void SetPosition(int x, int y, int width, int height) { if (width <= _ShipWidth + x || height <= _ShipHeight + y || x<0 || y<0) @@ -71,7 +76,7 @@ namespace Liner } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureWidth.HasValue || !_pictureHeight.HasValue) { @@ -79,8 +84,8 @@ namespace Liner } Pen pen = new(Color.Black); Brush br = new SolidBrush(Ship?.BodyColor ?? Color.Black); - g.FillRectangle(br, _startPosX + 40, _startPosY, 30 * 2, 10 * 2); - g.DrawRectangle(pen, _startPosX + 40, _startPosY, 30 * 2, 10 * 2); + g.FillRectangle(br, _startPosX + 40, _startPosY + 15, 70, 5); + g.DrawRectangle(pen, _startPosX + 40, _startPosY + 15, 70, 5); Point[] pointsdown = { new Point((int)_startPosX, (int)_startPosY+20), new Point((int)_startPosX + 60 * 2, (int)_startPosY+20), @@ -90,12 +95,10 @@ namespace Liner }; g.FillPolygon(br, pointsdown); - g.DrawLine(pen, _startPosX, _startPosY+20, _startPosX + 60 * 2, _startPosY+20); - g.DrawLine(pen, _startPosX+100, _startPosY+20*2, _startPosX + 120, _startPosY + 10 * 2); - g.DrawLine(pen, _startPosX, _startPosY+20, _startPosX + 20, _startPosY + 40); + g.DrawLine(pen, _startPosX, _startPosY + 20, _startPosX + 60 * 2, _startPosY + 20); + g.DrawLine(pen, _startPosX + 100, _startPosY + 20 * 2, _startPosX + 120, _startPosY + 10 * 2); + g.DrawLine(pen, _startPosX, _startPosY + 20, _startPosX + 20, _startPosY + 40); g.DrawLine(pen, _startPosX + 20, _startPosY + 40, _startPosX + 100, _startPosY + 40); - - } public void ChangeBorders(int width, int height) diff --git a/Liner/Liner/EntityLiner.cs b/Liner/Liner/EntityLiner.cs new file mode 100644 index 0000000..66b1827 --- /dev/null +++ b/Liner/Liner/EntityLiner.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Liner +{ + internal class EntityLiner : EntityShip + { + public Color DopColor { get; private set; } + + public bool DopDeck { get; private set; } + + public bool Pool { get; private set; } + + public EntityLiner(int speed, float weight, Color bodyColor, Color dopColor, bool dopDeck, bool pool) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + DopDeck = dopDeck; + Pool = pool; + } + } +} diff --git a/Liner/Liner/FormShip.Designer.cs b/Liner/Liner/FormShip.Designer.cs index d1d72f9..cc49763 100644 --- a/Liner/Liner/FormShip.Designer.cs +++ b/Liner/Liner/FormShip.Designer.cs @@ -38,6 +38,7 @@ this.buttonUp = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -143,11 +144,22 @@ this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(138, 373); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(118, 29); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // FormShip // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonUp); @@ -177,5 +189,6 @@ private Button buttonUp; private Button buttonRight; private Button buttonLeft; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Liner/Liner/FormShip.cs b/Liner/Liner/FormShip.cs index 68223cf..10f9e4d 100644 --- a/Liner/Liner/FormShip.cs +++ b/Liner/Liner/FormShip.cs @@ -19,15 +19,20 @@ namespace Liner pictureBoxShip.Image = bmp; } - + + private void SetData() + { + Random rnd = new(); + toolStripStatusLabelSpeed.Text = $": {_ship.Ship?.Speed}"; + toolStripStatusLabelWeight.Text = $": {_ship.Ship?.Weight}"; + toolStripStatusLabelColor.Text = $": {_ship.Ship?.BodyColor.Name}"; + _ship.SetPosition(rnd.Next(100, 500), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height); + } private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); _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}"; - toolStripStatusLabelColor.Text = $": {_ship.Ship?.BodyColor.Name}"; + SetData(); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) @@ -57,5 +62,13 @@ namespace Liner _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height); Draw(); } + + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _ship = new DrawningLiner(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