From 6196569b709d217928f321f49b18ec6078c1450e Mon Sep 17 00:00:00 2001 From: the Date: Tue, 27 Sep 2022 10:59:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D1=80=D0=B8=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D0=B3=D0=BE=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ship/Ship/DrawingMotorShip.cs | 45 ++++++++++++++++++++++++++++++++++ Ship/Ship/DrawingShip.cs | 22 ++++++++++++++--- Ship/Ship/EntityMotorShip.cs | 40 ++++++++++++++++++++++++++++++ Ship/Ship/FormShip.Designer.cs | 13 ++++++++++ Ship/Ship/FormShip.cs | 34 +++++++++++++++++++++---- 5 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 Ship/Ship/DrawingMotorShip.cs create mode 100644 Ship/Ship/EntityMotorShip.cs diff --git a/Ship/Ship/DrawingMotorShip.cs b/Ship/Ship/DrawingMotorShip.cs new file mode 100644 index 0000000..54a7326 --- /dev/null +++ b/Ship/Ship/DrawingMotorShip.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Ship +{ + internal class DrawingMotorShip : DrawingShip + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия труб + /// Признак наличия отсека для топлива + public DrawingMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool pipes, bool fuelTank) : base(speed, weight, bodyColor, 110, 60) + { + Ship = new EntityMotorShip(speed, weight, bodyColor, dopColor, pipes, fuelTank); + } + public override void DrawTransport(Graphics g) + { + if (Ship is not EntityMotorShip motorShip) + { + return; + } + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(motorShip.DopColor); + + if (motorShip.Pipes) + { + g.FillRectangle(dopBrush, _startPosX, _startPosY, 10, 10); + } + + base.DrawTransport(g); + if (motorShip.Fueltank) + { + + } + } + } +} diff --git a/Ship/Ship/DrawingShip.cs b/Ship/Ship/DrawingShip.cs index e2b98e5..b1c2714 100644 --- a/Ship/Ship/DrawingShip.cs +++ b/Ship/Ship/DrawingShip.cs @@ -11,15 +11,15 @@ namespace Ship /// /// Класс-сущность /// - public EntityShip Ship { private set; get; } + public EntityShip Ship { protected set; get; } /// /// Левая координата отрисовки корабля /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки корабля /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -46,6 +46,20 @@ namespace Ship { 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; + } + /// /// Установка позиции корабля /// @@ -119,7 +133,7 @@ namespace Ship /// Отрисовка автомобиля /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/Ship/Ship/EntityMotorShip.cs b/Ship/Ship/EntityMotorShip.cs new file mode 100644 index 0000000..4754d52 --- /dev/null +++ b/Ship/Ship/EntityMotorShip.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Ship +{ + internal class EntityMotorShip : EntityShip + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия антикрыла + /// + public bool Pipes { get; private set; } + /// + /// Признак наличия гоночной полосы + /// + public bool Fueltank { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public EntityMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool pipes, bool fuelTank) : base(speed, weight, bodyColor) + { + DopColor = dopColor; + Pipes = pipes; + Fueltank = fuelTank; + } + + } +} diff --git a/Ship/Ship/FormShip.Designer.cs b/Ship/Ship/FormShip.Designer.cs index 3e0ed0d..3e16931 100644 --- a/Ship/Ship/FormShip.Designer.cs +++ b/Ship/Ship/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.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -141,11 +142,22 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(93, 402); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(101, 23); + 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(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); @@ -175,5 +187,6 @@ private Button buttonLeft; private Button buttonDown; private Button buttonRight; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Ship/Ship/FormShip.cs b/Ship/Ship/FormShip.cs index 461105a..f846cc3 100644 --- a/Ship/Ship/FormShip.cs +++ b/Ship/Ship/FormShip.cs @@ -19,6 +19,15 @@ namespace Ship pictureBoxShip.Image = bmp; } /// + /// + /// + private void SetData() + { + toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}"; + toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}"; + toolStripStatusLabelColor.Text = $": {_ship.Ship.BodyColor.Name}"; + } + /// /// "" /// /// @@ -27,12 +36,10 @@ namespace Ship { 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), pictureBoxShip.Height - rnd.Next(20, 100), + _ship.SetPosition(rnd.Next(10, 100), pictureBoxShip.Height - rnd.Next(50, 100), pictureBoxShip.Width, pictureBoxShip.Height); - toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}"; - toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}"; - toolStripStatusLabelColor.Text = $": { _ship.Ship.BodyColor.Name}"; - Draw(); + SetData(); + Draw(); } /// /// @@ -70,5 +77,22 @@ namespace Ship _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height); Draw(); } + + /// + /// "" + /// + /// + /// + private void buttonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _ship = new DrawingMotorShip(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))); + _ship.SetPosition(rnd.Next(50, 100), pictureBoxShip.Height - rnd.Next(80, 100), pictureBoxShip.Width, pictureBoxShip.Height); + SetData(); + Draw(); + } } } \ No newline at end of file