From b06afd978659f93fd20342756b20ba1f54aede30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=91=D0=B0=D1=82=D1=8B?= =?UTF-8?q?=D0=BB=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 4 Oct 2022 21:30:36 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/DrawningShip.cs | 14 ++++-- WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs | 49 +++++++++++++++++++++ WarmlyShip/WarmlyShip/EntityWarmlyShip.cs | 36 +++++++++++++++ WarmlyShip/WarmlyShip/FormShip.Designer.cs | 13 ++++++ WarmlyShip/WarmlyShip/FormShip.cs | 27 +++++++++++- 5 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs create mode 100644 WarmlyShip/WarmlyShip/EntityWarmlyShip.cs diff --git a/WarmlyShip/WarmlyShip/DrawningShip.cs b/WarmlyShip/WarmlyShip/DrawningShip.cs index 65029ae..f99bce6 100644 --- a/WarmlyShip/WarmlyShip/DrawningShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningShip.cs @@ -5,9 +5,9 @@ /// internal class DrawningShip { - public EntityShip Ship { get; private 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; private readonly int _shipWidth = 80; @@ -16,6 +16,12 @@ { Ship = new EntityShip(speed, weight, сolor); } + protected DrawningShip(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 (x + _shipWidth <= width && y + _shipHeight <= height && x >= 0 && y >= 0) @@ -64,7 +70,7 @@ break; } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs new file mode 100644 index 0000000..bee8ebd --- /dev/null +++ b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class DrawningWarmlyShip : DrawningShip + { + public DrawningWarmlyShip(int speed, float weight, Color bodyColor, Color dopColor, bool anchor, bool pipe, bool window) : + base(speed, weight, bodyColor, 110, 60) + { + Ship = new EntityWarmlyShip(speed, weight, bodyColor, dopColor, anchor, pipe, window); + } + public override void DrawTransport(Graphics g) + { + if (Ship is not EntityWarmlyShip warmlyShip) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(warmlyShip.DopColor); + + base.DrawTransport(g); + + if (warmlyShip.Anchor) + { + g.DrawLine(pen, _startPosX + 52, _startPosY + 40, _startPosX + 52, _startPosY + 60); + g.DrawLine(pen, _startPosX + 46, _startPosY + 60, _startPosX + 58, _startPosY + 60); + g.DrawLine(pen, _startPosX + 46, _startPosY + 60, _startPosX + 46, _startPosY + 50); + g.DrawLine(pen, _startPosX + 58, _startPosY + 60, _startPosX + 58, _startPosY + 50); + } + + if (warmlyShip.Window) + { + g.FillEllipse(new SolidBrush(Color.White), _startPosX + 84, _startPosY + 30, 15, 15); + g.FillEllipse(new SolidBrush(Color.White), _startPosX + 59, _startPosY + 30, 15, 15); + g.FillEllipse(new SolidBrush(Color.White), _startPosX + 35, _startPosY + 30, 15, 15); + } + + if (warmlyShip.Pipe) + { + g.FillRectangle(dopBrush, _startPosX + 50, _startPosY - 5, 10, 15); + } + } + } +} diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs new file mode 100644 index 0000000..c9277f5 --- /dev/null +++ b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class EntityWarmlyShip : EntityShip + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия якоря + /// + public bool Anchor { get; private set; } + /// + /// Признак наличия трубы + /// + public bool Pipe { get; private set; } + /// + /// Признак наличия окон + /// + public bool Window { get; private set; } + public EntityWarmlyShip(int speed, float weight, Color bodyColor, Color dopColor, bool anchor, bool pipe, bool window) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Anchor = anchor; + Pipe = pipe; + Window = window; + } + } +} diff --git a/WarmlyShip/WarmlyShip/FormShip.Designer.cs b/WarmlyShip/WarmlyShip/FormShip.Designer.cs index 2049688..7dae5e1 100644 --- a/WarmlyShip/WarmlyShip/FormShip.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormShip.Designer.cs @@ -38,6 +38,7 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.buttonCreateModify = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -140,11 +141,22 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); // + // buttonCreateModify + // + this.buttonCreateModify.Location = new System.Drawing.Point(93, 402); + this.buttonCreateModify.Name = "buttonCreateModify"; + this.buttonCreateModify.Size = new System.Drawing.Size(101, 23); + this.buttonCreateModify.TabIndex = 7; + this.buttonCreateModify.Text = "Модификация"; + this.buttonCreateModify.UseVisualStyleBackColor = true; + this.buttonCreateModify.Click += new System.EventHandler(this.buttonCreateModify_Click); + // // FormShip // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonCreateModify); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); @@ -174,5 +186,6 @@ private Button buttonLeft; private Button buttonDown; private Button buttonRight; + private Button buttonCreateModify; } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormShip.cs b/WarmlyShip/WarmlyShip/FormShip.cs index fc8db62..adc335f 100644 --- a/WarmlyShip/WarmlyShip/FormShip.cs +++ b/WarmlyShip/WarmlyShip/FormShip.cs @@ -14,14 +14,22 @@ namespace WarmlyShip _ship?.DrawTransport(gr); pictureBoxShip.Image = bmp; } - private void buttonCreate_Click(object sender, EventArgs e) + /// + /// + /// + private void SetData() { Random rnd = new(); - _ship = new DrawningShip(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); toolStripStatusSpeed.Text = $": {_ship.Ship.Speed}"; toolStripStatusWeight.Text = $": {_ship.Ship.Weight}"; toolStripStatusColor.Text = $": {_ship.Ship.BodyColor.Name}"; + } + private void buttonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + _ship = new DrawningShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); Draw(); } private void PictureBoxShip_Resize(object sender, EventArgs e) @@ -50,5 +58,20 @@ namespace WarmlyShip } Draw(); } + /// + /// "" + /// + /// + /// + private void buttonCreateModify_Click(object sender, EventArgs e) + { + Random rnd = new(); + _ship = new DrawningWarmlyShip(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)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(); + Draw(); + } } }